HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/8.2.20
System: Linux 825a8fd6cf8c 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64
User: apache (48)
PHP: 8.2.20
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/themes/mobile/functions.php
<?php
/*** 首页分页页码调用  ,调用代码<?php wp_pagenavi() ? >****/

	function
	wp_pagenavi(
	$before = '', 
	$after = '', 
	$prelabel = '', 
	$nxtlabel = '', 
	$pages_to_show = 5, 
	$always_show = false
	) {
global $request, $posts_per_page, $wpdb, $paged;
if(empty($prelabel)) { $prelabel = '上一页';
} if(empty($nxtlabel)) {
$nxtlabel = '下一页';
} $half_pages_to_show = round($pages_to_show/2);
if (!is_single()) {
if(!is_category()) {
preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches); } else {
preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches); }
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts /$posts_per_page);
if(empty($paged)) {
$paged = 1;
}
if($max_page > 1 || $always_show) {
echo "$before <span class=extend>当前第 $paged / $max_page 页 : </span>"; if ($paged >= ($pages_to_show-1)) {
echo '<a href="'.get_pagenum_link().'">&laquo; 首页</a>'; }
previous_posts_link($prelabel);
for($i = $paged - $half_pages_to_show; $i <= $paged + $half_pages_to_show; $i++) { if ($i >= 1 && $i <= $max_page) { if($i == $paged) {
echo "<strong class=now-page>$i</strong>";
} else {
echo '<a href="'.get_pagenum_link($i).'">'.$i.'</a>'; }
}
}
next_posts_link($nxtlabel, $max_page);
if (($paged+$half_pages_to_show) < ($max_page)) {
echo '<a href="'.get_pagenum_link($max_page).'">尾页 &raquo;</a>'; }
echo " $after";
}
}
}

    //初始化时执行myadvert_button函数   
    add_action('init', 'myadvert_button');   
    function myadvert_button() {   
        //判断用户是否有编辑文章和页面的权限   
        if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {   
            return;   
        }   
        //判断用户是否使用可视化编辑器   
        if ( get_user_option('rich_editing') == 'true' ) {   
      
            add_filter( 'mce_external_plugins', 'add_plugin' );   
            add_filter( 'mce_buttons', 'register_button' );   
        }   
    }  

function register_button( $buttons ) {   
    array_push( $buttons, "|", "myadvert" ); //添加 一个myadvert按钮   
    //array_push( $buttons, "|", "mylink" ); //添加一个mylink按钮   
  
    return $buttons;   
}   
function add_plugin( $plugin_array ) {   
   $plugin_array['myadvert'] = get_bloginfo( 'template_url' ) . '/js/taobao.js'; //myadvert按钮的js路径   
   //$plugin_array['mylink'] = get_bloginfo( 'template_url' ) . '/js/mylink.js'; //mylink按钮的js路径   
   return $plugin_array;   
} 
//打开友情链接后台选项
add_filter( 'pre_option_link_manager_enabled', '__return_true' );


function cutstr($string, $length) {

$i = 0;//判断从$i位置截取字符串

$len_word = 0;//统计是否大于指定长度

while($len_word < $length) {

$stringtmp = substr($string, $i, 1);

if(ord($stringtmp) >= 224) {

$stringtmp = substr($string, $i, 3);

$i = $i + 3;

$len_word = $len_word + 2;

}else if(ord($stringtmp) >= 192) {

$stringtmp = substr($string, $i, 2);

$i = $i + 2;

$len_word = $len_word +2;

}else {

$i = $i + 1;

$len_word = $len_word + 1;

}

$stringlast[] = $stringtmp;

}

if(is_array($stringlast) && !empty($stringlast)) {

$stringlast = implode('',$stringlast);
if(strlen($string)>$length)
$stringlast .= '...';

}

return $stringlast;

}


?>