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; ?>
收藏 0
评论
WordPress 主题开发
WordPress 评论表单函数 comment_form()
2021-06-29 22:46:44
WordPress 主题开发
WordPress 自定义文章排序
2021-07-04 17:43:11
生成中...
登录
注册
重置密码