Skip to content

Instantly share code, notes, and snippets.

@lvwzhen
Created July 11, 2014 04:08
Show Gist options
  • Save lvwzhen/514dc7aa4ee1d4032864 to your computer and use it in GitHub Desktop.
Save lvwzhen/514dc7aa4ee1d4032864 to your computer and use it in GitHub Desktop.
wordpress-function
<?php
// pagenav
function par_pagenavi($range = 9){
global $paged, $wp_query;
if ( !$max_page ) {$max_page = $wp_query->max_num_pages;}
if($max_page > 1){if(!$paged){$paged = 1;}
// if($paged != 1){echo "<a href='" . get_pagenum_link(1) . "' class='extend' title='跳转到首页'> 返回首页 </a>";}
previous_posts_link(' 上一页 ');
if($max_page > $range){
if($paged < $range){for($i = 1; $i <= ($range + 1); $i++){echo "<a href='" . get_pagenum_link($i) ."'";
if($i==$paged)echo " class='active'";echo ">$i</a>";}}
elseif($paged >= ($max_page - ceil(($range/2)))){
for($i = $max_page - $range; $i <= $max_page; $i++){echo "<a href='" . get_pagenum_link($i) ."'";
if($i==$paged)echo " class='active'";echo ">$i</a>";}}
elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){
for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){echo "<a href='" . get_pagenum_link($i) ."'";if($i==$paged) echo " class='active'";echo ">$i</a>";}}}
else{for($i = 1; $i <= $max_page; $i++){echo "<a href='" . get_pagenum_link($i) ."'";
if($i==$paged)echo " class='active'";echo ">$i</a>";}}
next_posts_link(' 下一页 ');
// if($paged != $max_page){echo "<a href='" . get_pagenum_link($max_page) . "' class='extend' title='跳转到最后一页'> 最后一页 </a>";}
}
}
// 缩略图
add_theme_support('post-thumbnails');
function catch_that_image(){
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img ="0";
}
return $first_img;
};
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号
}
// 修改登录页 logo
function custom_login_logo() {
echo '<style type="text/css">h1 a { background: url('.get_bloginfo('template_directory').'/companylogo.png) 50% 50% no-repeat !important; }</style>';
}
add_action('login_head', 'custom_login_logo');
//去掉顶部菜单栏
show_admin_bar(false);
//去掉左侧板块
function remove_menus() {
global $menu;
$restricted = array(__('Pages'),__('Comments'),__('Media'),__('Appearance'),__('Plugins'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(strpos($value[0], '<') === FALSE) {
if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){
unset($menu[key($menu)]);
}
}
else {
$value2 = explode('<', $value[0]);
if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){
unset($menu[key($menu)]);
}
}
}
}
if ( is_admin() ) {
// 删除左侧菜单
add_action('admin_menu', 'remove_menus');
}
// 删除左侧菜单控制板下的更新
function remove_submenu() {
remove_submenu_page( 'index.php', 'update-core.php' );
}
if ( is_admin() ) {
add_action('admin_init','remove_submenu');
}
//去掉顶部菜单相关信息
function wpdaxue_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo'); //移除Logo
$wp_admin_bar->remove_menu('comments'); //移除评论
$wp_admin_bar->remove_menu('updates'); //移除升级通知
}
add_action( 'wp_before_admin_bar_render', 'wpdaxue_admin_bar' );
remove_action('wp_head', 'wp_generator');
// 同时删除head和feed中的WP版本号
add_filter('admin_footer_text', 'left_admin_footer_text');
function left_admin_footer_text($text) {
// 隐藏左边版本信息
}
add_filter('update_footer', 'right_admin_footer_text', 11);
function right_admin_footer_text($text) {
// 隐藏右边版本信息
}
//隐藏升级提示
add_filter('pre_site_transient_update_core', create_function('$a', "return null;")); // don't update core
add_filter('pre_site_transient_update_plugins', create_function('$a', "return null;")); // don't update plugins
add_filter('pre_site_transient_update_themes', create_function('$a', "return null;")); // don't update themes
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment