wordpress 调用置顶文章和排除置顶文章
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php $sticky = get_option('sticky_posts'); rsort( $sticky ); $sticky = array_slice( $sticky, 0, 4); //调用数量 query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) ); if (have_posts()) : while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php post_thumbnail( ); ?> <p class="caption"><?php the_title(); ?></p></a> </li> <?php endwhile; endif; ?> |
排除置顶文章,并输出文章列表。
1 2 3 4 5 6 | <?php $the_query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();?> <p> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p> <?php endwhile; ?> <?php else : ?> <?php endif; // end have_posts() check ?> |