7.wordpress调用含gravatar头像的评论输出
<?php</p> <p>global $wpdb;</p> <p>$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";</p> <p>$comments = $wpdb->get_results($sql);</p> <p>$output = $pre_HTML;</p> <p>foreach ($comments as $comment) {</p> <p>$output .= "\n<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>";</p> <p>}</p> <p>$output .= $post_HTML;</p> <p>$output = convert_smilies($output);</p> <p>echo $output;</p> <p>?>
上面代码把comment_author的值改成你的ID,18是头像大小,10是评论数量。
8.wordpress调用网站统计大全
1、日志总数:</p> <p><?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>
2、草稿数目:</p> <p><?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>
3、评论总数:</p> <p><?php echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?>
4、成立时间:</p> <p><?php echo floor((time()-strtotime("2008-8-18"))/86400); ?>
5、标签总数:</p> <p><?php echo $count_tags = wp_count_terms('post_tag'); ?>
6、页面总数:</p> <p><?php $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish; ?>
7、分类总数:</p> <p><?php echo $count_categories = wp_count_terms('category'); ?>
8、链接总数:</p> <p><?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?>
9、用户总数:</p> <p><?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?>
10、最后更新:</p> <p><?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; ?>
9.wordpress判断语句
is_single()
判断是否是具体文章的页面
is_single(’2′)
判断是否是具体文章(id=2)的页面
is_single(’Beef Stew’)
判断是否是具体文章(标题判断)的页面
is_single(’beef-stew’)
判断是否是具体文章(slug判断)的页面
comments_open()
是否留言开启
pings_open()
是否开启ping
is_page()
是否是页面
is_page(’42′)
id判断,即是否是id为42的页面
is_page(’About Me’)
判断标题
is_page(’about-me’)
slug判断
is_category()
是否是分类
is_category(’6′)
id判断,即是否是id为6的分类
is_category(’Cheeses’)
分类title判断
is_category(’cheeses’)
分类 slug判断
in_category(’5′)
判断当前的文章是否属于分类5
is_author()
将所有的作者的页面显示出来
is_author(’1337′)
显示author number为1337的页面
is_author(’Elite Hacker’)
通过昵称来显示当前作者的页面
is_author(’elite-hacker’)
下面是通过不同的判断实现以年、月、日、时间等方式来显示归档
is_date()
is_year()
is_month()
is_day()
is_time()
判断当前是否是归档页面
is_archive()
判断是否是搜索
is_search()
判断页面是否404
is_404()
判断是否翻页,比如你当前的blog是http://domain.com 显示http://domain.com?paged=2的时候,这个判断将返 回真,通过这个函数可以配合is_home来控制某些只能在首页显示的界面,
例如:
<?php if(is_single()):?></p> <p>//这里写你想显示的内容,包括函数</p> <p><?php endif;?>
或者:
<?php if(is_home() && !is_paged() ):?></p> <p>//这里写你想显示的内容,包括函数</p> <p><?php endif;?>
10.wordpress非插件同步twitter
<?php</p> <p>require_once (ABSPATH . WPINC . ‘/class-feed.php’);</p> <p>$feed = new SimplePie();</p> <p>$feed->set_feed_url(‘http://feeds.feedburner.com/agting′);</p> <p>$feed->set_file_class(‘WP_SimplePie_File’);</p> <p>$feed->set_cache_duration(600);</p> <p>$feed->init();</p> <p>$feed->handle_content_type();</p> <p>$items = $feed->get_items(0,1);</p> <p>foreach($items as $item) {</p> <p>echo ‘<a target=”_blank” rel=”external nofollow” title=”Follow Me on Twitter” href=”http://twitter.com/agting″>@郑永</a>: ‘.$item->get_description();</p> <p>}</p> <p>?>
代码中的agting改成你的twitter用户名,郑永改成你的名字。 另一种调用方法需要你的空间是国外主机:
<?php</p> <p>// Your twitter username.</p> <p>$username = "wange1228";</p> <p>// Prefix - some text you want displayed before your latest tweet.</p> <p>// (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")</p> <p>// Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)</p> <p>$suffix = "";</p> <p>$feed = "<a rel="external nofollow" >http://search.twitter.com/search.atom?q=from</a>:" . $username . "&rpp=1";</p> <p>function parse_feed($feed) {</p> <p>$stepOne = explode("<content type=\"html\">", $feed);</p> <p>$stepTwo = explode("</content>", $stepOne[1]);</p> <p>$tweet = $stepTwo[0];</p> <p>$tweet = str_replace("<", "<", $tweet);</p> <p>$tweet = str_replace(">", ">", $tweet);</p> <p>return $tweet;</p> <p>}</p> <p>$twitterFeed = file_get_contents($feed);</p> <p>echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);</p> <p>?>
ZeroZ 总结了一下这个方法的特点:
1、非插件!
2、不用验证用户名和密码,也就是说你可以指定调用任何一个人的 tweet!
3、可以自定义 tweet 信息后显示的文字,就是 $suffix = “”; 这里!
4、只能调用最新的一条 tweet,刚好满足我的需求。
5、大概只有国外空间才能使用!(经我验证,确实如此)
11.wordpress 非插件调用评论表情
<!--smilies-->
<?php</p> <p>function wp_smilies() {</p> <p>global $wpsmiliestrans;</p> <p>if ( !get_option('use_smilies') or (empty($wpsmiliestrans))) return;</p> <p>$smilies = array_unique($wpsmiliestrans);</p> <p>$link='';</p> <p>foreach ($smilies as $key => $smile) {</p> <p>$file = get_bloginfo('wpurl').'/wp-includes/images/smilies/'.$smile;</p> <p>$value = " ".$key." ";</p> <p>$img = "<img src=\"{$file}\" alt=\"{$smile}\" />";</p> <p>$imglink = htmlspecialchars($img);</p> <p>$link .= "<a href=\"#commentform\" title=\"{$smile}\" onclick=\"document.getElementByIdx_x('comment').value += '{$value}'\">{$img}</a> ";</p> <p>}</p> <p>echo '<div>'.$link.'</div>';</p> <p>}</p> <p>?></p> <p><?php wp_smilies();?></p> <p><!--smilies—>
将以上代码复制到 comments.php 中合适的位置。
标签:WordPress
相关阅读 >>
禁用wordpress gravatar使用本地头像提高网页打开速度
wordpress中给媒体文件添加分类和标签的php功能实现
wordpress高级自定义布局的内容编辑器(tinymce)模板
使用wordpress的$wpdb类读mysql数据库做ajax时出现的问题该如何解决
更多相关阅读请进入《wordpress》频道 >>
相关推荐
评论
管理员已关闭评论功能...
- 欢迎访问木庄网络博客
- 可复制:代码框内的文字。
- 方法:Ctrl+C。