怎样制作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 后台导航菜单自定义class,为什么前台无显示
wordpress 导航菜单的调用,一般都使用自带的wp_nav_menu()函数,使用后发现,这个函数并没提供给我们给每一项导航菜单添加自定义class的接口功能!搜索了下,最终在老外的一篇文章中发现了wordpress自身提供的解决方法!嗯,wordpress还是很强大的...方法很简单:依次进入wordpress后台->外观->菜单,然后在页面右侧的右上角点“显示选项”,我们看到“显示菜单高级属性”中有个“css类”选项,把它选中,再看菜单项中,已多出一个css类输入框,该框输入的内容即为导航菜单项自定义的class值!!再次见识到了wordpress的强大,擅抖吧,骚年!!哈...
wordpress 主题开发 文本框添加内容转化为数组的实现方法?
展开全部 如下,有问题追问或本人网站留言。
有时候我们的博客需要分享一些羞羞的内容,按惯例及服务器所在国家法律要求,是必须要在浏览前显示“成人内容警告”的,以提示方可内容可能不适宜未成年人或引起不适。
对于wordpress来说就很简单,简单的一段代码就能实现。
要实现这样的功能,我们需要wordpress在wp_loaded的时候判断指定cookie是否存在,以确定是否是该浏览者是否已经浏览警告页面。
如果该cookie不存在则显示警告页面,并且在浏览者点击确认后写入cookie。
代码如下: if(class_exists('AdultContentsWarning')) return;class AdultContentsWarning{var $path;function __construct(){add_action('wp_loaded',array($this,'isAdult'));$path= parse_url(untrailingslashit(home_url()))['path'] === NULL ? parse_url($_SERVER['REQUEST_URI'] )['path'] :explode(parse_url(untrailingslashit(home_url()))['path'],parse_url($_SERVER['REQUEST_URI'] )['path'])[0];}function isAdult(){if(is_user_logged_in() === true) return;if(!isset($_COOKIE['isAdult']) || $_COOKIE['isAdult'] != 'yes'){if($_POST['isAdult'] == 'yes'){if(setcookie('isAdult','yes',time()+3600*24) === true){echo 'success';die;}}else{$this->show_warning();die();}}return;}private function show_warning(){?>成人内容警告 - ">a{text-decoration:none;color:#0000FF}a:hover{text-decoration:underline;}警告 / WARNING 本物品内容可能令人反感;不可将本物品内容派发,传阅,出售,出租,交给或出借予年龄未满 18 岁的人士出示,播放或播映。
This article contains material which may offernd and may not bedistributed, circulated, sold, hired, given, lent, shown, played or projected to a person under the age of 18 years. All models are 18 orolder. __ 满 18 岁,请按此 __退出浏览jQuery(document).ready(function($) {$("#confirm").click(function(){$.post("",{isAdult:'yes'},function(result){if(result == 'success'){if (getCookie('isAdult') != false){location.reload(true);}else{alert('Cookie写入失败!');location.reload(false);}}});});$("#close").click(function(){if(window.history.go(-1) == undefined){window.location.href="about:blank";}else{window.history.go(-1);}});});function getCookie(c_name){if (document.cookie.length>0){c_start=document.cookie.indexOf(c_name + "=")if (c_start!=-1){c_start=c_start + c_name.length+1c_end=document.cookie.indexOf(";",c_start)if (c_end==-1) c_end=document.cookie.lengthreturn unescape(document.cookie.substring(c_start,c_end))}}return false}<?php}}new AdultContentsWarning();
wordpress怎么去除后台侧面插件
展开全部 在functions.php文件中添加以下代码:function remove_menus() {global $menu;$restricted = array(__('Plugins'));end ($menu);while (prev($menu)){$value = explode(' ',$menu[key($menu)][0]);if(strpos($value[0], '<') === FALSE) {if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){unset($menu[key($menu)]);}}else {$value2 = explode('<', $value[0]);if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){unset($menu[key($menu)]);}}}}if ( is_admin() ) {add_action('admin_menu', 'remove_menus');}...
知更鸟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);}}?>;代码来源于泪雪博客:网页链接 版权归原作者所有
php随机显示语句
那么这个随机名人名言的功能是如何实现的呢? 其实很简单,只需要一个字符串变量,这里面放所有要随机展现的名人名言,然后用到explode函数分解成数组,再用rand随机数生成一个值,输出这个数组中的某一句。
直接上代码: says.php 复制代码 代码如下: function random_str () { $poems="人生的价值,并不是用时间,而是用深度去衡量的。
-- 列夫·托尔斯泰 三人行,必有我师焉。
择其善者而从之,其不善者而改之。
——孔子 人生不是一种享乐,而是一桩十分沉重的工作。
-- 列夫·托尔斯泰 成为卓越的代名词,很多人并不需要杰出素质的环境。
——Steve Jobs 活着就是为了改变世界,难道还有其他原因吗?——Steve Jobs Follow yourself.追随你的内心。
——Steve Jobs 生活是不公平的;要去适应它。
——比尔盖茨 常常提醒自己注意幸福,就像在寒冷的日子里经常看看太阳,心就不知不觉暖洋洋,亮光光。
——毕淑敏 幸福是一种心灵的振颤。
它像会倾听音乐的耳朵一样,需要不断地训练。
——毕淑敏 这世界并不会在意你的自尊。
这世界指望你在自我感觉良好之前先要有所成就。
——比尔盖茨 生活只有在平淡无味的人看来才是空虚而平淡无味的。
-- 车尔尼雪夫斯基"; $poems=explode("\n",$poems); return $poems[rand(0,count($poems)-1)]; } function says(){ $says=random_str(); echo $says; } ?>关键在于这几句: 复制代码 代码如下: $poems=explode("\n",$poems); return $poems[rand(0,count($poems)-1)];如果您使用的是wordpress博客系统,可以把该文件says.php放到主题根目录下,然后修改主题根目录下的header.php,插入一条语句到前面: 复制代码 代码如下: 然后在你想显示随机名人名言的位置插入如下语句: says(); 这样就可以调用了。
对wordpress系统不是很了解,这个方法肯定不是最好的方法。
百度熊掌号接口配置服务器地址(url)指什么,如何填写
展开全部 网站CMS:WordPress网站主题:大前端DUX涉及文件:header.phpfunctions.phpsingle.php改造作用:1.添加以下代码后,您提交的内容能在搜索结果中以结构化样式展现。
2.同时每天还会从您提交的新增内容中随机抽取5条在您的手机百度熊掌号主页中展现。
准备好了就开始:header.php修改打开网站后台文件夹,进入根目录-wp_content-theme文件夹,找到header.php文件,加入如下代码:"/>{"@context ": "https://ziyuan.baidu.com/contexts/cambrian.jsonld","@id ": "'.get_the_permalink().'","appid": "你的熊掌号ID","title": "'.get_the_title().'","images": ["'.fanly_post_imgs().'"],"description": "'.fanly_excerpt().'","pubDate": "'.get_the_time('Y-m-d\TH:i:s').'"}';代码详解:第一行添加canonlcal标签第二行添加熊掌号ID声明剩下的代码添加JSON_LD数据!具体详情可在熊掌号查看,这里只需要修改熊掌号id即可,在页面提交中即可找到,最后保存即可!functions.php修改1. 打开当前目录下functions.php文件,添加如下代码://百度熊掌号页面改造//获取文章/页面摘要function fanly_excerpt($len=220){if ( is_single() || is_page() ){global $post;if ($post->post_excerpt) {$excerpt = $post->post_excerpt;} else {if(preg_match('/(.*)/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);}}//优先获取文章中的三张图,否则依次获取自定义图片/特色缩略图/文章首图 last update 2017/11/23function fanly_post_imgs(){global $post;$content = $post->post_content;preg_match_all('//', $content, $strResult, PREG_PATTERN_ORDER);$n = count($strResult[1]);if($n >= 3){$src = $strResult[1][0].'","'.$strResult[1][1].'","'.$strResult[1][2];}else{if( $values = get_post_custom_values("thumb") ) { //输出自定义域图片地址$values = get_post_custom_values("thumb");$src = $values [0];} elseif( has_post_thumbnail() ){ //如果有特色缩略图,则输出缩略图地址$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'full');$src = $thumbnail_src [0];} else { //文章中获取if($n > 0){ // 提取首图$src = $strResult[1][0];return $src;}这段代码的作用是通过上一段代码定义的两个函数获取文章和页面的描述以及图像。
两个变量为:.fanly_post_imgs().fanly_excerpt()single.php修改打开singlephp文件,并添加如下代码,添加地方大概在第二十行,后面。
cambrian.render('tail')顶部bar-在页面标签后添加代码cambrian.render('head')段落间bar-在页面段落之间添加代码cambrian.render('body')最后一种底部bar就是我们现在使用的,注意,最多只能添加两个bar,百度后期会审核!在线检验页面改造完毕后,使用在线检验工具检查页面的正确性!打开熊掌号-页面改造-在线检验工具。
随便打开博客内的一篇文章,复制该页URL地址并输入到检验工具中。
将刚才那篇文章的源代码(F12)也复制过去。
如果成功,显示检验成功!
怎样制作wordpress的面包屑导航
展开全部 如果是新手, 建议用其他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 '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 ...
转载请注明出处51数据库 » wordpress explode
送快递查水表社区送温暖