[不花钱站长]:从免费域名开始[0元] Oracle永久免费VPS[0元] VPS环境搭建免费脚本[0元] 秒变大盘挂载免费网盘[0元] 小白免费采集器1天500W[0元] CF免费DNS+CDN服务[0元]
[零基础网赚]:撸本站免费源码[0元] 网站强引免费蜘蛛法[0元] 图片视频文件免费存储[0元] 外链轻松发布免费友链[0元] 入坑免费教程学习源代码[0元] 网上百种+赚钱联盟推荐[?元]

↑↑VPS推荐网 WWW.VPS.COM.IN 稳定 便宜 免备案↑↑


您现在的位置是:首页 > 全球[VPS测评] >  wordpress教程,国外永久免费VPS

WordPress生成站点地图xml 代码版,适合内容较少的用户选择

全球[VPS测评]来源:VPS推荐网点击:1214
【性价之王】【线路之王】【价格之王】【配置之王】
【免费之王】【香港首推】【梯子之王】【独服之王】
WordPress生成站点地图xml 代码版,适合内容较少的用户选择

WordPress插件是非常丰富的,很多功能可以通过插件来实现,不过插件较多会影响一定的速度以及不同主题模板之间的兼容性。站点地图不少使用wordpress程序用户要使用的,不过需要安装相应的插件,小七博客在之前分享过wordpress sitemap插件,不过也可以使用代码来实现,以下方法适合DUX主题。其他主题自行修改相对位置位置,谢谢。

1、在主题目录中options.php 添加开关。

复制 $options[] = array( 'name' => __('更新文章时生成站点地图xml', 'haoui'), 'desc' => __('开启', 'haoui'), 'id' => 'sitemap_xml', 'std' => true, 'type' => 'checkbox');

注:位置自己安排,没有要求!

2、在主题目录 functions.php 添加

复制// sitemap_xmlif (_hui('sitemap_xml')) { function cvps_sitemap_resh() { require_once get_template_directory() . '/modules/sitemap-xml.php'; $sitemap_xml = cvps_get_xml_sitemap(); file_put_contents(ABSPATH.'sitemap.xml', $sitemap_xml); } if ( defined('ABSPATH') ) { add_action('publish_post', 'cvps_sitemap_resh'); add_action('save_post', 'cvps_sitemap_resh'); add_action('edit_post', 'cvps_sitemap_resh'); add_action('delete_post', 'cvps_sitemap_resh'); }}

3、在主题目录中 modules 文件夹 新建 sitemap-xml.php 并添加以下代码:

复制复制<?php function cvps_get_xml_sitemap() { ob_start(); echo '<?xml version="1.0" encoding="UTF-8"?>';?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/"><!-- generated-on=<?php echo get_lastpostdate('blog'); ?> --><url><loc><?php echo get_home_url(); ?></loc><lastmod><?php echo gmdate('Y-m-d\TH:i:s+00:00', strtotime(get_lastpostmodified('GMT'))); ?></lastmod><changefreq>daily</changefreq><priority>1.0</priority></url><?php // 文章 $posts = get_posts('numberposts=-1&orderby=post_date&order=DESC'); foreach($posts as $post) : ?><url><loc><?php echo get_permalink($post->ID); ?></loc><lastmod><?php echo str_replace(" ", "T", get_post($post->ID)->post_modified); ?>+00:00</lastmod><changefreq>monthly</changefreq><priority>0.6</priority></url><?php endforeach; // 页面 $pages = get_pages('numberposts=-1&orderby=post_date&order=DESC'); foreach($pages as $page) :?><url><loc><?php echo get_page_link($page->ID); ?></loc><lastmod><?php echo str_replace(" ", "T", get_page($page->ID)->post_modified); ?>+00:00</lastmod><changefreq>weekly</changefreq><priority>0.6</priority></url><?php endforeach; // 分类 $categorys = get_terms('category', 'orderby=name&hide_empty=0'); foreach ($categorys as $category) : ?><url><loc><?php echo get_term_link($category, $category->slug); ?></loc><changefreq>weekly</changefreq><priority>0.8</priority></url><?php endforeach; // 标签 $tags = get_terms('post_tag', 'orderby=name&hide_empty=0'); foreach ($tags as $tag) : ?><url><loc><?php echo get_term_link($tag, $tag->slug); ?></loc><changefreq>monthly</changefreq><priority>0.4</priority></url><?php endforeach;?></urlset><?php $sitemap = ob_get_contents(); ob_clean(); return $sitemap;}

如果您需要添加公告到sitemap中,请在</url>后  <?php  前加入以下代码:

复制<?php endforeach; // 公告 $posts = get_posts('post_type=bulletin&numberposts=-1&orderby=post_date&order=DESC'); foreach($posts as $post) : ?><?php if (_hui('no_bulletin')) { ?><url><loc><?php echo get_permalink($post->ID); ?></loc><lastmod><?php echo str_replace(" ", "T", get_post($post->ID)->post_modified); ?>+00:00</lastmod><changefreq>monthly</changefreq><priority>0.6</priority></url>

注意事项:此方法适合文章内容在1000之内的,超过生成时间较长!


[wordpress教程]历史优惠活动内容
  • 如何在Docker上安装WordPress网站程序?docker安装wordpress教程
  • 腾讯云云数据库MySQL外网启用及外网连接数据库安装WordPress教程
  • AMH教程 – 创建站点、MYSQL数据库、FTP账户搭建WordPress教程
  • 腾讯云云数据库MySQL外网启用及外网连接数据库安装WordPress教程
  • 腾讯云云数据库MySQL外网启用及外网连接数据库安装WordPress教程
  • WordPress教程:如何删除文章的同时删除图片附件以及特色图像
  • WordPress教程之 如何快速批量修改文章内容信息?
  • wordpress教程之wordpress自动内链内链Tag标签&关键词
  • wordpress教程之如何获取WordPress所有分类名字和ID
  • WordPress教程之使用batch cat插件批量更改文章分类
  • wordpress教程之自动为新文章添加已经存在的标签
  • #wordpress教程#为dux主题文章站外链接自动添加nofollow属性
  • AMH教程 – 创建站点、MYSQL数据库、FTP账户搭建WordPress教程

  • 猜你可能想看的VPS


    转载请注明原文地址:http://140.238.13.167:12355/read-73520.html

    下一篇       上一篇