wordpress中of
get_option()是WordPress核心的设置选项获取函数;of_get_option()是第三方插件Option Tree获取其设置项的函数。
所以,两者有本质区别:你可以在WordPress中直接使用get_option(),当然了,获取的设置项要被设置了才行,但是of_get_option()只有在Option Tree插件或其库存在时才能用,否则会报出一个函数不存在的致命错误提示。
类似Option Tree这样的WordPress后台设置面板插件有好几个,这个就很不错的!不了解再问,祝愉快!
wordpress中怎样在新建的页面中添加分类目录和文章(要和首页或其...
wordpress不同页面显示不同文章的方法:1. 在模板头部要加上下面的说明,不然后台选择模板找不到它:2. 直接在下面加入query_post函数,直接指定文章数和分类,其他的就不需要了。
3. 如果有多个页面模板,依此类推了。
自定义模板在wordpress后台页面编辑区的右边“属性”——“模板”,就可以看到自定义page模板了。
新增一个登录/注销链接到的导航菜单的方法:输入:add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);function add_login_logout_link($items, $args) {ob_start();wp_loginout('index.php');$loginoutlink = ob_get_contents();ob_end_clean();$items .= '4. '. $loginoutlink .'<>';return $items;}
//友情链接列表 在添加后 页面显示 ...
方法一、使用插件 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面包屑导航效果
1、层级较深的网站,面包屑导航适合层级较深的网站,如果只有一级分类的话,通过主导航就可以起到快速定位的作用。
比如“豆瓣网”类型扁平构架的网站就没有使用面包屑导航的作用。
2、独立不交叉的网站机构,由于面包屑网站导航路径是线性结构的,因此网站内容必须划分的非常清晰,且不存在交叉;否则,面包屑导航的路径就不是唯一的,同一分类可能出现在不同的路径中,让用户感到困惑。
在wordpress中添加面包屑导航的话,可以直接使用插件来实现,不过很多站长都不喜欢用插件,还是认为如果能用代码解决的话是最理想的。
我最近也找了一些关于面包屑导航的资料。
下文中就有详细解决怎么用代码来实现wordpress面包屑导航:一、在wordpress博客当前主题的functions.php文件(没有就创建一个)中添加以下代码://面包屑导航function get_breadcrumbs(){ global $wp_query; if ( !is_home() ){ // Start the UL echo ''; // Add the Home link echo ''. get_bloginfo('name') .''; if ( is_category() ) { $catTitle = single_cat_title( "", false ); $cat = get_cat_ID( $catTitle ); echo " ? ". get_category_parents( $cat, TRUE, " ? " ) .""; } elseif ( is_archive() && !is_category() ) { echo " ? Archives"; } elseif ( is_search() ) { echo " ? Search Results"; } elseif ( is_404() ) { echo " ? 404 Not Found"; } elseif ( is_single() ) { $category = get_the_category(); $category_id = get_cat_ID( $category[0]->cat_name ); echo ' ? '. get_category_parents( $category_id, TRUE, " ? " ); echo the_title('','', FALSE) .""; } elseif ( is_page() ) { $post = $wp_query->get_queried_object(); if ( $post->post_parent == 0 ){ echo " ? ".the_title('','', FALSE).""; } else { $title = the_title('','', FALSE); $ancestors = array_reverse( get_post_ancestors( $post->ID ) ); array_push($ancestors, $post->ID); foreach ( $ancestors as $ancestor ){ if( $ancestor != end($ancestors) ){ echo ' ? '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .''; } else { echo ' ? '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .''; } } } } // End the UL echo ""; }}二、在显示面包屑导航的位置添加以下调用代码:三、在主题的css样式文件中添加以下样式代码:ul.breadcrumbs {list-style: none; font-size:12px;}ul.breadcrumbs li {float: left; margin-right:5px;}
怎样修改WordPress自带的功能等小工具
你好,你是想去掉其中不想要的链接吧?看下面:function coolwp_remove_meta_widget() {/*移除Wordpress自带的Meta小工具*/unregister_widget('WP_Widget_Meta');/*注册自己的Meta小工具*/register_widget('WP_Widget_Meta_Mod');}add_action( 'widgets_init', 'coolwp_remove_meta_widget' );/*自定义小工具扩展类*/class WP_Widget_Meta_Mod extends WP_Widget {function __construct() {$widget_ops = array('classname' =>'widget_meta', 'description' =>__( "Log in/out, admin, feed and WordPress links") );parent::__construct('meta', __('Meta'), $widget_ops);}function widget( $args, $instance ) {extract($args);$title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base);echo $before_widget;if ( $title )echo $before_title . $title . $after_title;?>echo $after_widget;}function update( $new_instance, $old_instance ) {$instance = $old_instance;$instance['title'] = strip_tags($new_instance['title']);return $instance;}function form( $instance ) {$instance = wp_parse_args( (array) $instance, array( 'title' =>'' ) );$title = strip_tags($instance['title']);?>get_field_id('title'); ?>">get_field_id('title'); ?>" name="get_field_name('title'); ?>" type="text" value="" />}}将上述代码添加到你当前的主题或已启用的插件中即可,示意截图:祝愉快!
wordpress的get
wordpress可以设置自定义字段,方便扩展功能,wordpress利用巧妙的数据库表设计达到这一目的,posts表存放文章,页面和附件等,与之对应的postmeta表用来存储自定义的字段,采用post_id,key,value这样的设计来存放自定义字段的值。
get_post_meta函数用法:get_post_meta($post_id, $key, $single);该函数有3个基本参数:$post_id —— 所检索数据的文章的ID,使用 $post->ID 来获取文章的ID。
$key —— 要检索的自定义字段名称$single —— 这是一个布尔值,如果设置为 true ,将直接以字符串的形式返回字段的值;一个自定义字段可以填写多个值,如果设置为 false,将返回一个数组 array 来显示这多个值。
此函数定义在wordpress的post.php中:
wordpress的get
如果是新手, 建议用其他Wordpress 的插件。
例如Yoast SEO 或者 WP SEO 他们都有加面包屑的功能, 如果不想加插件, 可以把以下加进function.php // Breadcrumbsfunction custom_breadcrumbs() { // Settings $separator = '>'; $breadcrums_id = 'breadcrumbs'; $breadcrums_class = 'breadcrumbs'; $home_title = 'Homepage'; // If you have any custom post types with custom taxonomies, put the taxonomy name below (e.g. product_cat) $custom_taxonomy = 'product_cat'; // Get the query & post information global $post,$wp_query; // Do not display on the homepage if ( !is_front_page() ) { // Build the breadcrums echo ''; // Home page echo '' . $home_title . ''; echo ' ' . $separator . ' '; if ( is_archive() && !is_tax() && !is_category() && !is_tag() ) { echo '' . post_type_archive_title($prefix, false) . ''; } else if ( is_archive() && is_tax() && !is_category() && !is_tag() ) { // If post is a custom post type $post_type = get_post_type(); // If it is a custom post type display name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo '' . $post_type_object->labels->name . ''; echo ' ' . $separator . ' '; } $custom_tax_name = get_queried_object()->name; echo '' . $custom_tax_name . ''; } else if ( is_single() ) { // If post is a custom post type $post_type = get_post_type(); // If it is a custom post type display name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo '' . $post_type_object->labels->name . ''; echo ' ' . $separator . ' '; } // Get post category info $category = get_the_category(); if(!empty($category)) { // Get last category post is in $last_category = end(array_values($category)); // Get parent any categories and create array $get_cat_parents = rtrim(get_category_parents($last_category->term_id, true, ','),','); $cat_parents = explode(',',$get_cat_parents); // Loop through parent categories and store in variable $cat_display $cat_display = ''; foreach($cat_parents as $parents) { $cat_display .= ''.$parents.''; $cat_display .= ' ' . $separator . ' '; } } // If it's a custom post type within a custom taxonomy $taxonomy_exists = taxonomy_exists($custom_taxonomy); if(empty($last_category) && !empty($custom_taxonomy) && $taxonomy_exists) { $taxonomy_terms = get_the_terms( $post->ID, $custom_taxonomy ); $cat_id = $taxonomy_terms[0]->term_id; $cat_nicename = $taxonomy_terms[0]->slug; $cat_link = get_term_link($taxonomy_terms[0]->term_id, $custom_taxonomy); $cat_name = $taxonomy_terms[0]->name; } // Check if the post is in a category if(!empty($last_category)) { echo $cat_display; echo '' . get_the_title() . ''; // Else if post is in a custom taxonomy } else if(!empty($cat_id)) { echo '' . $cat_name . ''; echo ' ' . $separator . ' '; echo '' . get_the_title() . ''; } else { echo '' . get_the_title() . ''; } } else if ( is_category() ) { // Category page echo '' . single_cat_title('', false) . ''; } else if ( is_page() ) { // Standard page if( $post->post_parent ){ // If child page, get parents $anc = get_post_ancestors( $post->ID ); // Get parents in the right order $anc = array_reverse($anc); // Parent page loop if ( !isset( $parents ) ) $parents = null; foreach ( $anc as $ancestor ) { $parents .= '' . get_the_title($ancestor) . ''; $parents .= ' ' . $separator . ' '; } // Display parent pages echo $parents; // Current page echo ' ' . get_the_title() . ''; } else { // Just display current page if not parents echo ' ' . get_the_title() . ''; } } echo ''; }}
如何在WordPress首页调用某页面的文章内容
在wordpress中,不仅在首页,在其他任何地方调用页面,均可以通过get_page或get_pages这两个内置函数来实现调用一篇或多篇页面内容1、利用get_page获取1个指定的页面内容if ( is_home() ) : //这个判断非必需,这里表示将输出限定在首页$page = get_page( 5 ); // 5为调用页面的IDif( $page ) {//var_dump($page); printf("%s", apply_filters('the_content', $page->post_content) ); //输出页面内容}endif;2、利用get_pages获取页面列表 // 详细的参数可参考/wp-includes/ -> post.php中get_pages函数中的说明// 以下仅仅列出几个作为示例$args = array('sort_column' => 'ID', //指定依id排序'sort_order' => 'ASC', // 指定排序方式为升序'number' => 6 // 指定只获取6篇页面内容);$pages = get_pages($args);//var_dump($wpdb);if(count($pages)) {foreach ($pages as $key => $page) {printf("%s", apply_filters('the_content', $page->post_content) ); //输出页面内容}}总结:页面其实是wordpress文章格式的一种,内置有很多较为直观的函数,主要位置/wp-includes/ -> post.php文件中,建议多看看就好。
转载请注明出处51数据库 » wordpress中的get_links
嗫?暁雲?