在function.php中设置:
get('Version'));
define('GIT_URL', get_template_directory_uri());
add_action('after_setup_theme', 'deel_setup');
require ('admin/theme-options.php');
require ('admin/theme-widgets.php');
require ('admin/theme-metabox.php');
require ('include/func_load.php');
if (!defined('POINTS_CORE_DIR')) {
require ('modules/points.php');
}
function deel_setup() {
//添加主题特性
add_theme_support('post-thumbnails');//缩略图设置
add_theme_support('post-formats', array('aside')); //增加文章形式
add_theme_support('custom-background', array(
'default-image' => GIT_URL . '/assets/img/bg.png',
'default-repeat' => 'repeat',
'default-position-x' => 'left',
'default-position-y' => 'top',
'default-size' => 'auto',
'default-attachment' => 'fixed'
));
add_editor_style('editor-style.css');
//定义菜单
if (function_exists('register_nav_menus')) {
register_nav_menus(array(
'nav' => '网站导航',
'pagemenu' => '页面导航'
));
}
}
//自定义ajax提醒
function git_err($ErrMsg) {
header('HTTP/1.1 405 Method Not Allowed');
echo $ErrMsg;
exit;
}
//去除部分默认小工具
function unregister_d_widget() {
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Nav_Menu_Widget');
}
add_action('widgets_init', 'unregister_d_widget');
add_filter('admin_footer_text', 'git_admin_footer_text');
//显示数据库查询次数、查询时间及内存占用的代码
function git_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', 'git_performance', 20);
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => '全站侧栏',
'id' => 'widget_sitesidebar',
'before_widget' => '',
'after_title' => '
'
));
register_sidebar(array(
'name' => '首页侧栏',
'id' => 'widget_sidebar',
'before_widget' => ' ',
'before_title' => '',
'after_title' => '
'
));
register_sidebar(array(
'name' => '分类/标签/搜索页侧栏',
'id' => 'widget_othersidebar',
'before_widget' => ' ',
'before_title' => '',
'after_title' => '
'
));
register_sidebar(array(
'name' => '文章页侧栏',
'id' => 'widget_postsidebar',
'before_widget' => ' ',
'before_title' => '',
'after_title' => '
'
));
register_sidebar(array(
'name' => '页面侧栏',
'id' => 'widget_pagesidebar',
'before_widget' => ' ',
'before_title' => '',
'after_title' => '
'
));
}
//面包屑导航
function deel_breadcrumbs(){
if (!is_single() || get_post_type() != 'post') {
return false;
}
$categorys = get_the_category();
$category = $categorys[0];
return ' > ' . get_category_parents($category->term_id, true, ' > ') . '' . get_the_title() . '';
}
// 取消原有jQuery,加载自定义jQuery
function footerScript() {
if (!is_admin()) {
wp_deregister_script('jquery');
if (git_get_option('git_jqcdn') == 'git_jqcdn_upai') {
wp_register_script('jquery', 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/js/jquery-1.8.3.min.js', false, '1.0', true); //底部加载,速度快,兼容差
} else {
wp_register_script('jquery', GIT_URL . '/assets/js/jquery.min.js', false, '1.0', false); //头部加载,速度慢,兼容好
}
wp_enqueue_script('jquery');
wp_register_script('default', GIT_URL . '/assets/js/app.js', false, '1.0', true); //底部加载
wp_enqueue_script('default');
wp_register_style('style', GIT_URL . '/style.css', false, '1.0');
wp_enqueue_style('style');
}
}
add_action('wp_enqueue_scripts', 'footerScript');
if (!function_exists('deel_paging')) {
function deel_paging(){
$p = 4;
if (is_singular()) {
return;
}
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ($max_page == 1) {
return;
}
echo '';
if (empty($paged)) {
$paged = 1;
}
// echo 'Page: ' . $paged . ' of ' . $max_page . ' ';
echo '- ';
previous_posts_link('上一页');
echo '
';
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 "- {$i}
" : p_link($i);
}
}
if ($paged < $max_page - $p - 1) {
echo "- ...
";
}
//if ( $paged < $max_page - $p ) p_link( $max_page, '»' );
echo ' ';
// echo '- 共 '.$max_page.' 页
';
echo '
';
}
function p_link($i, $title = '')
{
if ($title == '') {
$title = "第 {$i} 页";
}
echo "{$i} ";
}
}
function deel_strimwidth($str, $start, $width, $trimmarker) {
$output = preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $start . '}((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $width . '}).*/s', '\1', $str);
return $output . $trimmarker;
}
if (!function_exists('deel_views')) {
function deel_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', 'deel_record_visitors');
function deel_views($after = '')
{
global $post;
$post_ID = $post->ID;
$views = (int) get_post_meta($post_ID, 'views', true);
echo $views, $after;
}
}
//页面伪静态
if (git_get_option('git_pagehtml_b')) {
function html_page_permalink(){
global $wp_rewrite;
if (!strpos($wp_rewrite->get_page_permastruct(), '.html')) {
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
}
}
add_action('init', 'html_page_permalink', -1);
}
//baidu分享
$dHasShare = false;
function deel_share() {
if (!git_get_option('git_bdshare_b')) return false;
echo ' ';
global $dHasShare;
$dHasShare = true;
}
//搜索表单
function git_searchform() {
$search_placeholder = git_get_option('git_search_placeholder');
?>
',
'before_title' => '
评论 (' . $commentcount . ')'; if (get_post_meta($postid, 'bigfa_ding', true)) { $output.= get_post_meta($postid, 'bigfa_ding', true); } else { $output.= '0'; } $output.= '赞
' . $i . '' . $title . ']*?class\s*?=\s*?[",\'].*?prettyprint.*?[",\'].*?>)(.*?)(<\/pre>)/sim'; return preg_replace_callback($regex, 'git_esc_callback', $content); } function git_esc_callback($matches) { $tag_open = $matches[1]; $content = $matches[2]; $tag_close = $matches[3]; $content = esc_html($content); return $tag_open . $content . $tag_close; } add_filter('the_content', 'git_esc_html', 2); add_filter('comment_text', 'git_esc_html', 2); //强制兼容function git_prettify_replace($text) { $replace = array( '' => '' ); $text = str_replace(array_keys($replace) , $replace, $text); return $text; } add_filter('the_content', 'git_prettify_replace'); //首页隐藏一些分类 function exclude_category_home($query) { if ($query->is_home) { $query->set('cat', git_get_option('git_blockcat')); //隐藏这两个分类 } return $query; } add_filter('pre_get_posts', 'exclude_category_home'); function git_exclude_category_search($query) { if (!$query->is_admin && $query->is_search) { $query->set('cat', git_get_option('git_blockcat_search')); //隐藏这两个分类 } return $query; } add_filter('pre_get_posts', 'git_exclude_category_search'); function git_exclude_category_rss($query) { if ($query->is_feed) { $query->set('cat', git_get_option('git_blockcat_rss')); //隐藏这两个分类 } return $query; } add_filter('pre_get_posts', 'git_exclude_category_rss'); //后台日志阅读统计 add_filter('manage_posts_columns', 'postviews_admin_add_column'); function postviews_admin_add_column($columns) { $columns['views'] = '阅读'; return $columns; } add_action('manage_posts_custom_column', 'postviews_admin_show', 10, 2); function postviews_admin_show($column_name, $id) { if ($column_name != 'views') return; $post_views = get_post_meta($id, "views", true); echo $post_views; } //后台快捷键回复 function hui_admin_comment_ctrlenter() { echo ''; }; add_action('admin_footer', 'hui_admin_comment_ctrlenter'); //获取所有站点分类id function Bing_category(){ $cat_ids = get_transient('Bing_category'); if (false === $cat_ids) { $categories = get_terms('category', 'hide_empty=0'); $k = []; foreach ($categories as $categorie) { $k[] = $categorie->term_id; } $cat_ids = implode(",", $k); set_transient('Bing_category', $cat_ids, 60*60*24*5);//缓存5天 } $cat_ids = explode(",", $cat_ids); foreach ($cat_ids as $catid) { $cat_name = get_cat_name($catid); $output = '' . $cat_name . "=(" . $catid . ') '; echo $output; } } //主题自动更新服务 if (!git_get_option('git_updates_b')) { require 'modules/updates.php'; $example_update_checker = new ThemeUpdateChecker('Git-alpha', 'https://u.gitcafe.net/api/info.json'); } //评论拒绝HTML代码 if (git_get_option('git_html_comment')) { function git_comment_post($incoming_comment){ $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']); $incoming_comment['comment_content'] = str_replace("'", ''', $incoming_comment['comment_content']); return $incoming_comment; } function git_comment_display($comment_to_display){ $comment_to_display = str_replace(''', "'", $comment_to_display); return $comment_to_display; } add_filter('preprocess_comment', 'git_comment_post', '', 1); add_filter('comment_text', 'git_comment_display', '', 1); add_filter('comment_text_rss', 'git_comment_display', '', 1); add_filter('comment_excerpt', 'git_comment_display', '', 1); } //中文文件重命名 function git_upload_filter($file) { $time = date("YmdHis"); $file['name'] = $time . "" . mt_rand(1, 100) . "." . pathinfo($file['name'], PATHINFO_EXTENSION); return $file; } add_filter('wp_handle_upload_prefilter', 'git_upload_filter'); //后台文章重新排序 function git_post_order_in_admin($wp_query) { if (is_admin()) { $wp_query->set('orderby', 'modified'); $wp_query->set('order', 'DESC'); } } add_filter('pre_get_posts', 'git_post_order_in_admin'); //UA信息 if (git_get_option('git_ua_b')) { function user_agent($ua){ //开始解析操作系统 $os = null; if (preg_match('/Windows NT 6.0/i', $ua)) { $os = 'Windows Vista'; } elseif (preg_match('/Windows NT 6.1/i', $ua)) { $os = 'Windows 7'; } elseif (preg_match('/Windows NT 6.2/i', $ua)) { $os = 'Windows 8'; } elseif (preg_match('/Windows NT 6.3/i', $ua)) { $os = 'Windows 8.1'; } elseif (preg_match('/Windows NT 10.0/i', $ua)) { $os = 'Windows 10'; } elseif (preg_match('/Windows NT 5.1/i', $ua)) { $os = 'Windows XP'; } elseif (preg_match('/Mac OS X/i', $ua)) { $os = 'Mac OS X'; } elseif (preg_match('#Linux#i', $ua)) { $os = 'Linux '; } elseif (preg_match('#Windows Phone#i', $ua)) { $os = 'Windows Phone '; } elseif (preg_match('/Windows NT 5.2/i', $ua) && preg_match('/Win64/i', $ua)) { $os = 'Windows XP 64 bit'; } elseif (preg_match('/Android ([0-9.]+)/i', $ua, $matches)) { $os = 'Android ' . $matches[1]; } elseif (preg_match('/iPhone OS ([_0-9]+)/i', $ua, $matches)) { $os = 'iPhone ' . $matches[1]; } else { $os = '未知操作系统'; } if (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'Camino ' . $matches[2]; } elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = '搜狗浏览器 2' . $matches[1]; } elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = '360浏览器 ' . $matches[1]; } elseif (preg_match('#Maxthon( |\\/)([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'Maxthon 浏览器' . $matches[2]; } elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'Chrome ' . $matches[1]; } elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $ua, $matches)) { $browser = '小米浏览器 ' . $matches[1]; } elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'Safari浏览器 ' . $matches[1]; } elseif (preg_match('#opera mini#i', $ua)) { preg_match('#Opera/([a-zA-Z0-9.]+)#i', $ua, $matches); $browser = 'Opera Mini ' . $matches[1]; } elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'Opera ' . $matches[1]; } elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = '腾讯TT浏览器 ' . $matches[1]; } elseif (preg_match('#(UCWEB|UBrowser|UCBrowser)/([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'UC浏览器 ' . $matches[1]; } elseif (preg_match('#(QQ|TIM)/([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = '手机QQ ' . $matches[1]; } elseif (preg_match('#Vivaldi/([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'Vivaldi浏览器 ' . $matches[1]; } elseif (preg_match('#wp-(iphone|android)/([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'WordPress客户端 ' . $matches[1]; } elseif (preg_match('#MicroMessenger/([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = '微信浏览器 ' . $matches[1]; } elseif (preg_match('#Edge ([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = '微软Edge浏览器 ' . $matches[1]; } elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'Internet Explorer ' . $matches[1]; } elseif (preg_match('#(Firefox|Phoenix|SeaMonkey|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $ua, $matches)) { $browser = 'Firefox浏览器 ' . $matches[2]; } else { $browser = '未知浏览器'; } return $os . " | " . $browser; } } //添加碎语功能 function git_shuoshuo() { $labels = array( 'name' => '说说', 'singular_name' => '说说', 'add_new' => '发表说说', 'add_new_item' => '发表说说', 'edit_item' => '编辑说说', 'new_item' => '新说说', 'view_item' => '查看说说', 'search_items' => '搜索说说', 'not_found' => '暂无说说', 'not_found_in_trash' => '没有已遗弃的说说', 'menu_name' => '说说' ); $args = array( 'labels' => $labels, 'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'capability_type' => 'post', 'menu_icon' => 'dashicons-megaphone', 'menu_position' => 4, 'supports' => array( 'editor', 'title', 'author' ) ); register_post_type('shuoshuo', $args); } add_action('init', 'git_shuoshuo'); //添加产品功能 if (!defined('UM_DIR') || !defined('WC_PLUGIN_FILE')) { /*如果安装um/Woo的话,就禁用这个功能*/ function git_product() { $labels = array( 'name' => '产品', 'singular_name' => '产品', 'menu_name' => '产品', 'name_admin_bar' => '产品', 'archives' => '产品分类', 'parent_item_colon' => '父分类', 'all_items' => '所有产品', 'add_new_item' => '添加新的产品', 'add_new' => '添加新产品', 'new_item' => '新产品', 'edit_item' => '编辑产品', 'update_item' => '更新产品', 'view_item' => '查看产品', 'search_items' => '搜索产品', 'not_found' => '没有产品', 'not_found_in_trash' => '回收站内没有产品', 'featured_image' => '特色图片', 'set_featured_image' => '设置特色图片', 'remove_featured_image' => '移除特色图片', 'use_featured_image' => '设为特色图片', 'insert_into_item' => '插入产品', 'uploaded_to_this_item' => '上传', 'items_list' => '产品列表', 'items_list_navigation' => '产品列表导航', 'filter_items_list' => '筛选产品列表', ); $rewrite = array( 'slug' => 'product', 'with_front' => true, 'pages' => true, 'feeds' => true, ); $args = array( 'label' => '产品', 'description' => '产品功能', 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields', ) , 'hierarchical' => false, 'public' => true, 'menu_position' => 7, 'menu_icon' => 'dashicons-cart', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => 'product', 'exclude_from_search' => true, 'publicly_queryable' => true, 'rewrite' => $rewrite, 'capability_type' => 'page', ); register_post_type('product', $args); } add_action('init', 'git_product', 0); //产品的固定连接格式 function custom_product_link($link, $post = 0) { if ($post->post_type == 'product') { return home_url('product/' . $post->ID . '.html'); } else { return $link; } } add_filter('post_type_link', 'custom_product_link', 1, 3); function custom_product_rewrites_init() { add_rewrite_rule('product/([0-9]+)?.html$', 'index.php?post_type=product&p=$matches[1]', 'top'); } add_action('init', 'custom_product_rewrites_init'); } //压缩html代码 if (git_get_option('git_compress')) { function wp_compress_html(){ function wp_compress_html_main($buffer){ if ( substr( ltrim( $buffer ), 0, 5) == '", $buffer); $count = count($buffer); for ($i = 0; $i <= $count; $i++) { if (stristr($buffer[$i], '')) { $buffer[$i] = str_replace("", " ", $buffer[$i]); } else { $buffer[$i] = str_replace("\t", " ", $buffer[$i]); $buffer[$i] = str_replace("\n\n", "\n", $buffer[$i]); $buffer[$i] = str_replace("\n", "", $buffer[$i]); $buffer[$i] = str_replace("\r", "", $buffer[$i]); while (stristr($buffer[$i], ' ')) { $buffer[$i] = str_replace(" ", " ", $buffer[$i]); } } $buffer_out .= $buffer[$i]; } $final = strlen($buffer_out); if ($initial !== 0) { $savings = ($initial - $final) / $initial * 100; } else { $savings = 0; } $savings = round($savings, 2); $buffer_out .= "\n"; return $buffer_out; } ob_start("wp_compress_html_main"); } add_action('get_header', 'wp_compress_html'); function git_unCompress($content) { if (preg_match_all('/(crayon-|)/i', $content, $matches)) { $content = '' . $content; $content .= ''; } return $content; } add_filter('the_content', 'git_unCompress'); } //增强编辑器开始 function git_editor_buttons($buttons) { $buttons[] = 'fontselect'; $buttons[] = 'fontsizeselect'; $buttons[] = 'backcolor'; return $buttons; } add_filter('mce_buttons_3', 'git_editor_buttons'); //获取访客VIP样式 if (git_get_option('git_vip')): function get_author_class($comment_author_email, $user_id) { $author_count = get_transient('author_count'); if(false === $author_count){ global $wpdb; $author_count = count($wpdb->get_results("SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' ")); set_transient('author_count', $author_count, 60*60*2);//缓存2小时 } if ($author_count >= 1 && $author_count < git_get_option('git_vip1')) echo ''; else if ($author_count >= git_get_option('git_vip1') && $author_count < git_get_option('git_vip2')) echo ''; else if ($author_count >= git_get_option('git_vip2') && $author_count < git_get_option('git_vip3')) echo ''; else if ($author_count >= git_get_option('git_vip3') && $author_count < git_get_option('git_vip4')) echo ''; else if ($author_count >= git_get_option('git_vip4') && $author_count < git_get_option('git_vip5')) echo ''; else if ($author_count >= git_get_option('git_vip5') && $author_count < git_get_option('git_vip6')) echo ''; else if ($author_count >= git_get_option('git_vip6')) echo ''; } endif; // 评论添加@,来自:http://www.ludou.org/wordpress-comment-reply-add-at.html function git_comment_add_at($comment_text, $comment = '') { if ($comment->comment_parent > 0) { $comment_text = '@' . get_comment_author($comment->comment_parent) . ' ' . $comment_text; } return $comment_text; } add_filter('comment_text', 'git_comment_add_at', 20, 2); //导航单页函数 function get_the_link_items($id = null) { $bookmarks = get_bookmarks('orderby=date&category=' . $id); $output = ''; if (!empty($bookmarks)) { $output.= ''; foreach ($bookmarks as $bookmark) { $output.= ''; } $output.= ''; } return $output; } function get_link_items() { $linkcats = get_terms('link_category', 'orderby=count&hide_empty=1&exclude=' . git_get_option('git_linkpage_cat')); if (!empty($linkcats)) { foreach ($linkcats as $linkcat) { $result.= '' . $linkcat->name . '
'; if ($linkcat->description) $result.= '' . $linkcat->description . ''; $result.= get_the_link_items($linkcat->term_id); } } else { $result = get_the_link_items(); } return $result; } //保护后台登录 //救命啊!ps.很好,搜索这段代码很可能意味着你把自己后台给锁了,将下面保护后台登录这段代码删除即可 //开始删除 if (git_get_option('git_admin')) { function git_login_protection() { if ($_GET[''.git_get_option('git_admin_q').''] !== git_get_option('git_admin_a')) { wp_die('您的访问密码错误,请使用加密链接登录,如果不明白怎么回事,请直接到主题function文件搜索【救命】'); } } add_action('login_enqueue_scripts', 'git_login_protection'); } //删除到这里结束 //获取云落的远程通知,加入缓存,1天一次 function get_Yunluo_Notice(){ $Yunluo_Notice = get_transient('Yunluo_Notice'); if(false === $Yunluo_Notice){ $Yunluo_Notice = wp_remote_get('https://u.gitcafe.net/api/notice.txt')['body']; if ( is_array( $Yunluo_Notice ) && !is_wp_error($Yunluo_Notice) && $Yunluo_Notice['response']['code'] == '200' ) { set_transient('Yunluo_Notice', $Yunluo_Notice, 60*60*12);//缓存12小时 }else{ set_transient('Yunluo_Notice', '有点小尴尬哈啊,服务器菌暂时有点累了呢,先休息一会儿~,', 60*60*2);//缓存2小时 } } return $Yunluo_Notice; } //获取页面id,并且不可重用 function git_page_id( $pagephp ) { global $wpdb; $pagephp = esc_sql($pagephp); $pageid = $wpdb->get_row("SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE `meta_value` = 'pages/{$pagephp}.php'", ARRAY_A) ['post_id']; return $pageid; } //根据订单描述金币数据,d=订单号 u=用户id function git_check( $d , $u = null) { global $wpdb; $des = " WHERE `description` = '" . $d . "'"; $userid = ""; if ( isset( $u ) && ( $u !== null ) ) { $userid = " AND `user_id` = '" . $u . "'"; } $result = $wpdb->query("SELECT `point_id` FROM " . Points_Database::points_get_table("users") . $des . $userid . " AND `status` = 'accepted' LIMIT 3", ARRAY_A); return $result;//0=无订单结果,1=有订单结果,>1均为异常数据 } // 内链图片src function link_the_thumbnail_src(){ global $post; ob_start(); ob_end_clean(); $content = $post->post_content; preg_match('/src="(.*?)"/i', $content, $matches, PREG_OFFSET_CAPTURE, 0); $post_thumbnail_src = $matches[1][0]; if (empty($post_thumbnail_src)) { $post_thumbnail_src = GIT_URL . '/assets/img/pic/' . mt_rand(1, 12) . '.jpg'; } return $post_thumbnail_src; } //文章目录,来自露兜,云落修改 if (git_get_option('git_article_list')) { function article_index($content) { $matches = array(); $ul_li = ''; $r = "/([^<]+)<\/h2>/im"; if (is_single() && preg_match_all($r, $content, $matches)) { foreach ($matches[1] as $num => $title) { $title = trim(strip_tags($title)); $content = str_replace($matches[0][$num], '
' . $title . '
', $content); $ul_li.= '
输入标签封面图片URL
输入标签标题
输入标签封面图片URL
输入标签标题