Exo me?看到标题是不是被吓了一跳呢?由于最近重装了系统,有一些保存在C盘的文档忘记备份了,其中就有关于WordPress调用最新、热门、随机文章的示例,因此还是记录在博客上比较重要,不仅可以随时随地拿出来看看,还能顺路唠嗑几句。
最近包揽了两个外包项目,还在努力中,博客似乎真的有一段时间没更新了呢,不说了献上干货(笔记)吧。
调用最新文章:
<?PHP query_posts(‘showposts=14′); ?><ul><?php while (have_posts()) : the_post(); ?><li><a title=”<?php the_title(); ?>” href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li><?php endwhile; ?></ul>
调用热门文章:
<ul><?php$post_num = 14; // 设置调用条数$args = array(‘post_password’ => ”,‘post_status’ => ‘publish’, // 只选公开的文章.‘post__not_in’ => array($post->ID),//排除当前文章‘caller_get_posts’ => 1, // 排除置頂文章.‘orderby’ => ‘comment_count’, // 依評論數排序.‘posts_per_page’ => $post_num);$query_posts = new WP_Query();$query_posts->query($args);while( $query_posts->have_posts() ) { $query_posts->the_post(); ?><li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li><?php } wp_reset_query();?></ul>
调用随机文章:
<ul><?phpglobal $post;$postid = $post->ID;$args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 14);$query_posts = new WP_Query();$query_posts->query($args);?><?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?><li><a href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li><?php endwhile; ?></ul>
联系客服