说明。
2. wordpress调用随机文章 $rand_posts = get_posts('numberposts=10&;orderby=rand'); foreach( $rand_posts as $post ) : ?>
3. wordpress调用最新留言
下面是我之前在一个Wordpress主题中代到的最新留言代码,具体也记不得是哪个主题了。该代码直接调用数据库显示一份最新留言。其中 LIMIT 10限制留言显示数量。绿色部份则是每条留言的输出样式。 global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->commentsment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND post_password = ''
ORDER BY comment_date_gmt DESC LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML; foreach ($comments as $comment) { $output .= "n
".strip_tags($comment->comment_author) .":" . " ID) .
"#comment-" . $comment->comment_ID . "" title="on " .
$comment->post_title . "">" . strip_tags($comment->com_excerpt) ."";
} $output .= $post_HTML; echo $output;?>
4.wordpress调用相关文章 $tags = wp_get_post_tags($post->ID);
if ($tags) {
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>10,
'caller_get_posts'=>1 );
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
endwhile; } }
wp_reset_query(); ?>
5.wordpress调用指定分类的文章