0

最初の投稿が全文+大きなサムネイル(特集として)で表示され、次にタイトルのみ+小さなサムネイルで投稿されるカテゴリテンプレートを作成しようとしています。

私は(助けを借りて)2つのクエリでこれを行うことができましたが、最初の投稿は各ページで同じままで、変更されません.また、ループは最初のページのオフセットを他のページにも適用しません.

コードはここにあります:

<?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