/**熊掌号isOriginal声明原创*/
function is_yc($post_ID){
//获取文章自定义栏目is_yc的值,0非原创 1原创
$is_yc= get_post_meta($post_ID,'is_yc',true);
if($is_yc==1||$is_yc==''){
return 1;
}else if($is_yc==0){
return 0;
}
}
/**搜索伪静态**/
function v7v3_search_url_rewrite() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) . "/");
exit();
}
}
add_action( 'template_redirect', 'v7v3_search_url_rewrite' );
/**在后台文章列表增加浏览量
add_filter( 'manage_posts_columns', 'ashuwp_customer_posts_columns' );
function ashuwp_customer_posts_columns( $columns ) {
$columns['views'] = '浏览次数';
return $columns;
}
//输出浏览次数
add_action('manage_posts_custom_column', 'ashuwp_customer_columns_value', 10, 2);
function ashuwp_customer_columns_value($column, $post_id){
if($column=='views'){
$count = get_post_meta($post_id, 'post_views_count', true);
if(!$count){
$count = 0;
}
echo $count;
}
return;
}**/
/* 发布文章自动设置字段*/
add_action('publish_post', 'add_custom_field_automatically', 10, 2 );
add_action( 'publish_picture', 'add_custom_field_automatically', 10, 2 );
function add_custom_field_automatically($post_ID) {
global $wpdb;
if(!wp_is_post_revision($post_ID)) {
$random = 0;
$random2 = 0;
if(option_off('cx_fujia_views'))
$random = mt_rand(500, 2000);
if(option_off('cx_fujia__ding'))
$random2 = mt_rand(5, 20);
add_post_meta($post_ID, 'views', $random, true);
add_post_meta($post_ID, 'bigfa_ding', $random2, true);
add_post_meta($post_ID, 'chenxing_post_collects', 0, true);
}
}
/* WordPress文字标签关键词自动内链
*/
$match_num_from = 1; //一篇文章中同一个标签少于几次不自动链接
$match_num_to = 1; //一篇文章中同一个标签最多自动链接几次
function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
function tin_tag_link($content){
global $match_num_from,$match_num_to;
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
$ex_word = '';
$case = '';
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = " $url .= ' target="_blank"';
$url .= ">".addcslashes($cleankeyword, '$')."";
$limit = rand($match_num_from,$match_num_to);
$content = preg_replace( '|(]+>)(.*)
$content = preg_replace( '|()|U'.$case, '$1$2$4$5', $content);
$cleankeyword = preg_quote($cleankeyword,'\'');
$regEx = '\'(?!((<.*?)|(
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( '', stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter('the_content','tin_tag_link',12);
/**移除WordPress标志,防止黑客扫描网站*/
remove_action('wp_head','wp_generator');
/**熊掌号原创内容提交**/
if(!function_exists('xiongzhang123')) {
function xiongzhang123($post_ID) {
$WEB_TOKEN='f7q8u1Xhi7i3HDRL'; //这里换成你的网站的百度主动推送的token值
$WEB_DOMAIN=get_option('home');
//已成功推送的文章不再推送
if(get_post_meta($post_ID,'xiongzhang123',true) == 1) return;
$url = get_permalink($post_ID);
$api = 'http://data.zz.baidu.com/urls?appid=1617725043698362&token=4D7JkJrS3JVpZjII&type=realtime';
$data = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-Type: text/plain",
"Content-Length: ".strlen($url)."rn",
'content' => $url
)
);
$data = stream_context_create($data);
$result = file_get_contents($api, false, $data);
$result = json_decode($result,true);
//如果推送成功则在文章新增自定义栏目Baidusubmit,值为1
if (array_key_exists('success_realtime',$result)) {
add_post_meta($post_ID, 'xiongzhang123', 1, true);
}
}
add_action('publish_post', 'xiongzhang123');
}
/**WordPress发布文章主动推送到百度,加快收录保护原创【file_get_contents方式】**/
if(!function_exists('Baidu_Submit1')) {
function Baidu_Submit1($post_ID) {
$WEB_TOKEN='K6ixl9CcQkZddh5B'; //这里换成你的网站的百度主动推送的token值
$WEB_DOMAIN=get_option('home');
//已成功推送的文章不再推送
if(get_post_meta($post_ID,'Baidusubmit',true) == 1) return;
$url = get_permalink($post_ID);
$api = 'http://data.zz.baidu.com/urls?site=www.fanhaota.com&token=K6ixl9CcQkZddh5B';
$data = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-Type: text/plain",
"Content-Length: ".strlen($url)."rn",
'content' => $url
)
);
$data = stream_context_create($data);
$result = file_get_contents($api, false, $data);
$result = json_decode($result,true);
//如果推送成功则在文章新增自定义栏目Baidusubmit,值为1
if (array_key_exists('success',$result)) {
add_post_meta($post_ID, 'Baidusubmit1', 1, true);
}
}
add_action('publish_post', 'Baidu_Submit1', 0);
}
/**显示数据库查询次数、查询时间及内存占用的代码**/
function performance( $visible = false ) {
$stat = sprintf( '%d 次查询 用时 %.3f 秒, 耗费了 %.2fMB 内存',
get_num_queries(),
timer_stop( 0, 3 ),
memory_get_peak_usage() / 1024 / 1024
);
echo $visible ? $stat : "" ;
}
add_action( 'wp_footer', 'performance', 20 );
/* 文章图片自动添加alt和title信息*/
function tin_image_alt($content){
global $post;
$pattern = "//i";
$replacement = '';
$content = preg_replace($pattern,$replacement,$content);
return $content;
}
add_filter('the_content','tin_image_alt',15);
/**获取文章/页面摘要**/
function fanly_excerpt($len=220){
if ( is_single() || is_page() ){
global $post;
if ($post->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);
}
}
/**获取文章中的图 last update 2018/01/22**/
function fanly_post_imgs(){
global $post;
$src = '';
$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];
}elseif($n >= 1){
$src = $strResult[1][0];
}
return $src;
}
/**
==================================================
fancybox图片灯箱效果
==================================================
**/
add_filter('the_content', 'fancybox1');
add_filter('the_content', 'fancybox2');
function fancybox1($content){
global $post;
$pattern = "/]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>/i";
$replacement = '';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
function fancybox2($content){
global $post;
$pattern = "/]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\/a>/i";
$replacement = '$7';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
/**删除wp自动生成rel_canonical标签
**/
remove_action( 'wp_head', 'rel_canonical' );
/** wordpress中使用canonical标签**/
function cx_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_single() ) {
$link = get_permalink( $id );
} 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' );
}
}
echo '';
}
add_action('wp_head', 'cx_archive_link');
//移除feed
function wpjam_disable_feed() {
wp_die(__('
// 移除自动保存和修订版本
add_action('wp_print_scripts','tin_disable_autosave' );
remove_action('post_updated','wp_save_post_revision' );
/* 移除自动保存
/* -------------- */
function tin_disable_autosave() {
wp_deregister_script('autosave');
}
//移除rel='shortlink'
remove_action('wp_head','wp_shortlink_wp_head',10,0);
remove_action('template_redirect','wp_shortlink_header',11,0);
//移除feed
function wpjam_disable_feed() {
wp_die(__('
/**在后台文章列表增加浏览量**/
add_filter( 'manage_posts_columns', 'ashuwp_customer_posts_columns' );
function ashuwp_customer_posts_columns( $columns ) {
$columns['views'] = '浏览次数';
return $columns;
}
//输出浏览次数
add_action('manage_posts_custom_column', 'ashuwp_customer_columns_value', 10, 2);
function ashuwp_customer_columns_value($column, $post_id){
if($column=='views'){
$count = get_post_meta($post_id, 'post_views_count', true);
if(!$count){
$count = 0;
}
echo $count;
}
return;
}