douzang7928 2016-03-03 23:32 采纳率: 100%
浏览 44

如何隐藏Wordpress循环中的精选帖子

I'm using the plugin "Featured Posts" to set featured posts. (plugin link https://wordpress.org/plugins/featured-post/)

I'm displaying featured posts at the top of my homepage, then displaying a list of blog posts at the bottom. However, I don't want featured posts from the top to be repeated in the bottom section.

Can anyone offer guidance on how to exclude featured posts from the loop? I realize I could just add a 'featured' category and exclude from the loop, but I really want to figure this out.

  • 写回答

1条回答 默认 最新

  • drl57959 2016-03-03 23:58
    关注

    It looks like the plugin uses meta keys to mark posts as featured, so you could try using a custom query and exclude posts where that meta key (_is_featured) is set to "yes" like this:

    $args = array(
        'post_type'  => 'post',
        'posts_per_page'=>-1,
        'meta_query' => array(
            array(
                'key'     => '_is_featured',
                'value'   => 'yes',
                'compare' => 'NOT LIKE',
            ),
        ),
    );
    $query = new WP_Query( $args );
    

    You could then run through this loop like so:

    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            $query->the_post();
            // display the post here
        }
    } else {
        // no posts found
    }
    

    https://codex.wordpress.org/Class_Reference/WP_Query

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)