我在WordPress开发中非常新,我正在尝试实现这个自定义主题,以处理所谓的特色文章:http://lnx.asper-eritrea.com/
如您所见,在主页的posts区域,我有Articoli在evidenza分区,其中包含我的特色帖子,以及包含最新帖子的Ultimi Articoli分区。
为了实现这一点,我使用posts标记,并在未来的posts区域显示具有tag=featured条件的posts。
这是我的密码:
<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> // <?php the_category(', ') ?> // <?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()函数具有标记特征的的帖子:
<?php query_posts('tag=featured');?>现在,我的问题是,如果post有功能的标记,我不希望它显示在最新的post区域(此时显示)。所以我试着用这个代码:
<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> // <?php the_category(', ') ?> // <?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; ?>但是不要工作,主页上仍然显示有特色的帖子。正如您可以看到的,我已经尝试过这样指定,为了显示,一个帖子不能有特色的标记:
<?php query_posts('tag != featured');?>为什么不工作?我遗漏了什么?你能帮我解决这个问题吗?
Tnx
发布于 2014-07-17 07:57:46
若要返回不包含特定标记的帖子,应使用tag__not_in参数。
// 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 ) );发布于 2014-07-17 07:52:37
is_front_page()
您应该尝试<?php is_front_page(); ?>,反之亦然。
page
<?php if (is_front_page()) { ?>
<!-- Do something -->
<?php } else { ?>
<!-- Add else only if you need it! -->
<?php } ?>https://stackoverflow.com/questions/24797713
复制相似问题