【发布时间】:2014-07-17 07:47:09
【问题描述】:
我是 WordPress 开发的新手,我正在尝试实现这个自定义主题来处理所谓的特色帖子:http://lnx.asper-eritrea.com/
正如您在主页的帖子区域中看到的那样,我有 Articoli in evidenza 子区域,其中包含我的精选帖子,其下方是 Ultimi Articoli 包含最新帖子的子区域。
为了实现这一点,我使用了帖子标签,并在未来帖子区域中显示具有 tag=featured 条件的帖子。
这是我的代码:
<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() 函数显示具有标签 featured 的帖子:
<?php query_posts('tag=featured');?>
现在我的问题是,如果帖子有 featured 标签,我不希望它显示在最新的帖子区域(此时显示)。所以我尝试使用这段代码:
<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; ?>
但不工作,特色帖子仍显示在主页上。如您所见,我尝试过指定要显示的帖子不能具有 featured 标签:
<?php query_posts('tag != featured');?>
为什么不工作?我错过了什么?你能帮我解决这个问题吗?
Tnx
【问题讨论】:
标签: php content-management-system wordpress-theming wordpress