我有自定义的post-post-type调用“news”,我正在努力让它正确分页。我正在寻找一个简单的上一页和下一页的链接,不担心中间的在中间。
在页面新闻中。php这是我的代码:
<?php
$paged = get_query_var(\'paged\') ? get_query_var(\'paged\') : 1;
$args = array(\'post_type\' => \'news\', \'posts_per_page\' => 2, \'paged\' => $paged);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
// Loop
<?php endwhile; wp_reset_postdata(); ?>
<div id="pagination" class="clearfix">
<?php posts_nav_link(); ?>
</div>
上面的代码显示了2篇文章,但没有分页链接这是我的自定义帖子类型代码:
function custom_post_news() {
register_post_type( \'news\',
array(\'labels\' => array(
\'name\' => __(\'News\', \'post type general name\'), /* This is the Title of the Group */
\'singular_name\' => __(\'News\', \'post type singular name\'), /* This is the individual type */
\'add_new\' => __(\'Add New\', \'custom post type item\'), /* The add new menu item */
\'add_new_item\' => __(\'Add New\'), /* Add New Display Title */
\'edit\' => __( \'Edit\' ), /* Edit Dialog */
\'edit_item\' => __(\'Edit\'), /* Edit Display Title */
\'new_item\' => __(\'New \'), /* New Display Title */
\'view_item\' => __(\'View\'), /* View Display Title */
\'search_items\' => __(\'Search news\'), /* Search Custom Type Title */
\'not_found\' => __(\'Nothing found in the Database.\'), /* This displays if there are no entries yet */
\'not_found_in_trash\' => __(\'Nothing found in Trash\'), /* This displays if there is nothing in the trash */
\'parent_item_colon\' => \'\'
), /* end of arrays */
\'description\' => __( \'This is the example custom post type\' ), /* Custom Type Description */
\'public\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'show_ui\' => true,
\'query_var\' => true,
\'menu_position\' => 2, /* this is what order you want it to appear in on the left hand side menu */
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'rewrite\' => array(\'slug\' => \'news\', \'with_front\' => true ),
/* the next one is important, it tells what\'s enabled in the post editor */
\'supports\' => array( \'title\', \'editor\', \'thumbnail\')
)
);
}
// REGISTER TAXOMONIES
add_action( \'init\', \'custom_post_news\');
register_taxonomy( \'custom_news\',
array(\'news\'), /* if you change the name of register_post_type( \'movies\', then you have to change this */
array(\'hierarchical\' => true,
\'labels\' => array(
\'name\' => __( \'News Categories\' ), /* name of the custom taxonomy */
\'singular_name\' => __( \'news Category\' ), /* single taxonomy name */
\'search_items\' => __( \'Search news Categories\' ), /* search title for taxomony */
\'all_items\' => __( \'All news Categories\' ), /* all title for taxonomies */
\'parent_item\' => __( \'Parent news Category\' ), /* parent title for taxonomy */
\'parent_item_colon\' => __( \'Parent news Category:\' ), /* parent taxonomy title */
\'edit_item\' => __( \'Edit news Category\' ), /* edit custom taxonomy title */
\'update_item\' => __( \'Update news Category\' ), /* update title for taxonomy */
\'add_new_item\' => __( \'Add New news item\' ), /* add new title for taxonomy */
\'new_item_name\' => __( \'New Custom news\' ) /* name title for taxonomy */
),
\'show_ui\' => true,
\'query_var\' => true,
)
);
这是一个自定义主题(从头开始),所以我的函数中没有任何内容。php引用分页。我在互联网上搜寻答案,但我得到了不同的解决方案,似乎什么都不起作用。我也没有新闻档案。我不确定这是否需要实现?