若是你是一个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去掉分类连接中category目录的两种方法
▪ query_posts函数把你的wordpress博客变成CMS