0

我正在尝试制作一个类别模板,其中第一篇文章显示为全文+大缩略图(如特色),然后只显示标题+较小的缩略图。

我已经(在帮助下)通过两个查询来做到这一点,但第一个帖子在每个页面上保持不变,不会改变,同样,循环也不会采用第一页的偏移量到其他页面。

代码在这里:

<?php $cat_link = get_category_link( $cat_id );
      $cat_name = get_cat_name($cat_id);
      $cat_id = 22; ?>

<?php $latest_cat_post = new WP_Query( array('posts_per_page' => 1, 'category__in' => array($cat_id)));
      if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post(); ?>

      <div class="catrecent">
           <div class="recenttitle">
           <h2 class="catidtxt"> <a href="<?php echo ($cat_link); ?>" title="<?php echo ($cat_name); ?>"><?php echo ($cat_name); ?></a></h2>
           <h2 class="recentposttitle"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>       
      </div>
           <?php if( has_post_thumbnail() ) { ?>
                 <div class="recentpostwrap">
                 <?php the_post_thumbnail( 'thumbcatbig' ); ?>
                 <?php the_content_limit(588,""); ?>
                 <div class="readrecent">
                 <a href="<?php the_permalink(); ?>"><?php _e("more", "mm"); ?></a>
                 </div>
                 </div>
           <?php } else { ?>
                 <div class="holder no-thumb-big">                                                                               
                 <?php the_content_limit(798,""); ?>
                 <div class="more">
                 <a href="<?php the_permalink(); ?>"><?php _e("more", "mm"); ?></a>
                 </div>
                 </div>
           <?php } ?>

           <?php endwhile; else: ?><?php endif; ?><?php wp_reset_query(); ?>
     </div>





<ul class="catlist-recent">
    <?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $ppp = 7;
    $offset = 1;
    $cat_id = '22,27,29';

    //Manually determine page query offset (offset + current page (minus one) x posts per page)
    $page_offset = $offset + ( ($paged - 1) * $ppp );

    $query = new wp_query(array(
        'offset'         => $page_offset,
        'posts_per_page' => $ppp,
        'cat'            => $cat_id,
        'paged'          => $paged
    ));

    if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

    <li class="catlist-recentpost">
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'thumbcatsmall' ); ?></a>
        <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?> </a>
                <div class="catlist-recentposttxt">  <?php the_content_limit(300, ''); ?></div>
    </li>

    <?php endwhile; else: ?><?php endif; ?>
</ul>

<div class="cat-pagenate">
<?php
// pagination
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
    'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) )    ),
    'total'   => ceil(($query->found_posts - $offset) / $ppp),
    'format'  => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
));
wp_reset_query();
?>
</div>

任何帮助表示赞赏!

4

1 回答 1

0

尝试

$query = new wp_query(array(
    'offset' => $page_offset,
    'number' => $ppp,
    'cat' => $cat_id,
    'page' => $paged
));

注意从“paged”到“page”的变化

于 2014-03-31T04:19:45.003 回答