wordpress 插件目录在哪
function article_index($content) {/*** 名称:文章目录插件* 作者:露兜* 博客:http://www.ludou.org/* 最后修改:2015年3月20日*/$matches = array();$ul_li = '';$r = "/([^<]+)<\/h3>/im";if(is_singular() && preg_match_all($r, $content, $matches)) {foreach($matches[1] as $num => $title) {$title = trim(strip_tags($title));$content = str_replace($matches[0][$num], ''.$title.'', $content);$ul_li .= ''.$title."\n";}$content = "\n文章目录\n" . $ul_li . "\n" . $content;}return $content;}add_filter( 'the_content', 'article_index' );
如何修改 WordPress 的默认 Gravatar 头像
1. 使用插件 Simple local avatar,可以让用户在后台->我的资料页面,设置自己的头像;2. 将默认的Gravatar服务器改为国内可以访问的cn.Gravatar点com:add_filter('get_avatar', 'cwp_change_avatar_source');function cwp_change_avatar_source($avatar){$protocol=is_ssl()?'https':'http';$avatar_source='cn.gravatar.com';$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','',$avatar);return $avatar;}
wordpress标签云怎么设置
实现Wordpress彩色标签云在相应主题的functions.php加入下面的代码,位置刻意在?>;前面:function colorCloud($text) {$text = preg_replace_callback('||i','colorCloudCallback', $text);return $text;}function colorCloudCallback($matches) {$text = $matches[1];$color = dechex(rand(0,16777215));$pattern = '/style=(\'|\”)(.*)(\'|\”)/i';$text = preg_replace($pattern, "style=\"color:#{$color};$2;\"", $text);return "";}add_filter('wp_tag_cloud', 'colorCloud', 1);修改Wordpress彩色标签字体大小,排序,显示数量等。
文件位置在wp-includes下的category-template.php 文件中,搜索wp_tag_cloud,找到相关参数进行修改:function wp_tag_cloud( $args = '' ) {$defaults = array('smallest' => 12, 'largest' => 16, 'unit' => 'pt', 'number' => 50,'format' => 'flat', 'separator' => "\n", 'orderby' => 'count', 'order' => 'DESC','exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true);$args = wp_parse_args( $args, $defaults );$tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) );注:smallest表示标签的最小字号largest表示最大字号unit=px表示字体使用像素单位number=0表示显示所有标签,如果为40,表示显示40个orderby=count表示按照标签所关联的文章数来排列order=DESC表示降序排序(ASC表示升序排序,DESC表示降序排序)Wordpress彩色标签云小工具调用。
保存之后回到首页就可以看到彩色标签云的效果了。
WordPress文章列表前如何添加彩色数字
展开全部 打开wp-content/themes/Gvan-X/下面的:functions.php 文件把以下代码加入里面:(加入的位置可以在多个地方,个人推荐在:CustomComment前面)//标签彩色显示代码开始functioncolorCloud($text){$text=preg_replace_callback('||i','colorCloudCallback',$text);return$text;}functioncolorCloudCallback($matches){$text=$matches[1];$color=dechex(rand(0,16777215));$pattern='/style=(\'|\”)(.*)(\'|\”)/i';$text=preg_replace($pattern,“style=\”color:#{$color};$2;\”",$text);return“”;}add_filter('wp_tag_cloud','colorCloud',1);这样你的标签云就变彩色了。
。
...
wordpress怎样调用文章缩略图
第一步:在主题模板的function.php里添加下面的函数,代码如下://截取内容中第一张图片函数 function catch_that_image() { global $post, $posts; ob_start(); ob_end_clean(); preg_match('/]*?src=['"]([^'"]+?)['"][^]*?>/i', $post->post_content, $matche); if($matche[1]) return $matche[1]; //否则取默认图片 return 'default.gif'; }第二步:在wordpress需要调用缩略图的地方直接用这个函数调用,如下面例子,代码如下:" alt="" title="" width="200px" height="200px" />
知更鸟wordpress主题摘要字数控制文件
WordPress获取指定的摘要指数可以参考一下以下代码:post_excerpt) {$excerpt = $post->post_excerpt;} else {if(preg_match('/(.*)<\/p>/iU',trim(strip_tags($post->post_content,"")),$result)){$post_content = $result['1'];} else {$post_content_r = explode("\n",trim(strip_tags($post->post_content)));$post_content = $post_content_r['0'];}$excerpt = preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s','$1',$post_content);}return str_replace(array("\r\n", "\r", "\n"), "", $excerpt);}}?>;代码来源于泪雪博客:网页链接 版权归原作者所有
wordpress调用缩略图(原始大小)不带链接,只要图片路径
下面是 php 语句哈:echo get_the_post_thumbnail($post->ID, 'full');两个参数,$post->ID _ 是指文章/页面 ID'full' 就是尺寸了,默认是 'thumbnail'。
还可以有一些其他的参数,以及参数具体可能只,可以参考文档哈:http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
如何使wordpress的标签自动变为网站文章的内链
方法一、使用插件 SEO Smart Links插件:介绍:SEO Smart Links可以通过一次性的设定文章、页面或留言出现的关键词,通过关键词的加入,使得我们把某些关键词链向知道的POST URL上,从而提供这个POST的权重,它匹配的项目包括文章链接、页面链接、分类链接和标签链接。
可设置是否添加“nofollow”属性, 是否在新窗口中打开链接.可手动指定关键词和对应的URL链接.可设置每个页面最多自动添加几个链接可设置要忽略的关键词不过自动为关键词添加链接对中文支持并不友好. Keyword Link Plugin插件:为你的wordpress博客添加关键词的链接,并且你可以自由设置“不追踪链接”、“第一次有效”、“新窗口链接”、“忽略大小写”这些功能,使用起来很灵活,比如可以为你的Tag增加自动关键词链 接,这样在正文出现时同样有效。
给文章加上内部链接有利于增加搜索引擎收录。
面向所有的wordpress中文用户。
完美支持中英文关键词。
Alinks 插件:通过预先设置关键词和对应的链接即可. 之后文章中出现设置过链接的关键词, 则会自动添加上. 可以设置每页最多添加多少个关键词, 链接是否在新窗口中打开, 自定义链接图标, 链接点击统计功能。
Link A Dink插件:半自动的链接插件. 和Alinks插件的使用差不多, 通过手动设置关键词和对应的链接, 然后你以后写文章时会自动为该关键词添加链接. 方法二、代码 function.php中添加如下代码:$match_num_from = 1; //一篇文章中同一个关键字少于多少不锚文本(这个直接填1就好了)$match_num_to = 2; //一篇文章中同一个关键字最多出现多少次锚文本(建议不超过2次)//连接到WordPress的模块add_filter('the_content','tag_link',1);//按长度排序function tag_sort($a, $b){ if ( $a->name == $b->name ) return 0; return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;}//改变标签关键字function tag_link($content){global $match_num_from,$match_num_to; $posttags = get_the_tags(); if ($posttags) { usort($posttags, "tag_sort"); foreach($posttags as $tag) { $link = get_tag_link($tag->term_id); $keyword = $tag->name; //连接代码 $cleankeyword = stripslashes($keyword); $url = "".addcslashes($cleankeyword, '$').""; $limit = rand($match_num_from,$match_num_to); //不连接的代码 $content = preg_replace( '|(]+>)(.*)('.$ex_word.')(.*)(]*>)|U'.$case, '$1$2%&&&&& %$4$5', $content); $content = preg_replace( '|()|U'.$case, '$1$2%&&&&& %$4$5', $content); $cleankeyword = preg_quote($cleankeyword,'\''); $regEx = '\'(?!((]*?)>)|([^>]*?))\'s' . $case; $content = preg_replace($regEx,$url,$content,$limit); $content = str_replace( '%&&&&& %', stripslashes($ex_word), $content); } } return $content;
wordpress怎么改变主题标签云样式
展开全部 有以下3种方法来实现“免插件仅代码实现WordPress评论回复邮件提醒”,都是把代码加到主题里的functions.php中的最后一个 ?> 即可。
第一种:所有回复都发邮件通知使用前,请确定你的主机是否支持 mail() 函数。
/* comment_mail_notify v1.0 by willin kan. (所有回复都发邮件) */function comment_mail_notify($comment_id) { $comment = get_comment($comment_id); $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; $spam_confirmed = $comment->comment_approved; if (($parent_id != '') && ($spam_confirmed != 'spam')) { $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); //e-mail 发出点, no-reply 可改为可用的 e-mail. $to = trim(get_comment($parent_id)->comment_author_email); $subject = '您在 [' . get_option("blogname") . '] 的留言有了回复'; $message = ' ' . trim(get_comment($parent_id)->comment_author) . ', 您好! 您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:' . trim(get_comment($parent_id)->comment_content) . ' ' . trim($comment->comment_author) . ' 给您的回复:' . trim($comment->comment_content) . ' 您可以点击 查看回复完整内容 欢迎再度光临 ' . get_option('blogname') . ' (此邮件由系统自动发送,请勿回复.) '; $from = "From: "" . get_option('blogname') . "" "; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers ); //echo 'mail to ', $to, ' ' , $subject, $message; // for testing }}add_action('comment_post', 'comment_mail_notify');// -- END - 第二种:让访客自己选择是否邮件通知在评论框下方显示一个勾选框,让评论人自己决定是否接收邮件通知。
不过要注意的是,具体的#comment_mail_notify 需要你自己定义css以符合你的主题样式。
function comment_mail_notify($comment_id) { $admin_notify = '1'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 ) $admin_email = get_bloginfo ('admin_email'); // $admin_email 可改为你指定的 e-mail. $comment = get_comment($comment_id); $comment_author_email = trim($comment->comment_author_email); $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; global $wpdb; if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '') $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;"); if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1')) $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'"); $notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0'; $spam_confirmed = $comment->comment_approved; if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') { $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail. $to = trim(get_comment($parent_id)->comment_author_email); $subject = '您在 [' . get_option("blogname") . '] 的留言有了回复'; $message = ' ' . trim(get_comment($parent_id)->comment_author) . ', 您好! 您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:' . trim(get_comment($parent_id)->comment_content) . ' ' . trim($comment->comment_author) . ' 给您的回复:' . trim($comment->comment_content) . ' 您可以点击查看回复的完整内容 还要再度光临 ' . get_option('blogname') . ' (此邮件由系统自动发送,请勿回复.) '; $from = "From: "" . get_option('blogname') . "" "; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers ); //echo 'mail to ', $to, ' ' , $subject, $message; // for testing }}add_action('comment_post', 'comment_mail_...
转载请注明出处51数据库 » wordpress preg_repla