分类目录

统计信息

  • 日志总数:59篇
  • 评论总数:2条
  • 分类总数:9个
  • 标签总数:51个
  • 友情链接:3个
  • 网站运行:2871天

2018 年十月
« 七    
1234567
891011121314
15161718192021
22232425262728
293031  
现在位置:    首页 > 社交媒体 > 正文
WordPress常用标签(二)
社交媒体 评论关闭

4.wordpress调用相关文章

在文章页显示相关文章

<?php

$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(); ?>

<li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title();?> <?php comments_number(‘ ‘,’(1)’,’(%)’); ?></a></li>

<?php

endwhile;

}

}

wp_reset_query();

?>

5.wordpress调用指定分类的文章

<?php $posts = get_posts( “category=4&numberposts=10″ ); ?>

<?php if( $posts ) : ?>

<ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

<li>

<a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a>

</li>

<?php endforeach; ?>

</ul>

<?php endif; ?>

6.wordpress去评论者链接的评论输出

<?php

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,14) AS com_excerpt

FROM $wpdb->comments

LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_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 .= “ <li>”.strip_tags($comment->comment_author).”:” . ” <a href=”” . get_permalink($comment->ID) .

“#comment-” . $comment->comment_ID . “” title=”on ” .

$comment->post_title . “”>” . strip_tags($comment->com_excerpt).”</a></li>”;

}

$output .= $post_HTML;

echo $output;?>

7.wordpress调用含gravatar头像的评论输出

<?php

global $wpdb;

$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,10) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ’1′ AND comment_type = ” AND comment_author != ‘郑 永’ AND post_password = ” ORDER BY comment_date_gmt DESC LIMIT 10″;

$comments = $wpdb->get_results($sql);

$output = $pre_HTML;

foreach ($comments as $comment)

{

$output .= “ <li>”.get_avatar(get_comment_author_email(‘comment_author_email’), 18). ” <a href=”” . get_permalink($comment->ID) . “#comment-” . $comment->comment_ID . “” title=”” . $comment->post_title . ” 上的评论”>”. strip_tags($comment->comment_author) .”: “. strip_tags($comment->com_excerpt) .”</a></li>”;

}

$output .= $post_HTML;

$output = convert_smilies($output);

echo $output;

?>

上面代码把comment_author的值改成你的ID,18是头像大小,10是评论数量。

8.wordpress调用网站统计大全

1、日志总数:

<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>

2、草稿数目:

<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>

3、评论总数:

<?php echo $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->comments”);?>

4、成立时间:

<?php echo floor((time()-strtotime(“2008-8-18″))/86400); ?>

5、标签总数:

<?php echo $count_tags = wp_count_terms(‘post_tag’); ?>

6、页面总数:

<?php $count_pages = wp_count_posts(‘page’); echo $page_posts = $count_pages->publish; ?>

7、分类总数:

<?php echo $count_categories = wp_count_terms(‘category’); ?>

8、链接总数:

<?php $link = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = ‘Y’”); echo $link; ?>

9、用户总数:

<?php $users = $wpdb->get_var(“SELECT COUNT(ID) FROM $wpdb->users”); echo $users; ?>

10、最后更新:

<?php $last = $wpdb->get_results(“SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = ‘post’ OR post_type = ‘page’) AND (post_status = ‘publish’ OR post_status = ‘private’)”);$last = date(‘Y-n-j’, strtotime($last[0]->MAX_m));echo $last; ?>

本文版权归不读书的读书人所有,转载引用请完整注明以下信息:
本文作者:望岳
本文地址:WordPress常用标签(二) | 不读书的读书人

抱歉!评论已关闭.