wordpress模板主题仿站functions.php常用功能与常用插件

1、wordpress模板主题仿站常用functions.php功能注册开启

<?php
//注册一个小工具
 register_sidebar(
	array(
		'name'              => '侧边栏',
		'before_widget'     => '<div class="sbox">',
		'after_widget'      => '</div>',
		'before_title'      => '<h2>',
		'after_title'       => '</h2>'
	)
 );

//删除wp-nav-menu函数菜单中多余的css选择器
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
function my_css_attributes_filter($var) {
	return is_array($var) ? array() : '';
}


//开启wordpress友情链接管理
add_filter( 'pre_option_link_manager_enabled', '__return_true' );
//开启wordpress特色图片
add_theme_support( 'post-thumbnails' );



//WordPress子分类页面使用父页面模板
add_filter('category_template', 'f_category_template');
function f_category_template($template){
	$category = get_queried_object();
	if($category->parent !='0'){
		while($category->parent !='0'){
			$category = get_category($category->parent);
		}
	}
	
	$templates = array();
 
	if ( $category ) {
		$templates[] = "category-{$category->slug}.php";
		$templates[] = "category-{$category->term_id}.php";
	}
	$templates[] = 'category.php';
	return locate_template( $templates );
}



/**分页   前端调用 <?php kriesi_pagination($query_string); **/
function kriesi_pagination($query_string){
global $posts_per_page, $paged;
$my_query = new WP_Query($query_string ."&posts_per_page=-1");
$total_posts = $my_query->post_count;
if(empty($paged))$paged = 1;
$prev = $paged - 1;
$next = $paged + 1;
$range = 2; // only edit this if you want to show more page-links
$showitems = ($range * 2)+1;
$pages = ceil($total_posts/$posts_per_page);
if(1 != $pages){
echo "<div class='pagination'>";
echo ($paged > 2 && $paged+$range+1 > $pages && $showitems < $pages)? "<a href='".get_pagenum_link(1)."' rel='external nofollow'>最前</a>":"";
echo ($paged > 1 && $showitems < $pages)? "<a href='".get_pagenum_link($prev)."' rel='external nofollow'>上一页</a>":"";
for ($i=1; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
echo ($paged == $i)? "<a href='".get_pagenum_link($i)."' class='current'>".$i."</a>":"<a href='".get_pagenum_link($i)."' class='inactive' rel='external nofollow'>".$i."</a>";
}
}
echo ($paged < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($next)."' rel='external nofollow'>下一页</a>" :"";
echo ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($pages)."' rel='external nofollow'>最后</a>":"";
echo "</div>\n";
}
}

//面包屑
function wz(){
$cat=get_the_category();
$cat=$cat[0];
$positions = '<li><a href="'.get_category_link($cat).'">'.$cat->name. '</a></li>&gt;'; 
if(!is_home() ){ 
	echo '<li><a href="'. get_settings('home') .'">'. '首页&gt;</a></li>';  
if(is_category()){
	echo $positions;
}
elseif(is_single()){
	echo $positions ;
    echo  the_title();
}
elseif(is_search()){echo $s;}
elseif(is_page()){ 
	the_title();
}elseif(is_404()){echo '404错误页面';}

 } 
}

//获取当前分类子分类列表
function get_category_root_id($cat){
$this_category = get_category($cat); // 取得当前分类
while($this_category->category_parent) {// 若当前分类有上级分类时,循环
$this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类(往上爬)
}
return $this_category->term_id; // 返回根分类的id号
}


2、wordpress模板主题仿站常用插件

2.1、wordpress自定义字段插件 -   Advanced Custom Fields 

它可以将字段添加到任何地方。可以在WP上添加字段,包括文章、用户、分类项目、媒体、评论甚至自定义选项页面

2.2、wordpress编辑器插件 - 经典编辑器

启用WordPress经典编辑器和旧式的编辑文章页面,包括TinyMCE、Meta Boxes等。支持扩展此页面的旧插件

2.3、wordpress会员中心登陆注册插件- Wechat Social

支持国内最热门的社交媒体登录。如:微信、QQ、微博、手机登录、账号绑定和解绑,全新的注册页面取代原生注册页面,支持Ultimate Member、WooCommerce、拖动验证码,登录菜单。部分扩展收费

3、wordpress自定义表单插件 Contact Form 7

Contract Form 7 可以管理多个联系表单,而且您可以自定义窗体并灵活调整邮件内容。不过Contact Form 7 不支持把留言的内容保存到数据库,而是需要在后台配置邮箱,留言内容部之间发到你的邮箱里

wordpress自定义模板主题开发仿站教程-wordpress调用标签教程大全

猜你喜欢

转载自blog.csdn.net/qq_39339179/article/details/115118522