上次说到去除一些不必需的 class 和 ID, 从上图看出,这些 domain name 似乎也是不必须的,如果像下图: 这样会不会更好呢,下面的代码可以实现这个效果。 add_filter('walker_nav_menu_start_el' , 'yao_walker_nav_menu_start_el' , 10 , 2); function yao_walker_nav_menu_start_el($item_output, $item){ //print_r($item); $home_url = home_url(); $site_url = site_url(); preg_match("/^(http:\/\/)?([^\/]+)/i",site_url(), $matches); $domain = $matches[0]; if( $domain == $home_url){ $replace = ''; }else{ $replace = str_replace($matches[0], '', site_url()); } $item->url = str_replace($home_url,$replace,$item->url); $attributes = ! empty( $item->attr_title ) [...]
wordpress 默认的菜单会产生很多 id 和 class 在代码里,打多时候,这些都是不需要的。 通过下面2个滤镜,可以去除那些我们不需要的 class 和 ID add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2); function special_nav_class($classes, $item){ $current_and_home = array("current-menu-item", "menu-item-home", 'last'); $classes = array_intersect($item->classes,$current_and_home); //保留有需要的 class return $classes; } add_filter('nav_menu_item_id' , 'special_nav_item_id' , 10 , 2); function special_nav_item_id($item_id, $item){ $item_id = ""; //去除 id return $item_id; } 清理之后如: 不过尚有 class=”" [...]
首先到 blog/wp-admin/nav-menus.php 页面。勾选上 链接目标。 然后在下面的自定义菜单区域,点开单个菜单单元 搞定。 Happy? Rel 属性设置以此类推。
实际上这是个插件叫 Disable Updates,但是想就这点代码直接写在主题的功能文件里倒来得更加方便:
The Feed templates are located in the /wp-includes/feed-{type}.php files and include formats for rdf, rss, rss2 and atom. 这儿是一些默认的 rss 模板,定制自己的模板时可以参照。
版本是 3.2.1 在原本的服务器上运行无错,移植到新的服务器就有这个问题,大概就是服务器配置的缘故了。 官方上也相关的文章。http://wordpress.org/support/topic/25-imagemedia-uploader-problems 是apache Mod_Security 的缘故。如果你能够修改你服务器的httpd.conf文件的话,删除里面关于mod_security部分就可以了。不过多数wordpress玩家是没有权限修改这个文件的,那就只好修改.htaccess文件了。在.htaccess文件里面加上一行: <IfModule mod_security.c> SecFilterEngine Off SecFilterScanPOST Off </IfModule> 这样就可以关闭 Mod_Security。
UTF8 中文截取 其中对字符串预先 __() 处理,可以从 qtranslate 中取出当前语言部分然后进行截取。 function utf8Substr($str, $from, $len) { if ($len == 0){ return __($str); }else{ return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', '$1',__($str)); } } //use utf8Substr($recent["post_title"],0,14); function utf8_trim($str) { $len = strlen($str); for ($i=strlen($str)-1; $i>=0; $i-=1){ $hex .= ' '.ord($str[$i]); $ch = ord($str[$i]); if (($ch & 128)==0) return(substr($str,0,$i)); if (($ch & [...]
This piece of code should do it for you. Place this code in your theme’s functions.php file. You can add customizations to the custom_password_form() function – just don’t use print or echo – the function must return a value. <?php add_filter( 'the_password_form', 'custom_password_form' ); function custom_password_form() { global $post; $label = 'pwbox-'.( empty( $post->ID ) [...]
Changes double line-breaks in the text into HTML paragraphs (<p>…</p>). 把文章里的 2次换行 格式化成 html 段落(<p>…</p>). $foo (string) (required) The text to be formatted. 需要格式化的文章。 Default: None $br (boolean or integer) (optional) Preserve line breaks. When set to true, any line breaks remaining after paragraph conversion are converted to HTML . Line breaks within script and [...]
Advanced Custom Fields for wordpress 是一个不错的插件,但是api 里只有 get fields,却没有get labels,对此,作者认为没有必要(作者的论坛上表示的)。一般情况是真的没必要。但是有会更好! 在配合 WPML 做多语言网站的时候就大有用处了,可以设置不同的 Field Label 用相同的 Field Name,这样就可以实现切换语言的时候自动切换 Field Label,而用相同的 get field 获取不同 label 下面的值。 吧下面的代码放进header.php 或这 function.php function get_acf_labels($name = null, $post_id) { global $wpdb; //SELECT name, label FROM wp_acf_fields as waf left jolin wp_acf_values as wav on wav.field_id = waf.id where [...]
Posted on 5, 一











