【发布时间】:2016-12-29 06:14:39
【问题描述】:
我正在尝试创建一个类似于 WordPress 提供的默认帖子的额外内容区域。我的结果是在页面上循环这些帖子而不需要 WordPress 默认帖子,因为它们将用于我的博客。
我已经设置了管理区域来创建帖子,它显示在我的主题中,但我遇到了问题。它只显示最近的帖子,而不是循环所有帖子
我使用了帮助我构建它的指南。 adding editable areas 可以帮助大家理解。
任何人都知道如何修复它,所以它会显示所有帖子,而不仅仅是最新的?
到目前为止我的代码:
example-page.php
<p>
<?php $content_block = new WP_Query(array('post_type'=>'content-block',
'posts_per_page'=>10, 'content-position'=>'about-bottom'))?>
<?php if($content_block->have_posts()): $content_block->the_post(); ?>
<?php the_content();?>
<?php endif; ?>
</p>
functions.php
function initialize_content_blocks() {
register_post_type('content-block', array(
'labels' => array(
'name' => 'Page Content ',
'singular_name' => 'Content Block',
'add_new_item' => 'Add New Content Block',
'edit_item' => 'Edit Content Block',
'new_item' => 'New Content Block',
'view_item' => 'View Content Block',
'search_items' => 'Search Content Blocks',
'not_found' => 'No content_blocks found',
'not_found_in_trash' => 'No content blocks found in Trash',
'view' => 'View Content Block'
),
'publicly_queryable' => false,
'exclude_from_search' => true,
'public' => true,
'rewrite' => false,
'supports' => array('title', 'editor'),
'taxonomies' => array()
));
register_taxonomy('content-position', array('content-block'), array(
'rewrite' => false,
'labels' => array(
'name' => 'Content Positions',
'singular_name' => 'Content Position',
'search_items' => 'Search Content Positions',
'popular_items' => 'Popular Content Positions',
'all_items' => 'All Content Positions',
'edit_item' => 'Edit Content Position',
'update_item' => 'Update Content Position',
'add_new_item' => 'Add New Content Position',
'new_item_name' => 'New Tag Content Position'
),
'show_tagcloud' => false,
'hierarchical' => true
));
}
add_action('init', 'initialize_content_blocks');
【问题讨论】: