wordpress小技巧:如何在首页显示最新评论
 .hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=ade97d69b9b7d0a27b9c0c9bfbdf5a31/63d0f703918fa0ec082775d62d9759ee3c6ddb0c. href="');'a href="%1$s , ', .php然后,找到\wp-includes\default-widgets;/li>', );span>. '/a>. ' <.baidu. ' ;> 将其修改为: //sprintf(_x('%1$s on %2$s') ;) ;/a>get_comment_author_link(). comment_ID) comment_post_ID) ';' ;<://a; strip_tags( $comment->' . get_comment_author_link().hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=3170ef047d094b36dbc713e996fc50ef/63d0f703918fa0ec082775d62d9759ee3c6ddb0c;on . . 'get_the_title($comment->comment_post_ID) ,来吧实战开始:首先,备份\wp-includes\default-widgets;widgets'. ''''.php文件中,大约在679行sprintf(_x(', . . get_the_title($comment->'">'.jpg" esrc="http。
前台显示效果如图;comment_post_ID) . get_the_title($comment->comment_ID) ) 这样就OK了;. 'href="', ''"<. , ;sprintf(_x('%1$s 在“%2$s”留言:'.com/zhidao/pic/item/63d0f703918fa0ec082775d62d9759ee3c6ddb0c.jpg" target="_blank" title="点击查看大图" class="ikqb_img_alink">//get_comment_link($comment->comment_ID) 
WordPress 首页 显示 一篇 特定 文章
方法一:修改WordPress文件。
优点:操作简单。
缺点:博客升级后会失效,需重新修改。
找到WorsPress目录wp-includes下formating.php文件,查找unction wp_trim_excerpt($text)函数,再找到excerpt_length,默认值是55,修改成需要的值即可。
方法二:自定义函数,修改主题function.php文件。
(楼主推荐)优点:一劳永逸。
缺点:换主题后需要重新设置。
The_excerpt()在Wordpress中,默认是截取55个英文单词的,但是在中文中却是无法截取到55个汉字。
原因是因为在wordpress的the_excerpt()函数中用到了1$text = implode(' ', $words);在php中是用空格来截取字数的,而我们汉字就杯具了,因为我们汉字是相连的,没有空格来区分,所以在使用中文的时候,经常地我们使用the_excerpt()函数的时候,截取出来的结果是全文!对于这个情况我们可以用PHP函数mb_substr去解决。
所以在Wordpress中可以打开主题中的funtions.php,加入下面的代码:12345function chinese_excerpt($text, $lenth=100) {$text = mb_substr($text,0, $lenth);return $text;}add_filter('the_excerpt', ' chinese_excerpt ');我这里设置默认的截取长度是100个字符,50个汉字。
可以在上面的代码中的$lenth=100设定为任意的截取长度。
或者直接使用中文截取法,加入如下代码12345function custom_excerpt_length( $length ) {return 200;}add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );200为字数,可以修改为自己的值。
需要安装服务器打开php mb_string扩展。
1、安装php-mbstrin扩展,终端执行。
sudo yum install php-mbstring。
2、切换root用户。
sudo -s3、修改php.ini,终端执行。
echo 'extension=mbstring.so' >>/etc/php.ini 4、重启web服务器。
apache:sudo service httpd restartnginx:sudo service nginx reload
转载请注明出处51数据库 » wordpress 首页显示