フォーラムへの返信

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者 yppon

    (@yppon)

    関連記事は以下のようなコードで表示していますが、the_excerptを使っても2ページ目以降だと、その関連記事の該当ページ(2ページ目なら2ページ目)の先頭から抜粋されてしまいます…なぜでしょうか?

    <?php
    $original_post = $post;
    $tags = wp_get_post_tags($post->ID);
    $tagIDs = [];
    if ($tags) {
    $tagcount = count($tags);
    for ($i = 0; $i < $tagcount; $i++) {
      $tagIDs[$i] = $tags[$i]->term_id;
    }
    $args = [
      'tag__in' => $tagIDs,
      'post__not_in' => [$post->ID],
      'showposts' => 2,
      'caller_get_posts' => 1
    ];
    $my_query = new WP_Query($args); ?>
    <?php if( $my_query->have_posts() ) {
      echo '<div class="related-posts"><div class="postauthor-top"><h3>'.__('Related Posts','mythemeshop').'</h3></div><ul>';
      while( $my_query->have_posts() ) { ++$counter; if($counter == 2) { $postclass = 'last'; $counter = 0; } else { $postclass = ''; } $my_query->the_post();?>
        <li class="<?php echo $postclass; ?>">
          <a href="<?php the_permalink();?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
            <span class="rthumb">
    	  <?php if(has_post_thumbnail()): ?>
    	    <?php the_post_thumbnail('related', 'title='); ?>
    	  <?php else: ?>
    	    <img src="<?php echo get_template_directory_uri(); ?>/images/relthumb.png" alt="<?php the_title(); ?>"  width='180' height='120' class="wp-post-image" />
    	  <?php endif; ?>
    	</span>
    	<span class="title">
    	  <?php the_title(); ?>
    	</span>
          </a>
          <div class="post-content image-caption-format-1">
    	<?php the_excerpt(); ?>
          </div>
        </li>
      <?php } echo '</ul></div>'; wp_reset_query(); ?>
    <?php } } ?>
1件の返信を表示中 - 1 - 1件目 (全1件中)