我希望能够在分类页面的顶部显示粘性帖子。我正在使用存档。php用于我的分类页面。
我使用下面的代码在我的分类归档页面的顶部显示粘性帖子,然后显示该分类中的其他帖子。
这很好,直到类别中没有可显示的粘性帖子,然后复制帖子列表。
<?php
// get the current category
$category = get_the_category();
// get the sticky post in the category, order by title - ascending
query_posts(array( \'post__in\' => get_option(\'sticky_posts\'), \'orderby\' => \'title\', \'post_date\' => \'DESC\' , \'cat\' => \'\'.$category[0]->cat_ID.\'\' ));
?>
<?php if (have_posts()) : ?>
<?php
if ($cat)
{echo "<h2>Articles in " . get_the_category_by_ID($cat) . "</h2>";}
?>
<ul id="archive-list">
<?php while (have_posts()) : the_post(); ?>
<li class="sticky"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span>Updated on <?php the_modified_date(); ?> at <?php the_modified_time() ?></span></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php
// get the sticky post in the category, order by title - ascending
query_posts(array( \'post__not_in\' => get_option(\'sticky_posts\'), \'orderby\' => \'title\', \'post_date\' => \'DESC\' , \'cat\' => \'\'.$category[0]->cat_ID.\'\' ) );
?>
<?php if (have_posts()) : ?>
<ul id="archive-list">
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span>Updated on <?php the_modified_date(); ?> at <?php the_modified_time() ?></span></li>
<?php endwhile; ?>
</ul>
<?php if(function_exists(\'wp_page_numbers\')) { wp_page_numbers(); } ?>
<?php else : ?>
<h1 class="center">Sorry, no articles have been published in the <?php if ($cat) {echo "" . get_the_category_by_ID($cat) . "";} ?> category.</h1>
<?php include (TEMPLATEPATH . \'/searchform.php\'); ?>
<?php endif; ?>
任何帮助都将不胜感激!谢谢