无法显示自定义帖子列表

时间:2013-04-08 作者:Tietje

我正在做一个项目,需要显示自定义帖子的列表,就像使用类别一样。我在函数中创建了一个自定义的post类型(称为“videor”)。php:

function register_rc() { // A unique name for our function
$labels = array( // Used in the WordPress admin
    \'name\' => _x(\'Videoer\', \'post type general name\'),
    \'singular_name\' => _x(\'Video\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New\', \'Video\'),
    \'add_new_item\' => __(\'Add New Video\'),
    \'edit_item\' => __(\'Edit Video\'),
    \'new_item\' => __(\'New Video\'),
    \'view_item\' => __(\'View Video \'),
    \'search_items\' => __(\'Search Videos\'),
    \'not_found\' =>  __(\'Nothing found\'),
    \'not_found_in_trash\' => __(\'Nothing found in Trash\')
);
$args = array(
    \'labels\' => $labels, // Set above
    \'public\' => true, // Make it publicly accessible
    \'hierarchical\' => true, // No parents and children here
    \'menu_position\' => 5, // Appear right below "Posts"
    \'has_archive\' => \'resources\', // Activate the archive
    \'supports\' => array(\'title\',\'editor\',\'comments\',\'thumbnail\',\'custom-fields\'),
    \'taxonomies\' => array(\'category\', \'post_type\'),
    \'public\' => true,
    \'show_ui\' => true,
    \'exclude_from_search\' => true,
    \'query_var\' => true,
);

register_post_type( \'videoer\', $args );
}

这在wordpress管理区域中运行良好,我也可以正确显示帖子。我给每篇文章都加了一个类别,叫做videoer (与costum post类型的名称相同)。现在如果我想显示该类别下的所有帖子videoer 我什么也得不到。

我已经在我的video-category.php:

    <?php $loop = new WP_Query( array( \'post_type\' => \'videoer\', \'posts_per_page\' => 100   )  ); ?>
   <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
   <?php the_post_thumbnail(); ?>
   <h3><?php the_title() ?></h3>
   <a href="<?php the_permalink() ?>">Read More</a>

   <?php endwhile; ?>
欢迎任何建议!

1 个回复
SO网友:Tom J Nowell

您的videoer 帖子类型将在以下位置进行帖子存档:example.com/videor 列出了所有videoer 帖子You shouldn\'t try to reinvent taxonomies using page templates. Instead use a custom taxonomy and call it something like videoer_category. Use the rewrite option on registration to change it to category and you\'ll be able to have archives such as example.com/videor/category/<term name here>/taxonomy-videoer_category.php 然后,您可以通过进一步深入模板继承权,以这种方式设置各个术语的样式。我建议您在codex上查找有用的图表,您可以使用single-videoer.php

  • videoer 是一个复杂的名字(不是真正的英语单词),也许你应该把它重命名为视频,或者如果你指的是拍摄电影的人,“制片人”,你会使用很多不必要的PHP开头和结尾标记。你不需要用?> 并将<?php 在下一行中,如果中间没有HTML,只会使它更难阅读,更容易犯愚蠢的错误

  • 结束

    相关推荐