我想要我的单曲{slug}。php对来自不同自定义帖子类型的帖子列表执行查询,并使用分页。分页显示,但遗憾的是,单击分页不会转到该页,并且始终保留在第1页。目前正在使用WP navi,btw。
示例:从单个运动加载帖子列表。php到单个电影。php
如有任何建议或帮助,将不胜感激。
这是我的单曲{slug}。php:
<?php
$args = array(
\'post_type\' => \'crew\',
\'paged\' => ( get_query_var(\'paged\') ? get_query_var(\'paged\') : 1),
);
while (have_posts()) : the_post();
/* Do whatever you want to do for every page... */
?>
<div class="project_item">
<div class="dotted">
<hr />
</div>
<div class="project_thumb"><a href="<?php echo get_permalink(); ?>"><img src="" /></a></div>
<div class="project_entry"><h4><a href="<?php echo get_permalink(); ?>"></a></h4>
<a href="<?php echo get_permalink(); ?>" class="readmore">Read more..</a> </div>
</div>
<?php
endwhile;
?>
<nav>
<?php wp_pagenavi(array(\'query\'=>$post_query)); ?>
</nav>
<?php
wp_reset_query(); // Restore global post data
?>
这是我的功能。php:
$labels = array(
\'name\' => _x(\'Crew\', \'post type general name\'),
\'singular_name\' => _x(\'A crew\', \'post type singular name\'),
\'add_new\' => _x(\'Add A New Crew\', \'crew\'),
\'add_new_item\' => __(\'Add A New Creww\'),
\'edit_item\' => __(\'Edit Crew\'),
\'new_item\' => __(\'New Crew\'),
\'view_item\' => __(\'View Crew\'),
\'search_items\' => __(\'Search Cre\'),
\'not_found\' => __(\'Crew Not Found\'),
\'not_found_in_trash\' => __(\'Not found in trash\'),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'menu_position\' => 6,
\'public\' => true,
\'supports\' => array(\'title\', \'editor\', \'thumbnail\'),
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'has_archive\' => true,
);
register_post_type(\'crew\',$args);
$args = array(
\'label\' => \'Author Catefory\',
\'public\' => true,
\'show_ui\' => true,
\'hierarchical\' => true
);
register_taxonomy(\'crew_tax\',\'crew\',$args);
最合适的回答,由SO网友:Jérome Obbiet 整理而成
您忘记启动新查询。
如果您在自定义查询中不使用have post,您将得到当前的主要查询,在您的情况下是您的single。
$args = array(
\'post_type\' => \'crew\',
\'posts_per_page\' => 10
);
$your_custom_query = new WP_Query( $args ); // is that you forgot
// The Loop
if ( $your_custom_query->have_posts() ) :
while ( $your_custom_query->have_posts() ) : $your_custom_query->the_post();
// Do Stuff
endwhile;
endif;
我不知道什么是wp\\u pagenvi()
使用paginate\\u links()
$big = 999999999; // need an unlikely integer
$pagination_args = array(
\'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
\'format\' => \'?paged=%#%\',
\'current\' => max( 1, get_query_var(\'paged\') ),
\'total\' => $your_custom_query->max_num_pages,
\'type\' => \'plain\',
\'prev_text\' => \'Prev\',
\'next_text\' => \'Next\'
);
echo( paginate_links( $pagination_args ) );
并通过重置完成
wp_reset_postdata();