我最近一直在建立一个网站,我遇到了分页的问题。我在每个页面上获得相同的帖子(在这种情况下是投资组合帖子)。我一直在谷歌搜索如何解决这个问题,但似乎这个问题在每个主题上都是个体的。
这是我正在使用的页面模板中的代码...
<?php if ( have_posts() ) while ( have_posts() ) : the_post();
$pag = get_post_meta( $post->ID, 'folio_pag', true );
$per = get_post_meta( $post->ID, 'folio_per', true );
$style = get_post_meta( $post->ID, 'folio_style', true );
$animation = get_post_meta( $post->ID, 'folio_anim', true );
$color = get_post_meta( $post->ID, 'folio_color', true );
$info = get_post_meta( $post->ID, 'folio_info', true );
$ratio = get_post_meta( $post->ID, 'folio_ratio', true );
$r = explode( ':', $ratio );
$cols = get_post_meta( $post->ID, 'folio_cols', true );
$c = $cols == 'two' ? 648 : ( $cols == 'three' ? 432 : 324 );
$img_factor = '0';
$cats = get_post_meta( $post->ID, 'folio_cats', true );
$query_filter = '';
$filter_output = '<li><a href="#" data-filter="*" class="selected">' . __( 'All', 'krown' ) . '</a></li>';
$show_cats = get_post_meta( $post->ID, 'folio_filter', true ) == 'enable-filters' ? true : false;
if ( ! empty ( $cats ) ) {
if ( sizeof( $cats ) == 1 ) {
$show_cats = false;
}
foreach ( $cats as $cat ) {
$filter = get_term_by( 'id', $cat, 'portfolio_category' );
$query_filter .= $filter->slug . ', ';
$filter_output .= '<li><a href="#" data-filter=".' . $filter->slug . '">' . $filter->name . '</a></li>';
}
} else {
$cats = get_categories( array( 'taxonomy'=>'portfolio_category' ) );
foreach ( $cats as $cat ) {
$filter_output .= '<li><a href="#" data-filter=".' . $cat->slug . '">' . $cat->name . '</a></li>';
}
}
?>
<?php if ( get_post_meta( $post->ID, 'folio_content', true ) == 'content-above' ) {
the_content();
} ?>
<?php if ( $show_cats ) {
echo '<div id="filter"><ul class="clearfix">' . $filter_output . '</ul></div>';
} ?>
<div id="portfolio-holder" class="clearfix">
<ul id="portfolio" class="folio-grid cols-<?php echo $cols; ?> style-<?php echo $animation . ' ' . $color; ?> show-<?php echo $info; ?> layout-<?php echo $style; ?> clearfix">
<?php
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : ( get_query_var( 'page' ) ? get_query_var( 'page' ) : 1 );
$args = array(
'post_type' => 'portfolio',
'portfolio_category' => $query_filter,
'offset' => 0,
'posts_per_page' => ( $pag == 'no-pagination' ? -1 : $per ),
'paged' => $paged
);
$all_posts = new WP_Query( $args );
$page_id = $post->ID;
while ( $all_posts->have_posts() ) : $all_posts->the_post();
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_image_src( $thumb, 'full' );
if ( $thumb == '' ) {
$img_url = Array( get_template_directory_uri() . '/images/blank_2.gif' );
}
$retina = krown_retina();
$retina_thumb = get_post_meta( $post->ID, 'portfolio_retina-thumbnail_thumbnail_id', true );
if ( $style == 'fixed' ) {
switch ( $cols ) {
case 'two':
$img_width = 648;
$img_height = ceil( $img_width / $r[0] * $r[1] );
break;
case 'three':
$img_width = 432;
$img_height = ceil( $img_width / $r[0] * $r[1] );
break;
default:
$img_width = 324;
$img_height = ceil( $img_width / $r[0] * $r[1] );
break;
}
if ( $retina === 'true' && $retina_thumb != '' ) {
$retina_url = wp_get_attachment_image_src( $retina_thumb, 'full' );
$image = aq_resize( $retina_url[0], $img_width*2, $img_height*2, true, false );
} else {
$image = aq_resize( $img_url[0], $img_width, $img_height, true, false );
}
} else if ( $style == 'masonry' ) {
$img_factor = 1;
$img_width = $c;
if ( $retina === 'true' && $retina_thumb != '' ) {
$retina_url = wp_get_attachment_image_src( $retina_thumb, 'full' );
$image = aq_resize( $retina_url[0], $img_width*2, null, false, false );
} else {
$image = aq_resize( $img_url[0], $img_width, null, false, false );
}
} else if ( $style == 'masonry-advanced' ) {
$img_factor = floor( $img_url[1] / $c );
$img_width = $img_factor * $c;
if ( $retina === 'true' && $retina_thumb != '' ) {
$retina_url = wp_get_attachment_image_src( $retina_thumb, 'full' );
$image = aq_resize( $retina_url[0], $img_width*2, null, false, false );
} else {
$image = aq_resize( $img_url[0], $img_width, null, false, false );
}
}
?>
<li class="item <?php krown_categories( $post->ID, 'portfolio_category', ' ', 'slug' ); ?>" data-factor="<?php echo $img_factor; ?>">
<a href="<?php echo get_new_permalink( $page_id, $post->ID, $cats ); ?>">
<img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" alt="<?php the_title(); ?>" />
<div class="caption">
<div>
<div>
<h3><?php the_title(); ?></h3>
<span class="category"><?php krown_categories( $post->ID, 'portfolio_category' ); ?></span>
<span class="excerpt"><?php echo krown_excerpt( 'krown_excerptlength_post' ); ?></span>
</div>
</div>
</div>
</a>
</li>
<?php endwhile;
?>
</ul>
</div>
<?php if ( $pag == 'classic' ) {
krown_pagination( $all_posts, true );
} else if ( $pag == 'infinte-loading' ) {
echo '<div class="infinite-barrier"><span class="preloader"></span><p class="end">' . __( 'No More Projects', 'krown' ) . '</p><a id="infinite-link" href="' . next_posts( 0, false ) . '">' . __( 'Load More Projects', 'krown' ) . '</a></div>';
} ?>
<?php wp_reset_query(); ?>
<?php if ( get_post_meta( $post->ID, 'folio_content', true ) == 'content-below' ) {
the_content();
} ?>
答案 0 :(得分:0)
我认为,因为您在投资组合查询中将offset
设置为0,所以每个其他网页都显示相同内容的原因。您应该更新偏移$offset = $per * ($paged-1)
,以便每次更改页面都会告诉WP_Query
抵消与当前页面上下文匹配的正确数量的帖子。