【发布时间】:2016-12-20 13:48:10
【问题描述】:
由于 Wordpress sticky posts 功能允许在帖子发布面板中检查为 sticky 的帖子放置在帖子首页的顶部。我还打算通过自定义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; ?>
结果是我得到了前三个具有自定义样式的帖子(检查为粘性),同时在 标准帖子 输出中重复,但我未能删除。
我尝试将<?php else : ?> 替换为<?php elseif(!is_sticky()) : ?>,但显示的页面已“分页”或当前页码大于1,帖子数根据每页的发布日期减去粘性帖子。
非常感谢任何帮助制作不重复的粘性帖子。
【问题讨论】:
-
你有 2 个循环还是只有 1 个?如果可能的话,请分享整个代码......
-
嘿@Ehab,假设您只有一个循环,请在下面查看我的答案????