dqj5046 2017-03-18 15:45
浏览 347

修复wordpress循环

I am new too wordpress and have one problem. I finaly understand post loop and it work well but have one problem. For example: I have two pages of my posts (all are 6). In one page i have five posts (excerpt only) and on secound page i have one post only and in this case (when on one of my pages i have only one post it change to content post but it need to stay excerpt). So my question is what can i change in my code to make it work well in this case when on some page left only one post?

It's my loop:

    <?php if (have_posts()) : ?>

  <?php if (($wp_query->post_count) > 1) : ?>
     <?php while (have_posts()) : the_post(); ?>
       <!-- Do your post header stuff here for excerpts-->
          <?php the_excerpt() ?>
       <!-- Do your post footer stuff here for excerpts-->
     <?php endwhile; ?>

  <?php else : ?>

     <?php while (have_posts()) : the_post(); ?>
       <!-- Do your post header stuff here for single post-->
          <?php the_content() ?>
       <!-- Do your post footer stuff here for single post-->
     <?php endwhile; ?>

  <?php endif; ?>

<?php else : ?>
     <!-- Stuff to do if there are no posts-->

<?php endif; ?>
  • 写回答

3条回答 默认 最新

  • duanjiao8007 2017-03-18 16:01
    关注

    Ur second if condition should be inside while and while shuld be called once .. Somthing like If While Then if for count Elseif Else End while End if

    I hope it wil help ..

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大