我已经看到了几种(并在StackExchange上尝试了至少15种以上的方法)如何执行自定义post类型循环,但在我的情况下,没有一种可行的方法。
我尝试过使用分页和不分页、使用自定义导航和重置永久链接的方法。
I can get the posts to show, the issue I\'m experiencing is with the navigation loading the same content despite the link changing to page-2.
这是我目前的方法,没有使用paged <?php
$args = array(\'post_type\' => array(\'posts\', \'affiliate-products\'));
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
get_template_part(\'template-parts/content\', \'product\');
endwhile;
the_posts_navigation();
else :
?>
<p><?php esc_html_e(\'Sorry, no posts matched your criteria.\'); ?></p>
<?php endif; ?>
任何人都可以建议一种方法来做这与工作分页的头版。php?提前感谢<;3.编辑:
当前非工作代码,根据有关“pre\\u get\\u posts”功能的建议:主页循环
<?php
if (have_posts()) : while (have_posts()) : the_post();
get_template_part(\'template-parts/content\', \'product\');
endwhile;
the_posts_navigation();
else :
?>
<p><?php esc_html_e(\'Sorry, no posts matched your criteria.\'); ?></p>
<?php endif; ?>
功能。php
add_action( \'pre_get_posts\', function( \\WP_Query $query) {
if ( is_home() && $query->is_main_query() ) {
$query->set(\'post_type\', \'affiliate-products\');
$query->set( \'posts_per_page\', 3 );
}
} );
有什么想法吗?:)