<?php
add_theme_support( 'post-thumbnails'); //添加缩略图支持
set_post_thumbnail_size( 250, 250,true); //设置默认缩略图尺寸
add_image_size( 'po', 100, 100, true ); // 相关文章缩略图
 
//添加导航菜单支持
register_nav_menus( array(
		'primary' => __( 'Primary Navigation'),
) );

//添加小工具
register_sidebar( array (
		'name' => '首页国内新闻',
		'id' => 'vxiao-widget-guonei',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '<div id="con_one_1">',
		'after_widget' => '</div>',
		'before_title' => '<div class="rsstit">',
		'after_title' => '</div>',
	) );
	
register_sidebar( array (
		'name' => '首页国际新闻',
		'id' => 'vxiao-widget-guoji',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '<div id="con_one_2" style="display:none">',
		'after_widget' => '</div>',
		'before_title' => '<div class="rsstit">',
		'after_title' => '</div>',
	) );

register_sidebar( array (
		'name' => '首页财经新闻',
		'id' => 'vxiao-widget-caijing',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '<div id="con_one_3" style="display:none">',
		'after_widget' => '</div>',
		'before_title' => '<div class="rsstit">',
		'after_title' => '</div>',
	) );

register_sidebar( array (
		'name' => '首页体育新闻',
		'id' => 'vxiao-widget-tiyu',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '<div id="con_one_4" style="display:none">',
		'after_widget' => '</div>',
		'before_title' => '<div class="rsstit">',
		'after_title' => '</div>',
	) );
	
register_sidebar( array (
		'name' => '首页科技新闻',
		'id' => 'vxiao-widget-keji',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '<div id="con_one_5" style="display:none">',
		'after_widget' => '</div>',
		'before_title' => '<div class="rsstit">',
		'after_title' => '</div>',
	) );

register_sidebar( array (
		'name' => '顶部功能（左）',
		'id' => 'vxiao-widget-topl',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<!--',
		'after_title' => '-->',
	) );
	
register_sidebar( array (
		'name' => '顶部功能（中）',
		'id' => 'vxiao-widget-topc',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<!--',
		'after_title' => '-->',
	) );

register_sidebar( array (
		'name' => '顶部功能（右）',
		'id' => 'vxiao-widget-topr',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<!--',
		'after_title' => '-->',
	) );

register_sidebar( array (
		'name' => '顶部导航',
		'id' => 'vxiao-widget-nav',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<!--',
		'after_title' => '-->',
	) );

register_sidebar( array (
		'name' => '博客内容',
		'id' => 'vxiao-widget-content',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<!--',
		'after_title' => '-->',
	) );
	
register_sidebar( array (
		'name' => '推荐导航',
		'id' => 'vxiao-widget-tj',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<!--',
		'after_title' => '-->',
	) );

register_sidebar( array (
		'name' => '底部边栏（左）',
		'id' => 'vxiao-widget-left',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
register_sidebar( array (
		'name' => '底部边栏（中）',
		'id' => 'vxiao-widget-conter',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );

register_sidebar( array (
		'name' => '底部边栏（右）',
		'id' => 'vxiao-widget-right',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '<!--',
		'after_title' => '-->',
	) );
	
register_sidebar( array (
		'name' => '正文边栏',
		'id' => 'vxiao-widget-sidebar',
		'description' => __( '请将小工具拖拽至此'),
		'before_widget' => '<div class="sidebox">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>',
	) );


//主题设置页
$themename = "X-girl";  
$shortname = "vxiao.COM";

$categories = get_categories('hide_empty=0&orderby=name');  
$wp_cats = array();  
foreach ($categories as $category_list ) {  
       $wp_cats[$category_list->cat_ID] = $category_list->cat_name;  
}  
array_unshift($wp_cats, "Choose a category");


function mytheme_add_admin() {  
   
global $themename, $shortname, $options;  
   
if ( $_GET['page'] == basename(__FILE__) ) {  
   
    if ( 'save' == $_REQUEST['action'] ) {  
   
        foreach ($options as $value) {  
        update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }  
   
foreach ($options as $value) {  
    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }  
   
    header("Location: admin.php?page=functions.php&saved=true");  
die;  
   
}   
else if( 'reset' == $_REQUEST['action'] ) {  
   
    foreach ($options as $value) {  
        delete_option( $value['id'] ); }  
   
    header("Location: admin.php?page=functions.php&reset=true");  
die;  
   
}  
}  
   
add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');  
}  
  
function mytheme_add_init() {  
$file_dir=get_bloginfo('template_directory');  
wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all");  
} 

function mytheme_admin() {  
   
global $themename, $shortname, $options;  
$i=0;  
   
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';  
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';  
   
?>  
<div class="wrap rm_wrap">  
<h2><?php echo $themename; ?> Settings</h2>  
  
<?php  
}  
  
?>
<?php  
add_action('admin_init', 'mytheme_add_init');  
add_action('admin_menu', 'mytheme_add_admin');  
?>
<?php 
//移除顶部多余信息及版本号等
function wpbeginner_remove_version() { 
return ; 
} add_filter('the_generator', 'wpbeginner_remove_version');//wordpress的版本号
remove_action('wp_head', 'feed_links', 2);// 包含文章和评论的feed 
remove_action('wp_head', 'index_rel_link');//当前文章的索引 
remove_action('wp_head', 'feed_links_extra', 3);// 额外的feed,例如category, tag页 
remove_action('wp_head', 'start_post_rel_link', 10, 0);// 开始篇 
remove_action('wp_head', 'parent_post_rel_link', 10, 0);// 父篇 
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // 上、下篇. 
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );//rel=pre
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 );//rel=shortlink 
remove_action('wp_head', 'rel_canonical' ); 
remove_action('wp_head', 'wlwmanifest_link'); // 外部编辑器
remove_action( 'wp_head','rsd_link');//ML-RPC
wp_deregister_script( 'l10n' );//la0n.js
?>
<?php
//设置小工具RSS订阅的更新时间
add_filter( 'wp_feed_cache_transient_lifetime',  create_function('$a', 'return 1800;') );
//添加来源信息到the_content
function feed_copyright($content) {
	global $wp_query;
$postid = $wp_query->post->ID;
$fd_copy_vurl = get_post_meta($postid, 'vurl_value', true);
$fd_copy_via = get_post_meta($postid, 'via_value', true);
if(is_single() or is_feed()) {                
$content.= '<div id="sm"><a href="'.$fd_copy_vurl.'" rel="nofollow" target="_blank">'.$fd_copy_via.'</a></div>';
$content.= '';           
        }
        return $content;
}
add_filter ('the_content', 'feed_copyright');
?>
<?php
//添加文字预定义内容
function insertPreContent($content) {
if(!is_feed() && !is_home()) {
$content.= '<h3>标题</h3>';
$content.= '<ul>';
$content.= '<li><a href="http://www.vxiao.com">链接</a></li></ul>';
$content.= '<ul><dl>';
$content.= '<dt><a href="http://www.vxiao.com">链接</a></dt>';
$content.= '<dd>简介</dd>';
$content.= '</dl></ul>';
}
return $content;
}
add_filter ('default_content', 'insertPreContent');
?>
<?php
//更改编辑器默认视图为HTML
add_filter('wp_default_editor', create_function('','return "html";'));
?>
<?php
//实现分页
if ( !function_exists('pagenavi') ) {
	function pagenavi( $p = 5 ) { // 取当前页前后各 2 页
		if ( is_singular() ) return; // 文章与插页不用
		global $wp_query, $paged;
		$max_page = $wp_query->max_num_pages;
		if ( $max_page == 1 ) return; // 只有一页不用
		if ( empty( $paged ) ) $paged = 1;
		//echo '<span class="pages">总页数: ' . $paged . ' / ' . $max_page . ' </span> '; // 显示页数
		if ( $paged > 1 ) p_link( $paged - 1, '上一页', '上页' );/* 如果当前页大于1就显示上一页链接 */
		if ( $paged > $p + 1 ) p_link( 1, '最前' );
		if ( $paged > $p + 2 ) echo '... ';
		for( $i = $paged - $p; $i <= $paged + $p; $i++ ) { // 中间页
			if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<span>{$i}</span>" : p_link( $i );
		}
		if ( $paged < $max_page - $p - 1 ) echo '<span class="current">...</span>';
		if ( $paged < $max_page - $p ) p_link( $max_page, '最后' );
		if ( $paged < $max_page ) p_link( $paged + 1,'下一页', '下页' );/* 如果当前页不是最后一页显示下一页链接 */
	}
	function p_link( $i, $title = '', $linktype = '' ) {
		if ( $title == '' ) $title = "第{$i}页";
		if ( $linktype == '' ) { $linktext = $i; } else { $linktext = $linktype; }
		echo "<a href='", esc_html( get_pagenum_link( $i ) ), "' title='{$title}' target='_self'>{$linktext}</a>";
	}
}?>
<?php
//去掉自定义个人资料内容
add_filter('user_contactmethods','hide_profile_fields',10,1);
function hide_profile_fields( $contactmethods ) {
unset($contactmethods['aim']);
unset($contactmethods['jabber']);
unset($contactmethods['yim']);
return $contactmethods;
}
?>
<?php
//添加自定义个人资料内容
function my_new_contactmethods( $contactmethods ) {
// 添加专属页面
$contactmethods['ihome'] = '[个人专属导航]';
return $contactmethods;
}
add_filter('user_contactmethods','my_new_contactmethods',10,1);
?>
<?php
//修改注册页面LOGO
add_action('login_head','my_custom_login_logo');
function my_custom_login_logo(){
	echo '<style type="text/css">';
	echo '.login h1 a{background: url('.get_bloginfo('template_directory').'/images/logo.png) no-repeat top center; width:270px; height:68px;}';
	echo '</style>';
}
//更换登录logo链接
add_filter("login_headerurl", create_function(false,"return get_bloginfo('siteurl');"));
//更换登录logo描述
add_filter("login_headertitle", create_function(false,"return get_bloginfo('description');"));
?>
<?php
remove_filter('the_content', 'wpautop');
?>