置頂文章歸置頂的樣式,在循環文章列表中排除置頂文章.
Case1置頂列表解決方案:
在要插入置頂文章列表的地方寫入以下語句:
- <?php query_posts(array('showposts' => 1, 'post__in' => get_option('sticky_posts'), 'caller_get_posts' => 1 )); if (have_posts()) : while (have_posts()) : the_post(); ?>
將置頂文章的代碼表示如下:
- <ul> <?php post_class(); ?> id="post-<?php the_ID(); ?>">
- <li>
- <div class="article">
- <h2 class="entry-title">
- <i class="sticky sticky_ordinary"></i>
- <a href="<?php the_permalink() ?>" rel="bookmark" title="詳細閱讀 <?php the_title_attribute(); ?>">
- <?php the_title();?><font style="color:#f00;">( 于<?php echo mysql2date('Y-m-j', $post->post_modified); ?>更新 )</font>
- </a>
- <span class="new">
- <?php include('includes/new.php'); ?>
- </span>
- </h2>
- </div>
- </li>
- </ul>
最后結束置頂循環列表,代碼如下:<?php endwhile; endif;?>
Case2排除置頂文章的列表解決方案,代碼如下:
<?phpif ( have_posts() ) : while ( have_posts() ) : the_post();?>
在原先的循環語句上替換如下去除置頂列表的代碼,代碼如下:
- <?php
- $args=array(
- 'post_status' => 'publish',
- 'paged' => $paged,
- 'caller_get_posts' => 1,
- 'posts_per_page' => $post_num
- );
- query_posts($args);
- if ( have_posts() ) : while ( have_posts() ) : the_post();
- ?>
Ok!趕緊更新index.php,刷新下首頁看看.
新聞熱點
疑難解答
圖片精選