WordPress 文章置顶循环

WordPress文章编辑页,设置文章置顶,还需要修改文章调用函数。

<?php
$sticky = get_option('sticky_posts');
rsort( $sticky ); // 文章数组逆向排序
$sticky = array_slice( $sticky, 0, 3); // 限制只有3个置顶文章
$args = array(
    "cat"=>$product_id,
    "posts_per_page" => 8,
    'post__in' => $sticky
);
query_posts($args); while(have_posts()): the_post(); 
?>
    <a class="card" href="<?php the_permalink(); ?>"><?php the_title() ?></a>
<?php endwhile; wp_reset_query(); ?>

显示置顶文章以后,需要循环调用非置顶文章。

<?php
$the_query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile; endif; ?>
收藏
评论
打赏
WordPress 评论表单函数 comment_form()
上一篇
WordPress 自定义文章排序
下一篇
像素鱼丸
50093 阅读
91 发布
3 收藏
动态
MirageV 主题 2.16.2 发布
MirageV 主题 v2.6.4 发布
LandV 企业主题 v2.6.0 发布
FishV 主题 v1.14 发布
BotV 插件 v1.7.0 发布
FishV 主题 v1.21.0 发布
MirageV 主题 v2.5 正式发布
MirageV 主题 v2.6.0 发布
生成中...
真诚赞赏,手留余香
登录
注册
重置密码