怎样制作wordpress的面包屑导航
如果是新手, 建议用其他Wordpress 的插件。
例如Yoast SEO 或者 WP SEO 他们都有加面包屑的功能, 如果不想加插件, 可以把以下加进function.php // Breadcrumbs function 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 'labels->name . '">' . $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 'labels->name . '">' . $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 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; // Else if post is in a custom taxonomy } else if(!empty($cat_id)) { echo '' . $cat_name . ''; echo ' ' . $separator . ' '; echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; } else { echo 'ID . '">ID . '" title="' . get_the_title() . '">' . 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 'ID . '"> ' . get_the_title() . ''; } else { // Just display current page if not parents echo 'ID . '">ID . '"> ' . get_the_title() . ''; } } echo ''; } }
怎么删除wordpress程序中文章浏览数
可以用两种方式,一是插件,二是用代码插件这个WP-Postviews关于这个插件的详细使用,下次详细说明:seotaoke这个模板的,那就是下面的方法:第一步,在网站的后台里找到外观编辑,这个文件functions.php,在这个文件的 ?>前面添加如下一些代码:/* 访问计数 */function record_visitors(){if (is_singular()){global $post;$post_ID = $post->ID;if($post_ID){$post_views = (int)get_post_meta($post_ID, 'views', true);if(!update_post_meta($post_ID, 'views', ($post_views+1))){add_post_meta($post_ID, 'views', 1, true);}}}}add_action('wp_head', 'record_visitors');/// 函数名称:post_views/// 函数作用:取得文章的阅读次数function post_views($before = '(点击 ', $after = ' 次)', $echo = 1){global $post;$post_ID = $post->ID;$views = (int)get_post_meta($post_ID, 'views', true);if ($echo) echo $before, number_format($views), $after;else return $views;}第二步,在你的文章里,有显示浏览次数的地方添加这样的代码:这时到首页文章里查看即可见到效果!
如何用纯代码方法实现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 ""; } } 二、在显示面包屑导航的位置添加以下调用代码:if (function_exists('get_breadcrumbs')){ get_breadcrumbs(); } ?> 三、在主题的css样式文件中添加以下样式代码:ul.breadcrumbs {list-style: none; font-size:12px;} ul.breadcrumbs li {float: left; margin-right:5px;}
wordpress如何提取出整个网页
展开全部 获取存档页面链接function get_current_archive_link( $paged = true ) {$link = false;if ( is_front_page() ) {$link = home_url( '/' );} else if ( is_home() && "page" == get_option('show_on_front') ) {$link = get_permalink( get_option( 'page_for_posts' ) );} else if ( is_tax() || is_tag() || is_category() ) {$term = get_queried_object();$link = get_term_link( $term, $term->taxonomy );} else if ( is_post_type_archive() ) {$link = get_post_type_archive_link( get_post_type() );} else if ( is_author() ) {$link = get_author_posts_url( get_query_var('author'), get_query_var('author_name') );...
如何获取 WordPress 各类页面的链接
在WordPress项目开发过程,很可能需要获取WordPress 各类页面的链接,包括首页、文章页、Page页面、存档页面等等,今天倡萌就简单分享下获取 WordPress 各类页面的链接的方法。
获取文章或页面链接 直接输出文章或页面的链接: 返回文章或页面的链接,以供调用: get_permalink(); 可以使用 echo 输出,结果和直接使用 the_permalink() 一样: 获取存档页面链接 function get_current_archive_link( $paged = true ) { $link = false; if ( is_front_page() ) { $link = home_url( '/' ); } else if ( is_home() && "page" == get_option('show_on_front') ) { $link = get_permalink( get_option( 'page_for_posts' ) ); } else if ( is_tax() || is_tag() || is_category() ) { $term = get_queried_object(); $link = get_term_link( $term, $term->taxonomy ); } else if ( is_post_type_archive() ) { $link = get_post_type_archive_link( get_post_type() ); } else if ( is_author() ) { $link = get_author_posts_url( get_query_var('author'), get_query_var('author_name') ); } else if ( is_archive() ) { if ( is_date() ) { if ( is_day() ) { $link = get_day_link( get_query_var('year'), get_query_var('monthnum'), get_query_var('day') ); } else if ( is_month() ) { $link = get_month_link( get_query_var('year'), get_query_var('monthnum') ); } else if ( is_year() ) { $link = get_year_link( get_query_var('year') ); } } } if ( $paged && $link && get_query_var('paged') > 1 ) { global $wp_rewrite; if ( !$wp_rewrite->using_permalinks() ) { $link = add_query_arg( 'paged', get_query_var('paged'), $link ); } else { $link = user_trailingslashit( trailingslashit( $link ) . trailingslashit( $wp_rewrite->pagination_base ) . get_query_var('paged'), 'archive' ); } } return $link; } 该函数可以输出首页、分类法(自定义分类法、标签、分类)、自定义文章类型的存档页面、作者存档页面、日期存档页面 的链接,包含分页。
获取当前页面链接 如果你不想判断页面类型,只想输出当前页面的链接,可以使用下面的代码: request)); echo $current_url; ?>
求教wordpress如何调用最新文章?
$limit = get_option('posts_per_page');$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;query_posts('showposts=' . $limit=7 . '&paged=' . $paged);//limit变量控制最新文章数量$wp_query->is_archive = true; $wp_query->is_home = false;?>ID)) : ?>
wordpress文章标题输出
试试这个" />$description =""; $keywords =""; } elseif (is_single()){ if ($post->post_excerpt) { $description = $post->post_excerpt; } else { $description = substr(strip_tags($post->post_content),0,220); } $keywords = ""; $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $keywords . $tag->name . ", "; }}?>" />" />
wordpress首页如何调用最新文章
第一种方法WordPress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现. 代码如下:(显示10篇最新更新文章)或后面这个代码显示你博客中最新的20篇文章,其中format=custom这里主要用来自定义这份文章列表的显示样式。
具体的参数和使用方法你可以参考官方的使用说明- wp_get_archvies。
(fromat=custom也可以不要,默认以UL列表显示文章标题。
)补充: 通过WP的query_posts()函数也能调用最新文章列表, 虽然代码会比较多一点,但可以更好的控制Loop的显示,比如你可以设置是否显示摘要。
具体的使用方法也可以查看官方的说明。
第二种方法调用最新文章:(直接在想要呈现的位置放上以下代码即可)$limit = get_option('posts_per_page');$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;query_posts('showposts=' . $limit=7 . '&paged=' . $paged);$wp_query->is_archive = true; $wp_query->is_home = false;?>ID)) : ?>
如何给WordPress页面添加关键词和描述
第一步:修改WordPress中首页、文章页、分类页、标签页以及page页面的关键词首先打开外观->编辑->header.php第二步:注意你的文本编辑框下面一定要有保存更新的按钮,如果没有的话说明你的header.php地权限不够,更改权限的方法为进入主机控制面板中的文件管理,找到网站所在的文件夹即根目录下的wp-content/themes/theme_name/header.php修改其权限为777即可。
第三步:把下面的内容复制到header.php的head标签之间,代码已经注释很明白了。
如果想看高亮代码这里是飞机票给WordPress页面添加关键词和描述。
转载请注明出处51数据库 » wordpress is post
奥巴驴g