我正在做一个项目,需要显示自定义帖子的列表,就像使用类别一样。我在函数中创建了一个自定义的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; ?>
欢迎任何建议!