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

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

1、get_archives()函数html

<?php get_archives("postbypost", 10); ?> //显示10篇最新更新文章

或者数据库

<?php wp_get_archives(‘type=postbypost&limit=20&format=custom’); ?>//显示20篇最新更新文章

后面这个代码显示你博客中最新的20篇文章,其中format=custom这里主要用来自定义这份文章列表的显示样式。(fromat=custom也能够不要,默认以UL列表显示文章标题。)wordpress

更多get_archives()函数的用法, 请参考官网:http://codex.wordpress.org.cn/Function_Reference/wp_get_archives函数

2、遍历文章数据库工具

<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>

3、query_posts()函数post

<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>

更多方法:wordpress调用最新文章五种方法包括排除置顶文章网站

您可能感兴趣的文章:spa


▪ wordpress标签云显示文章数量两种方法插件

▪ WordPress去掉分类连接中category目录的两种方法

▪ query_posts函数把你的wordpress博客变成CMS

▪ wordpress获取分类下文章列表四种方法

▪ 图片类Wordpress网站必备响应式灯箱插件WF Magnific Lightbox

▪ WordPress 开发带缩略图的小工具最新文章

▪ Wordpress自定义pre样式DIY代码高亮

▪ query_posts在你的边栏显示指定ID的文章

▪ 解决wordpress页面(page)分页失效

▪ WordPress浏览次数统计插件:WP-PostViews Plus