首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在我的主页上不显示有指定标签的帖子?

如何在我的主页上不显示有指定标签的帖子?
EN

Stack Overflow用户
提问于 2014-07-17 07:47:09
回答 2查看 60关注 0票数 1

我在WordPress开发中非常新,我正在尝试实现这个自定义主题,以处理所谓的特色文章http://lnx.asper-eritrea.com/

如您所见,在主页的posts区域,我有Articoli在evidenza分区,其中包含我的特色帖子,以及包含最新帖子的Ultimi Articoli分区。

为了实现这一点,我使用posts标记,并在未来的posts区域显示具有tag=featured条件的posts。

这是我的密码:

代码语言:javascript
复制
<section id="blog-posts">

<header class="header-sezione">
        <h2>Articoli in evidenza</h2>
</header>

<?php query_posts('tag=featured');?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <div id="featured-posts">

    <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
      <div class="meta">
Scritto da <span class="author"><?php the_author_link(); ?></span> &nbsp;//&nbsp;  <?php the_category(', ') ?>  &nbsp;//&nbsp;  <?php comments_popup_link('Nessun Commento', '1 Commento ', '% Commenti'); ?> 
      </div>
      <div class="featured-details"><?php the_excerpt()?>
      <?php $featured_img = get_post_meta($post->ID, 'featured_img', $single = true); ?>
      <a href="<?php the_permalink(); ?>"><img src="<?php echo $featured_img ?>" alt="<?php the_title(); ?>" /></a>
      </div>
    </div>

<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>



    <header class="header-sezione">
        <h2>Ultimi Articoli</h2>
    </header>

    <?php
    if (have_posts()) :
        // Start the Loop.
        while (have_posts()) : the_post();

            /*
             * Include the post format-specific template for the content. If you want to
             * use this in a child theme, then include a file called called content-___.php
             * (where ___ is the post format) and that will be used instead.
             */
            get_template_part('content', get_post_format());

        endwhile;
    else :
        // If no content, include the "No posts found" template.
        get_template_part('content', 'none');

    endif;
    ?>

</section>

正如您首先看到的,我展示了使用query-posts()函数具有标记特征的的帖子:

代码语言:javascript
复制
<?php query_posts('tag=featured');?>

现在,我的问题是,如果post有功能的标记,我不希望它显示在最新的post区域(此时显示)。所以我试着用这个代码:

代码语言:javascript
复制
<header class="header-sezione">
    <h2>Ultimi Articoli NOT FEATURED</h2>
</header>

<?php query_posts('tag != featured');?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <div id="featured-posts">

    <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
      <div class="meta">
Scritto da <span class="author"><?php the_author_link(); ?></span> &nbsp;//&nbsp;  <?php the_category(', ') ?>  &nbsp;//&nbsp;  <?php comments_popup_link('Nessun Commento', '1 Commento ', '% Commenti'); ?> 
      </div>
      <div class="featured-details"><?php the_excerpt()?>
      <?php $featured_img = get_post_meta($post->ID, 'featured_img', $single = true); ?>
      <a href="<?php the_permalink(); ?>"><img src="<?php echo $featured_img ?>" alt="<?php the_title(); ?>" /></a>
      </div>
    </div>

<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>

但是不要工作,主页上仍然显示有特色的帖子。正如您可以看到的,我已经尝试过这样指定,为了显示,一个帖子不能有特色的标记:

代码语言:javascript
复制
<?php query_posts('tag != featured');?>

为什么不工作?我遗漏了什么?你能帮我解决这个问题吗?

Tnx

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-17 07:57:46

若要返回不包含特定标记的帖子,应使用tag__not_in参数。

代码语言:javascript
复制
// get the term using the slug and the tag taxonomy
$term = get_term_by( 'slug', 'featured', 'post_tag' );
// pass the term_id to tag__not_in
query_posts( array( 'tag__not_in' => array ( $term->term_id ) );
票数 1
EN

Stack Overflow用户

发布于 2014-07-17 07:52:37

is_front_page()

您应该尝试<?php is_front_page(); ?>,反之亦然。

page

代码语言:javascript
复制
<?php if (is_front_page()) { ?>
    <!-- Do something -->
<?php } else { ?>
    <!-- Add else only if you need it! -->
<?php } ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24797713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档