方法一、wp_get_archvies函数
wordpress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现
get_archives(‘postbypost’,10); (显示10篇最新更新文章)
或者
wp_get_archives(‘type=postbypost&limit=20&format=custom’);
type=postbypost:按最新文章排列
limit:限制文章数量最新20篇
format=custom:用来自定义这份文章列表的显示样式(fromat=custom也可以不要,默认以UL列表显示文章标题。)
方法二、query_posts()函数
通过WP的query_posts()函数也能调用最新文章列表的好处就是可以通过Loop控制显示。
query_posts('showposts=6&cat=-10'); while (have_posts()) : the_post(); the_permalink(); the_title(); endwhile;
上面代码的意思是 读取6篇文章,排除分类ID为10里面的文章
三、使用WP_Query函数
$post_query = new WP_Query('showposts=10'); while ($post_query->have_posts()) : $post_query->the_post(); $do_not_duplicate = $post->ID; the_permalink(); the_title(); endwhile;
四、使用 get_results 函数
$result = $wpdb->get_results(“SELECT ID,post_title FROM $wpdb->posts where post_status=’publish’ and post_type=’post’ ORDER BY ID DESC LIMIT 0,10″); foreach ($result as $post) { setup_postdata($post); $postid = $post->ID; $title = $post->post_title;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。