当我点击主页上的“旧条目”时,它会转到第二个链接,但显示的是相同的帖子。我想我需要修改index.php
, 这是我认为需要修改的完整代码部分:
<div class="container">
<div class="post_content">
<div class="home_posts">
<?php
$args2 = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 10,
\'paged\' => ( get_query_var(\'paged\') ? get_query_var(\'paged\') : 2),
);
$query = new WP_Query( $args2 );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
echo \'<div class="grid_post">
<h3><a href="\'.get_permalink().\'">\'.get_the_title().\'</a></h3>\';
$type = get_post_meta($post->ID,\'page_featured_type\',true);
switch ($type) {
case \'youtube\':
echo \'<iframe width="560" height="315" src="http://www.youtube.com/embed/\'.get_post_meta( get_the_ID(), \'page_video_id\', true ).\'?wmode=transparent" frameborder="0" allowfullscreen></iframe>\';
break;
case \'vimeo\':
echo \'<iframe src="http://player.vimeo.com/video/\'.get_post_meta( get_the_ID(), \'page_video_id\', true ).\'?title=0&byline=0&portrait=0&color=03b3fc" width="500" height="338" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>\';
break;
default:
echo \'<div class="grid_post_img">
<a href="\'.get_permalink().\'">\'.get_the_post_thumbnail().\'</a>
</div>\';
break;
}
echo \'<div class="grid_home_posts">
<p>\'.dess_get_excerpt(120).\'</p>
</div>
</div>
\';
endwhile;
?>
</div>
<?php
echo \'<div class="load_more_content"><div class="load_more_text">\';
ob_start();
next_posts_link(\'LOAD MORE\',$query->max_num_pages);
$buffer = ob_get_contents();
ob_end_clean();
if(!empty($buffer)) echo $buffer;
echo\'</div></div>\';
$max_pages = $query->max_num_pages;
wp_reset_postdata();
endif;
?>
<span id="max-pages" style="display:none"><?php echo $max_pages ?></span>
</div>
<?php get_sidebar(); ?>
<div class="clear"></div>
</div>
</div>
可能在这里:
<?php
$args2 = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 6,
\'paged\' => ( get_query_var(\'paged\') ? get_query_var(\'paged\') : 1),
);
$query = new WP_Query( $args2 );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
echo \'<div class="grid_post">
这是“旧条目”的URL:
http://www.wha2wear.com/page/2/ 显示与主页相同的内容。此外,我真的看不到代码中的某个地方写了“旧条目”。。
另外,在实际页面、头版中,有以下代码
[posts-for-page order_by =\'date\' hide_images=\'false\' num=\'11\' read_more=\'
Read More »\' show_full_posts=\'false\' use_wp_excerpt=\'true\' strip_html=\'true\' hide_post_content=\'false\' show_meta=\'false\' force_image_height=\'200\' force_image_width=\'250\']
I have the feeling that this code has higher priority than the php, so the homepage does what it says there?
SO网友:ma_dev_15
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args=array(
\'orderby\'=> \'id\',
\'order\' => \'desc\',
\'paged\'=>$paged
);
global $wp_query;
$original_query = $wp_query;
$wp_query = null;
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
while ( have_posts() ):
the_post();
get_template_part( \'template-parts/content\', get_post_format());
endif;
$count++;
endwhile;
// If no content, include the "No posts found" template.
else :
get_template_part( \'template-parts/content\', \'none\' );
endif;
$nav = get_the_posts_pagination( array(
\'mid_size\' => 4,
\'prev_text\' => __( \'«\', \'twentysixteen\' ),
\'next_text\' => __( \'»\', \'twentysixteen\' ),
\'before_page_number\' => \'<span class="meta-nav screen-reader-text">\' . __( \'\', \'twentysixteen\' ) . \' </span>\',
\'screen_reader_text\' => __( \'Post Navigation\' )
) );
$nav = str_replace(\'<h2 class="screen-reader-text">Post Navigation</h2>\', \'\', $nav);
echo $nav;
$wp_query = null;
$wp_query = $original_query;
wp_reset_postdata();$wp_query = null;
$wp_query = $original_query;
wp_reset_postdata();
这就是它的工作方式,您需要更新WP\\u查询,而不是使用另一个对象,它不能用于分页。