自制WordPress Sitemap Page Template

代码片段:
<?php
$cat_and_art = $wpdb->get_results(“SELECT t.term_id FROM  $wpdb->terms t left join $wpdb->term_taxonomy tt on tt.term_id = t.term_id WHERE tt.taxonomy= ‘category’ and tt.parent=’0′ and tt.count > 0″);

foreach ($cat_and_art as $cat_and_art_id) {
$category_id[] = $cat_and_art_id->term_id;
}
//print_r($category_id);
for($c_id = 0; $c_id < strlen($category_id); $c_id++ ){
?>

<li><?php echo(get_category_parents($category_id[$c_id], TRUE, ”)); ?>
<ul>
<?php /* EDIT THE showposts= NUMBER BELOW FOR MORE POSTS IN EACH CAT */
$my_query = new WP_Query(‘cat=’.$category_id[$c_id].’&showposts=-1′);
while ($my_query->have_posts()) :
$my_query->the_post();
if ( $post->ID == $do_not_duplicate ) continue;
update_post_caches($posts);
$do_not_duplicate = $post->ID;
?>
<li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
</li>
<?php
}
?>

新建一个文件 sitemap.php

首先在文件顶部写入:
<?php
/*
Template Name: sitemap
*/
?>
这样在post page 里就会有 “sitemap” 的选项

然后把上面的代码也一同复制进去。保存到当前theme 文件夹里。

然后后台新建一个页面(page) 填写标题,自定义固定连接,内容为空即可,在右边的模板的下拉菜单里选择刚刚新建的模板。保存页面即可。

Related posts:

  1. Miniml – Free WordPress Theme
  2. Apache日志分析
此条目发表在 代码人生 分类目录,贴了 , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已被标记为 *

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word