wordpress最新文章实现的三种方法 wordpress



如果你是一个WordPress主题开发者,或者wordpress谜,那么自己动手实现纯代码的wp最新文章,小编下面的文章对你有所帮助。


一、get_archives()函数

<?php get_archives("postbypost", 10); ?> //显示10篇最新更新文章
或者
<?php wp_get_archives(‘type=postbypost&limit=20&format=custom’); ?>//显示20篇最新更新文章
后面这个代码显示你博客中最新的20篇文章,其中format=custom这里主要用来自定义这份文章列表的显示样式。(fromat=custom也可以不要,默认以UL列表显示文章标题。)


二、遍历文章数据库

<ul>
<?php
  $new_posts = get_posts(‘numberposts=10&order=ASC&orderby=title’);
  foreach( $new_posts as $post ) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>


三、query_posts()函数

<li>  
    <h2>最新文章</h2>  
    <?php query_posts('showposts=6&cat=-111'); ?>  
    <ul>  
        <?php while (have_posts()) : the_post(); ?>  
        <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>  
        <?php endwhile;?>  
     </ul>  
</li>


签名:这个人很懒,什么也没有留下!
最新回复 (0)
返回