好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

WordPress置顶文章与非置顶文章的列表分离 - Word

WordPress置顶文章与非置顶文章的列表分离

置顶文章归置顶的样式,在循环文章列表中排除置顶文章.

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,刷新下首页看看.

查看更多关于WordPress置顶文章与非置顶文章的列表分离 - Word的详细内容...

  阅读:55次