这是我的主页代码
这是一篇特写文章,我想在这篇文章中用一个类别“拼贴”来排除文章。。。
<?php
$count = 1;
if (have_posts()) : while (have_posts()) : the_post(); if($count == 1) : ?>
<div id="featurd_post">
<div class="ftrd_image">
<?php woo_get_image(\'image\',455,245,\' \'.$GLOBALS[\'align\']); ?> </div>
<div class="fix"></div>
<div class="ftrd_entry">
<h2 class="title">
<a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a>
</h2>
<p class="fetrd_entry"><?php dynamic_excerpt(400); ?></p>
<a href="#" title="" class="read_more">(<?php _e(\'आगे
पढे \', \'shreshthbharat\'); ?>)</a>
</div></div>
<?php else : ?>
<--- Rest of post goes here --- >
<div class="box"><div class="post">
<h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="">
<?php the_title(); ?></a></h2>
SO网友:magicroundabout
要排除类别,需要修改正在运行的查询。使用query\\u posts()函数执行此操作:http://codex.wordpress.org/Function_Reference/query_posts
首先,您需要获取要排除的类别的ID:
$exclude_category = get_term_by(\'name\', \'collage\', \'category\');
然后需要将类别排除添加到查询中,并将新查询传递给query\\u posts:
global $wp_query;
$args = array_merge( $wp_query->query, array( \'category__not_in\' => array( $exclude_category) ) );
query_posts( $args );
将所有这些都放在脚本的顶部,就在循环之前。
希望对你有用!
SO网友:pixelngrain
试试看,这可能有用。。我没有写它,但在wordpress网站上找到了。
<?php query_posts($query_string . \'&cat=-3,-8\'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
<!-- Display the Title as a link to the Post\'s permalink. -->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time(\'F jS, Y\') ?> by <?php the_author_posts_link() ?></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata">Posted in <?php the_category(\', \'); ?></p>
</div> <!-- closes the first div box -->
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
有关更多详细信息,请查看此链接
http://codex.wordpress.org/The_Loop#Exclude_Posts_From_Some_Category