由于Wordpress 粘贴帖子功能允许在帖子发布面板中检查为粘性的帖子放置在帖子首页的顶部.通过自定义The Loop默认编码,我还打算通过自定义循环默认编码来设置粘贴帖子的风格与循环中的普通邮件不同:
<?php if (have_posts()) : ?>
<?php $post = $posts[0]; $c=0;?>
<?php while (have_posts()) : the_post(); ?>
<?php $c++;
if( is_home() && !$paged && $c == 1 ) :?>
<!--First sticky post content -->
<?php elseif( is_home() && !$paged && $c == 2 ) :?>
<!--Second sticky post content -->
<?php elseif( is_home() && !$paged && $c == 3 ) :?>
<!--Third sticky post content -->
<?php else:?>
<!-- Standard post content -->
<?php endif;?>
<?php endwhile; ?>
<!-- End of the main loop -->
//pagination
<?php else : ?>
<?php _e('Sorry, no posts matched your criteria.'); ?>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)
结果是我得到了前三个帖子(检查为粘性)和自定义样式,而在标准帖子输出中重复,我没有摆脱.
我试图替换<?php else : ?>,<?php elseif(!is_sticky()) : ?>但是显示的页面被"分页"或者当前页面编号大于1,根据每页的发布日期,粘贴帖子减去了帖子数量.
非常感谢任何帮助使粘贴帖子不重复的帮助.
| 归档时间: |
|
| 查看次数: |
1101 次 |
| 最近记录: |