WordPress自定义帖子类型分类页面
我有一个称为tutorials的自定义帖子类型。WordPress自定义帖子类型分类页面
我可以去mysite.com/tutorials并获得所有教程的列表。
我也创建了一个叫做tutorial_categories与下面的代码自定义分类:
register_taxonomy(
'tutorial_categories',
'tutorials',
array(
'labels' => array(
'name' => 'Tutorial Categories',
'add_new_item' => 'Add New Tutorial Category',
'new_item_name' => "New Tutorial Category"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'hasArchive' => true
)
);
我觉得这是一个插件的一部分,让我做这件事。
如何创建一个分类页面的tutorial_category,所以如果有人去:
mysite.com/tutorials/php/
他们将获得教程的一个列表(自定义后型) PHP的自定义分类。
任何帮助将不胜感激,因为我做了一些谷歌搜索,我似乎无法找到这个问题的答案。
谢谢!
Leon。
首先,建立一个新的页面模板。
最简单的方法是复制当前的page.php文件并将其保存为:tutorials-page.php。
在顶部,这包括:
<?php
/*
Template Name: Tutorials Page
*/
?>
然后用下面的自定义循环替换新的教程-page.php文件文件的循环:
<?php $args=array(
'post_type' => 'tutorials', //set the post_type to use.
'taxonomy' => 'tutorial_categories', // set the taxonomy to use.
'term' => 'php', //set which term to use.
'posts_per_page' => 10 // how many posts or comment out for all.
);
$tutorialsloop = new WP_Query($args);
if($tutorialsloop->have_posts()) : while($tutorialsloop->have_posts()) :
$tutorialsloop->the_post();
get_template_part('content'); //or whatever method your theme uses for displaying content.
endwhile; endif; //end the custom post_type loop
?>
然后,让一个新的页面,并分配这个新的页面模板。
还没有尝试过,但看起来很有希望。
http://wp-types.com/documentation/user-guides/creating-wordpress-custom-taxonomy-archives/
谢谢。所以通过查看那篇文章和我上面发布的代码。我应该能够创建一个分类页面:taxonomy-tutorial_categories.php,然后转到mysite.com/tutorials/php-tutorials(“php-tutorials”是我的自定义帖子类型教程下的PHP类别的子弹)。这仍然不起作用,我只是没有找到页面:(谢谢你的帮助! –
我不明白这是如何正确的答案。这不会产生'/ custom_post_type/taxonomy'的永久链接。它也是一个非常硬编码的解决方案,不是真正可扩展的.. – Bill