init blog

This commit is contained in:
dengtongyu committed 2018-05-08 11:22:54 +08:00
1 parent 5acc46db8e
commit 843783ce9a
1820 files changed
+539344

No files matched your search

@@ -0,0 +1,62 @@
<?php
if ( !function_exists( 'Bing_archive_header' ) ) :
/**
* 存档页信息
*
* @see get_the_author_meta()
* @see get_author_feed_link()
*
* @see single_term_title()
* @see term_description()
* @see get_term_feed_link()
*
* @global object $authordata
*/
function Bing_archive_header(){
if( !is_archive() ) return;
if( is_author() ){
$dashicons = 'admin-users';
$name = $GLOBALS['authordata']->display_name;
$description = get_the_author_meta( 'description' );
$feed_link = get_author_feed_link( $GLOBALS['authordata']->ID );
}elseif( is_date() ){
$dashicons = 'calendar';
if( is_day() ) $format = __( 'Y年m月d日', 'Bing' );
elseif( is_month() ) $format = __( 'Y年m月', 'Bing' );
else $format = __( 'Y年', 'Bing' );
$name = get_the_date( $format );
$description = sprintf( __( '%s发布的文章', 'Bing' ), $name );
}elseif( is_post_type_archive() ){
$dashicons = 'clipboard';
$name = get_queried_object()->labels->name;
$description = get_queried_object()->description;
}else{
$dashicons = is_tag() ? 'tag' : 'category';
$name = single_term_title( '', false );
$description = term_description();
$feed_link = get_term_feed_link( get_queried_object_id(), get_queried_object()->taxonomy );
}
$description = strip_tags( $description );
?>
<div class="span12 archive-header">
<article class="panel">
<header class="panel-header">
<<?php echo Bing_get_page_title_tag(); ?> class="archive-title">
<span class="dashicons dashicons-<?php echo $dashicons; ?>"></span>
<?php echo $name; ?>
</<?php echo Bing_get_page_title_tag(); ?>>
<?php if ( Bing_mpanel( 'breadcrumbs' ) ) : ?>
<span class="right"><?php Bing_Breadcrumbs::output(); ?></span>
<?php endif; ?>
</header>
<?php
echo empty( $description ) ? __( '无描述', 'Bing' ) : $description;
if( !empty( $feed_link ) ) printf( '<a href="%s" title="%s" class="feed-link"><span class="dashicons dashicons-rss"></span></a>', esc_url( $feed_link ), esc_attr( __( '此存档的 Feed 源,可以使用 RSS 阅读器订阅这些内容', 'Bing' ) ) );
?>
</article>
</div>
<?php
}
endif;
//End of page.
@@ -0,0 +1,95 @@
<?php
/**
* 获取广告
*/
function Bing_banner( $banner ){
if (
( $hide_date = Bing_mpanel( $banner . '_hide_date' ) ) &&
strtotime( $hide_date ) > current_time( 'timestamp' )
)
return;
if( Bing_mpanel( $banner . '_type' ) == 'code' )
return Bing_mpanel( $banner . '_code' );
$url = esc_url( Bing_mpanel( $banner . '_img' ) );
$alt = esc_attr( Bing_mpanel( $banner . '_alt' ) );
$code = "<img src='$url' title='$alt' alt='$alt' />";
if( $url = Bing_mpanel( $banner . '_url' ) ){
$url_attr = esc_url( $url );
$tab = Bing_mpanel( $banner . '_tab' ) ? ' target="_blank"' : '';
$code = "<a href='$url_attr'$tab>$code</a>";
}
return $code;
}
/**
* 获取宽屏广告
*/
function Bing_banner_span12( $banner ){
$banner_id = 'banner_' . $banner;
if( !( $code = Bing_banner( $banner_id ) ) || !Bing_mpanel( $banner_id . '_show' ) )
return;
$classes = array(
'span12',
'banner',
'banner-type-' . Bing_mpanel( $banner_id . '_type' ),
$banner_id
);
if( Bing_mpanel( 'responsive' ) ){
$client = (array) Bing_mpanel( $banner_id . '_client' );
if( !in_array( 'pc', $client ) )
$classes[] = 'pc-hide';
if( !in_array( 'mobile', $client ) )
$classes[] = 'mobile-hide';
}
?>
<div class="row">
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
<div class="panel no-padding"><?php echo $code; ?></div>
</div>
</div>
<?php
}
/**
* 获取文章底部
*/
function Bing_banner_post_bottom(){
$banner_id = 'banner_post_bottom';
if( !( $code = Bing_banner( $banner_id ) ) || !Bing_mpanel( $banner_id . '_show' ) )
return;
$classes = array(
'span12',
'banner',
'banner-type-' . Bing_mpanel( $banner_id . '_type' ),
$banner_id
);
if( Bing_mpanel( 'responsive' ) ){
$client = (array) Bing_mpanel( $banner_id . '_client' );
if( !in_array( 'pc', $client ) )
$classes[] = 'pc-hide';
if( !in_array( 'mobile', $client ) )
$classes[] = 'mobile-hide';
}
?>
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
<div class="panel no-padding"><?php echo $code; ?></div>
</div>
<?php
}
//End of page.
@@ -0,0 +1,62 @@
<?php
if ( !function_exists( 'Bing_comments_list_loop' ) ) :
/**
* 评论列表样式
*/
function Bing_comments_list_loop( $comment, $args = null, $depth = 0 ){
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class( get_option( 'show_avatars' ) ? 'show-avatars' : '' ); ?>>
<article id="comment-box-<?php comment_ID(); ?>" class="comment-box">
<?php echo get_avatar( $comment, 42 ); ?>
<div class="right-box">
<p class="comment-meta">
<span class="author"><?php comment_author_link(); ?></span>
<time class="time" pubdate="pubdate"><?php comment_time( 'Y-m-d H:i:s' ); ?></time>
<?php
edit_comment_link( __( '编辑', 'Bing' ), '<span class="edit-link">', '</span>' );
if( !empty( $args ) ) comment_reply_link( wp_parse_args( $args, array(
'add_below' => 'comment-box',
'before' => ' <span class="reply">',
'after' => '</span>',
'reply_text' => __( '回复', 'Bing' ),
'depth' => $depth
) ) );
?>
</p>
<?php
comment_text();
if( $comment->comment_approved == '0' ) echo '<span class="waiting">' . __( '评论正在审核中...', 'Bing' ) . '</span>';
?>
</div>
</article>
<?php
}
endif;
if ( !function_exists( 'Bing_comments_list_loop_end' ) ) :
/**
* 评论列表样式(结尾)
*/
function Bing_comments_list_loop_end(){
echo '</li>';
}
endif;
/**
* 添加表情按钮
*/
function Bing_smiley_button(){
if( !get_option( 'use_smilies' ) ) return;
?>
<div class="comment-form-smiley no-js-hide">
<a href="javascript:;" title="<?php esc_attr_e( '插入表情', 'Bing' ); ?>" class="button">
<span class="dashicons dashicons-smiley"></span>
</a>
<div class="smiley-box"></div>
</div>
<?php
}
add_action( 'comment_form', 'Bing_smiley_button' );
//End of page.
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
@@ -0,0 +1,328 @@
<?php
if ( !function_exists( 'Bing_mobile_header' ) ) :
/**
* 移动版头部
*/
function Bing_mobile_header(){
$show_class = is_singular() && get_post_type() != 'page' ? ' show' : '';
?>
<div id="mobile-header">
<a href="javascript:history.go( -1 );" class="mobile-return<?php echo $show_class; ?>">
<span class="dashicons dashicons-arrow-left-alt2"></span><?php _e( '返回', 'Bing' ); ?>
</a>
<div class="mobile-title"><?php echo Bing_mobile_title(); ?></div>
</div>
<?php
}
endif;
if ( !function_exists( 'Bing_mobile_menu' ) ) :
/**
* 移动版菜单
*
* @since Unknown
* @since Beginning 4.0.2 增加对自定义关于页面的支持。
*/
function Bing_mobile_menu(){
$current = Bing_mobile_menu_current();
if ( Bing_mpanel( 'about_page' ) == 'custom' )
$about_url = get_permalink( (int) Bing_mpanel( 'custom_about_page' ) );
else
$about_url = add_query_arg( 'mobile_page', 'about', home_url() );
?>
<ul id="mobile-menu">
<li class="home<?php if( $current == 'home' || empty( $current ) ) echo ' current'; ?>" data-name="home">
<a href="<?php echo esc_url( home_url() ); ?>">
<span class="dashicons dashicons-admin-home"></span>
<?php _e( '首页', 'Bing' ); ?>
</a>
</li>
<li class="category<?php if( $current == 'category' ) echo ' current'; ?>" data-name="category">
<a href="<?php echo esc_url( add_query_arg( 'mobile_page', 'category', home_url() ) ); ?>">
<span class="dashicons dashicons-category"></span>
<?php _e( '分类', 'Bing' ); ?>
</a>
</li>
<li class="search<?php if( $current == 'search' ) echo ' current'; ?>" data-name="search">
<a href="<?php echo esc_url( home_url( '?s' ) ); ?>">
<span class="dashicons dashicons-search"></span>
<?php _e( '搜索', 'Bing' ); ?>
</a>
</li>
<li class="about<?php if( $current == 'about' ) echo ' current'; ?>" data-name="about">
<a href="<?php echo esc_url( $about_url ); ?>">
<span class="dashicons dashicons-info"></span>
<?php _e( '关于', 'Bing' ); ?>
</a>
</li>
</ul>
<?php
}
endif;
if ( !function_exists( 'Bing_mobile_tab_menu' ) ) :
/**
* 移动版 tab 菜单
*/
function Bing_mobile_tab_menu(){
$tabs = array(
'context' => array( 'name' => __( '内容', 'Bing' ), 'current' => true ),
'comments' => array( 'name' => __( '评论', 'Bing' ), 'disable' => post_password_required() || ( !comments_open() && get_comments_number() <= 0 ) ),
'related' => array( 'name' => __( '相关', 'Bing' ), 'disable' => !Bing_mpanel( 'related_posts' ) || get_post_type() != 'post' )
);
?>
<ul id="mobile-tab-menu" class="no-js-hide">
<?php
foreach( $tabs as $ID => $tab ):
$classes = array();
if( isset( $tab['current'] ) && $tab['current'] ) $classes[] = 'current';
if( isset( $tab['disable'] ) && $tab['disable'] ) $classes[] = 'disable';
?>
<li class="<?php echo implode( $classes, ' ' ); ?>" data-tab="<?php echo esc_attr( $ID ); ?>"><?php echo $tab['name']; ?></li>
<?php endforeach; ?>
</ul>
<?php
}
endif;
if ( !function_exists( 'Bing_mobile_menu_hot_searches' ) ) :
/**
* 移动版热门搜索
*/
function Bing_mobile_menu_hot_searches(){
if( !$tags = get_tags( 'orderby=count&order=DESC&number=10' ) )
return;
?>
<div class="span12 hot-searches">
<article class="panel center">
<header class="panel-header">
<<?php echo Bing_get_main_list_title_tag(); ?> class="hot-searches-title"><?php _e( '热门搜索', 'Bing' ); ?></<?php echo Bing_get_main_list_title_tag(); ?>>
</header>
<ul class="hot-searches-list">
<?php foreach( $tags as $tag ): ?>
<li>
<a href="<?php echo esc_url( get_search_link( $tag->name ) ); ?>"><?php echo $tag->name; ?></a>
</li>
<?php endforeach; ?>
</ul>
</article>
</div>
<?php
}
endif;
/**
* 获取移动版菜单当前页
*
* @since Unknown
* @since Beginning 4.0.5 增加对使用静态首页时的功能支持。
*/
function Bing_mobile_menu_current(){
if( is_search() )
return 'search';
if( is_archive() || Bing_is_mobile_page_category() )
return 'category';
if( Bing_is_mobile_page_about() )
return 'about';
if( is_home() || is_front_page() )
return 'home';
return '';
}
/**
* 获取移动版标题
*/
function Bing_mobile_title(){
if( is_category() || is_tag() || is_tax() )
return single_term_title( '', false );
if( is_search() )
return get_search_form( false );
if( is_author() )
return $GLOBALS['authordata']->display_name;
if( is_date() ){
if( is_day() )
$format = __( 'Y年m月d日', 'Bing' );
elseif( is_month() )
$format = __( 'Y年m月', 'Bing' );
else
$format = __( 'Y年', 'Bing' );
return get_the_date( $format );
}
if( is_404() )
return '404';
if( is_page() )
return get_the_title();
if( Bing_is_mobile_page_category() )
return __( '分类', 'Bing' );
if( Bing_is_mobile_page_about() )
return __( '关于', 'Bing' );
return get_bloginfo( 'name', 'display' );
}
if ( !function_exists( 'Bing_mobile_page_navi' ) ) :
/**
* 移动版分页导航
*/
function Bing_mobile_page_navi(){
if( !Bing_mpanel( 'ajax_load_page' ) )
return Bing_mobile_page_navi_button();
?>
<div class="span12 posts-list-mobile-page-navi" data-next-link="<?php echo get_next_posts_link() ? esc_url( get_next_posts_page_link() ) : ''; ?>">
<div class="panel">
<?php if( get_next_posts_link() ): ?>
<p class="help-text"><?php _e( '更多...', 'Bing' ); ?></p>
<p class="loading">
<span class="dashicons dashicons-image-rotate"></span>
<?php _e( '加载中...', 'Bing' ); ?>
</p>
<?php else: ?>
<p class="help-text"><?php _e( '全部加载完成', 'Bing' ); ?></p>
<?php endif; ?>
</div>
</div>
<?php
}
endif;
if ( !function_exists( 'Bing_mobile_page_navi_button' ) ) :
/**
* 移动版分页导航(按钮翻页)
*/
function Bing_mobile_page_navi_button(){
if( get_previous_posts_link() ):
?>
<a href="<?php echo esc_url( get_previous_posts_page_link() ); ?>" class="span12 posts-list-mobile-page-navi">
<div class="panel">
<p class="help-text"><?php _e( '上一页', 'Bing' ); ?></p>
</div>
</a>
<?php
endif;
if( get_next_posts_link() ):
?>
<a href="<?php echo esc_url( get_next_posts_page_link() ); ?>" class="span12 posts-list-mobile-page-navi">
<div class="panel">
<p class="help-text"><?php _e( '下一页', 'Bing' ); ?></p>
</div>
</a>
<?php
endif;
}
endif;
/**
* 判断移动版分类列表页
*
* @since Unknown
* @since Beginning 4.0.5 增加对使用静态首页时的功能支持。
*/
function Bing_is_mobile_page_category(){
return ( is_home() || is_front_page() ) && isset( $_GET['mobile_page'] ) && $_GET['mobile_page'] == 'category';
}
/**
* 使用移动版分类列表页
*/
function Bing_mobile_page_category( $template ){
if( !Bing_is_mobile_page_category() )
return $template;
get_header();
?>
<section id="container">
<div class="row">
<div class="span12">
<article class="panel no-padding">
<ul id="mobile-categories">
<?php
wp_list_categories( array(
'hide_empty' => 0,
'title_li' => '',
'orderby' => 'count',
'order' => 'DESC'
) );
?>
</ul>
</article>
</div>
</div>
</section>
<?php
get_footer();
return false;
}
add_filter( 'template_include', 'Bing_mobile_page_category', 16 );
/**
* 判断移动版关于页
*
* @since Unknown
* @since Beginning 4.0.2 增加对自定义页面的支持。
* @since Beginning 4.0.5 增加对使用静态首页时的功能支持。
*/
function Bing_is_mobile_page_about(){
if ( Bing_mpanel( 'about_page' ) == 'custom' )
return is_page( (int) Bing_mpanel( 'custom_about_page' ) );
else
return ( is_home() || is_front_page() ) && isset( $_GET['mobile_page'] ) && $_GET['mobile_page'] == 'about';
}
/**
* 使用移动版分类列表页
*
* @since Unknown
* @since Beginning 4.0.2 自定义页面时不会再替换模板。
*/
function Bing_mobile_page_about( $template ){
if( !Bing_is_mobile_page_about() || Bing_mpanel( 'about_page' ) == 'custom' )
return $template;
get_header();
?>
<section id="container">
<div class="row">
<div class="span12 mobile-about">
<article class="panel">
<header class="panel-header">
<<?php echo Bing_get_main_list_title_tag(); ?> class="about"><span class="dashicons dashicons-info"></span><?php _e( '关于', 'Bing' ); ?></<?php echo Bing_get_main_list_title_tag(); ?>>
</header>
<p><?php echo Bing_mpanel( 'footer_text_left' ); ?></p>
<p><?php echo Bing_mpanel( 'footer_text_right' ); ?></p>
</article>
</div>
</div>
</section>
<?php
get_footer();
return false;
}
add_filter( 'template_include', 'Bing_mobile_page_about', 16 );
/**
* AJAX 加载页面添加移动版信息
*/
function Bing_ajax_load_page_data_mobile( $data ){
return array_merge( $data, array(
'mobile_menu_current' => Bing_mobile_menu_current(),
'mobile_title' => Bing_mobile_title(),
'mobile_return_show' => is_singular() && get_post_type() != 'page'
) );
}
add_filter( 'ajax_load_page_data', 'Bing_ajax_load_page_data_mobile' );
//End of page.
@@ -0,0 +1,230 @@
<?php
if ( !function_exists( 'Bing_posts_list' ) ) :
/**
* 主文章列表
*/
function Bing_posts_list(){
if ( have_posts() ) :
echo '<ul class="posts-list' . ( Bing_mpanel( 'full_text' ) ? ' full-text' : '' ) . '">';
while ( have_posts() ) :
the_post();
Bing_posts_list_loop();
endwhile;
echo '</ul>';
Bing_page_navi( array(
'before' => '<div class="span12 posts-list-page-navi"><div class="panel page-navi">',
'after' => '</div></div>'
) );
Bing_mobile_page_navi();
else:
?>
<div class="empty-posts-list span12">
<article class="panel">
<?php
echo '<p>';
if ( is_home() ) {
_e( '这里什么都没有', 'Bing' );
echo '</p>';
} elseif( is_search() ) {
_e( '没有搜索到任何结果', 'Bing' );
echo '</p>';
} else {
_e( '这里什么都没有,你也许可以使用搜索功能找到你需要的内容:', 'Bing' );
echo '</p>';
get_search_form();
}
?>
</article>
</div>
<?php
endif;
}
endif;
if ( !function_exists( 'Bing_posts_list_loop' ) ) :
/**
* 主文章列表样式
*/
function Bing_posts_list_loop(){
$thumbnail_class = Bing_mpanel( 'thumbnail' ) ? 'thumbnail' : '';
?>
<li <?php post_class( array( 'span12', $thumbnail_class ) ); ?>>
<article class="panel">
<header class="panel-header">
<?php the_title( '<' . Bing_get_main_list_title_tag() . ' class="post-title"><a href="' . esc_url( get_permalink() ) . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></' . Bing_get_main_list_title_tag() . '>' ); ?>
</header>
<?php if ( Bing_mpanel( 'full_text' ) ) : ?>
<section class="context">
<?php the_content(); ?>
</section>
<?php else : ?>
<?php if( Bing_mpanel( 'thumbnail' ) ) echo Bing_thumbnail( 170, 120 ); ?>
<div class="right-box">
<p class="excerpt"><?php echo Bing_excerpt( 120 ); ?></p>
<?php Bing_post_meta(); ?>
</div>
<?php endif; ?>
</article>
</li>
<?php
}
endif;
if ( !function_exists( 'Bing_sidebar_posts_list' ) ) :
/**
* 边栏文章列表
*/
function Bing_sidebar_posts_list( $query_args, $thumbnail = true ){
$query = new WP_Query( $query_args );
if( $query->have_posts() ):
echo '<ul class="sidebar-posts-list">';
while( $query->have_posts() ):
$query->the_post();
Bing_sidebar_posts_list_loop( $thumbnail );
endwhile;
wp_reset_postdata();
echo '</ul>';
else:
?>
<div class="empty-sidebar-posts-list">
<p><?php _e( '这里什么都没有,你也许可以使用搜索功能找到你需要的内容:' ); ?></p>
<?php get_search_form(); ?>
</div>
<?php
endif;
}
endif;
if ( !function_exists( 'Bing_sidebar_posts_list_loop' ) ) :
/**
* 边栏文章列表样式
*/
function Bing_sidebar_posts_list_loop( $thumbnail = true ){
?>
<li <?php post_class( $thumbnail ? 'thumbnail' : '' ); ?>>
<?php if( $thumbnail ) echo Bing_thumbnail( 50 ); ?>
<div class="right-box">
<?php the_title( '<h4 class="post-title"><a href="' . esc_url( get_permalink() ) . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h4>' ); ?>
<?php Bing_post_meta( array( 'date-abb', 'views' ) ); ?>
</div>
</li>
<?php
}
endif;
if ( !function_exists( 'Bing_thumbnail' ) ) :
/**
* 文章缩略图
*/
function Bing_thumbnail( $width, $height = null, $link = true ) {
if ( empty( $height ) )
$height = $width;
$title_attribute = the_title_attribute( 'echo=0' );
$url = Bing_post_thumbnail_url();
if ( Bing_mpanel( 'crop_thumbnail' ) )
$url = Bing_crop_thumbnail( $url, $width, $height );
$code = sprintf(
'<img src="%s" class="thumbnail" width="%s" height="%s" title="%s" alt="%s" />',
esc_url( $url ),
esc_attr( $width ),
esc_attr( $height ),
$title_attribute,
$title_attribute
);
if ( $link )
$code = sprintf(
'<a href="%s" class="thumbnail-link" rel="bookmark" title="%s">%s</a>',
esc_url( get_permalink() ),
$title_attribute,
$code
);
return $code;
}
endif;
if ( !function_exists( 'Bing_post_meta' ) ) :
/**
* 文章信息
*/
function Bing_post_meta( $items = array( 'author', 'date', 'views' ) ){
$items = (array) $items;
if ( empty( $items ) )
return;
echo '<ul class="post-meta">';
foreach ( $items as $item ) :
switch ( $item ) {
case 'author' :
?>
<li class="author">
<span class="dashicons dashicons-admin-users"></span>
<?php the_author_posts_link(); ?>
</li>
<?php
break;
case 'date' :
?>
<li class="date">
<span class="dashicons dashicons-calendar"></span>
<a href="<?php echo esc_url( get_day_link( get_post_time( 'Y' ), get_post_time( 'm' ), get_post_time( 'd' ) ) ); ?>" title="<?php echo esc_attr( sprintf( __( '《%s》的发布日期', 'Bing' ), get_the_title() ) ); ?>">
<time pubdate="pubdate"><?php echo get_the_date(); ?></time>
</a>
</li>
<?php
break;
case 'date-abb' :
?>
<li class="date date-abb">
<span class="dashicons dashicons-calendar"></span>
<a href="<?php echo esc_url( get_day_link( get_post_time( 'Y' ), get_post_time( 'm' ), get_post_time( 'd' ) ) ); ?>" title="<?php echo esc_attr( get_the_date( __( '发布于Y年m月d日', 'Bing' ) ) ); ?>">
<time pubdate="pubdate"><?php echo get_the_date( 'm-d' ); ?></time>
</a>
</li>
<?php
break;
case 'views' :
if ( get_post_type() == 'page' )
break;
?>
<li class="views">
<span class="dashicons dashicons-visibility"></span>
<a href="javascript:;" title="<?php echo esc_attr( sprintf( __( '浏览了%s次', 'Bing' ), Bing_Views_Stats::get() ) ); ?>">
<?php echo Bing_Views_Stats::output(); ?>
</a>
</li>
<?php
break;
case 'comments' :
?>
<li class="comments">
<span class="dashicons dashicons-admin-comments"></span>
<?php comments_popup_link( __( '无评论', 'Bing' ), '1', '%', '', __( '已关闭评论', 'Bing' ) ); ?>
</li>
<?php
break;
case 'tags' :
the_tags( '<li class="tags no-js-hide" title="' . esc_attr__( '标签', 'Bing' ) . '"><span class="dashicons dashicons-tag"></span> <span class="tags-list">', ' ', '</span></li>' );
break;
}
endforeach;
echo '</ul>';
}
endif;
//End of page.
@@ -0,0 +1,154 @@
<?php
if ( !function_exists( 'Bing_related_posts' ) ) :
/**
* 相关文章
*/
function Bing_related_posts(){
if( !$related_posts_ID = Bing_related_posts_ID() )
return;
$query = new WP_Query( array(
'nopaging' => true,
'post__in' => $related_posts_ID,
'orderby' => 'rand',
'ignore_sticky_posts' => true
) );
if( !$query->have_posts() )
return;
?>
<div class="span12 related-posts-box<?php if ( Bing_mpanel( 'mobile_single_collapse' ) ) echo ' mobile-hide collapse'; ?>">
<div class="panel transparent no-padding related-posts-box-panel">
<header class="panel-header">
<h3>
<span class="dashicons dashicons-pressthis"></span>
<?php _e( '相关文章', 'Bing' ); ?>
</h3>
<span class="right">
<a href="javascript:;" class="refresh" data-post-id="<?php the_ID(); ?>" title="<?php esc_attr_e( '换一批新的相关文章', 'Bing' ); ?>">
<span class="dashicons dashicons-image-rotate"></span><?php _e( '刷新', 'Bing' ); ?>
</a>
</span>
</header>
<ul class="related-posts row">
<?php
while( $query->have_posts() ):
$query->the_post();
Bing_related_posts_loop();
endwhile;
?>
</ul>
</div>
</div>
<?php
wp_reset_postdata();
}
endif;
/**
* 获取相关文章
*/
function Bing_related_posts_ID( $post = null ){
$post = get_post( $post );
$number = Bing_mpanel( 'related_posts_number' );
$posts = array();
$exclude_ID = array( $post->ID );
if( $tags = get_the_tags( $post ) ){
$tags_ID = array();
foreach( $tags as $tag )
$tags_ID[] = $tag->term_id;
$posts = get_posts( array(
'tag__in' => $tags_ID,
'exclude' => $exclude_ID,
'orderby' => 'rand',
'fields' => 'ids',
'numberposts' => $number
) );
}
if( count( $posts ) < $number && $cats = get_the_category( $post ) ){
$cats_ID = array();
foreach( $cats as $cat )
$cats_ID[] = $cat->term_id;
$_posts = get_posts( array(
'category__in' => $cats_ID,
'exclude' => array_merge( $exclude_ID, $posts ),
'orderby' => 'rand',
'fields' => 'ids',
'numberposts' => $number - count( $posts )
) );
$posts = array_merge( $posts, $_posts );
}
if( count( $posts ) < $number ){
$_posts = get_posts( array(
'exclude' => array_merge( $exclude_ID, $posts ),
'orderby' => 'rand',
'fields' => 'ids',
'numberposts' => $number - count( $posts )
) );
$posts = array_merge( $posts, $_posts );
}
return $posts;
}
if ( !function_exists( 'Bing_related_posts_loop' ) ) :
/**
* 相关文章样式
*/
function Bing_related_posts_loop(){
?>
<li <?php post_class( 'span4' ); ?>>
<div class="panel transparent no-padding related-posts-panel">
<a href="<?php the_permalink(); ?>" class="thumbnail-link" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php echo Bing_thumbnail( 175, 80, false ); ?>
<div class="excerpt"><?php echo Bing_excerpt( 50 ); ?></div>
</a>
<div class="bottom-box">
<?php
the_title( '<h4 class="post-title"><a href="' . esc_url( get_permalink() ) . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h4>' );
Bing_post_meta( array( 'author', 'date-abb' ) );
?>
</div>
</div>
</li>
<?php
}
endif;
/**
* 相关文章刷新
*/
function Bing_related_posts_refresh(){
if( empty( $_REQUEST['post_id'] ) || get_post_status( $_REQUEST['post_id'] ) != 'publish' || !$related_posts_ID = Bing_related_posts_ID( $_REQUEST['post_id'] ) )
return;
$query = new WP_Query( array(
'nopaging' => true,
'post__in' => $related_posts_ID,
'orderby' => 'rand',
'ignore_sticky_posts' => true
) );
while( $query->have_posts() ){
$query->the_post();
Bing_related_posts_loop();
}
wp_reset_postdata();
wp_die();
}
add_action( 'wp_ajax_related_posts_refresh', 'Bing_related_posts_refresh' );
add_action( 'wp_ajax_nopriv_related_posts_refresh', 'Bing_related_posts_refresh' );
//End of page.
@@ -0,0 +1,101 @@
<?php
/**
* 文章存档简码
*
* @since Unknown
* @since Beginning 4.1.0 修复翻译函数没有添加 domain 的问题。
*/
function Bing_shortcode_archives() {
$query = new WP_Query( array(
'nopaging' => true,
'ignore_sticky_posts' => true,
'post_type' => 'post'
) );
if ( !$query->have_posts() )
return __( '没有文章。', 'Bing' );
$month = null;
$heading = Bing_get_main_list_title_tag();
$code = '';
while ( $query->have_posts() ) {
$query->the_post();
if ( ( $current_month = get_the_date( 'Y-m' ) ) != $month ) {
if ( $month )
$code .= '</ul>';
$month = $current_month;
$code .= "<$heading>$month</$heading><ul>";
}
$url_attr = esc_url( get_permalink() );
$day = get_the_date( 'd' );
$title = get_the_title();
$code .= "<li>$day - <a href='$url_attr'>$title</a></li>";
}
$code .= '</ul>';
wp_reset_postdata();
return $code;
}
add_shortcode( 'archives', 'Bing_shortcode_archives' );
/**
* 标签云简码
*/
function Bing_shortcode_tags() {
return wp_tag_cloud( 'echo=0&number=0' );
}
add_shortcode( 'tags', 'Bing_shortcode_tags' );
/**
* 友情链接简码
*
* @since Beginning 4.1.0
*/
function Bing_shortcode_links( $atts, $content, $shortcode ) {
$pairs = array( 'menu' => null );
$atts = shortcode_atts( $pairs, $atts, $shortcode );
if ( !$items = wp_get_nav_menu_items( $atts['menu'] ) )
return __( '没有找到友情链接。', 'Bing' );
$code = '<ul class="links-list row">';
foreach ( $items as $item ) {
$name = get_the_title( $item );
$link = $item->url;
$domain = parse_url( $link, PHP_URL_HOST );
$icon = Bing_get_website_favicon( $domain );
$title = '<img class="link-favicon" src="' . esc_url( $icon ) . '" />';
$title .= '<span class="link-name">' . $name . '</span>';
$title = '<header class="link-title">' . $title . '</header>';
if ( empty( $item->post_content ) )
$description = '';
else
$description = '<span class="link-description">' . $item->post_content . '</span>';
$atts = Bing_render_attributes( array_filter( array(
'href' => $link,
'class' => 'link-box',
'title' => $item->attr_title,
'target' => $item->target,
'rel' => $item->xfn
) ) );
$code .= "<li class='span4'><a{$atts}>{$title}{$description}</a></li>";
}
$code .= '</ul>';
return $code;
}
add_shortcode( 'links', 'Bing_shortcode_links' );
// End of page.
@@ -0,0 +1,87 @@
<?php
if ( !function_exists( 'Bing_slider' ) ) :
/**
* 获取幻灯片
*/
function Bing_slider(){
if( !Bing_mpanel( 'slider_home' ) )
return;
$query = Bing_slider_query();
if( !$query->have_posts() )
return;
$items = Bing_mpanel( 'slider_home_page_items_number' );
$excerpt_length = round( 80 / $items );
$thumbnail_width = round( 720 / $items );
$thumbnail_height = Bing_mpanel( 'slider_home_height' );
$args = array(
'items' => $items,
'loop' => Bing_mpanel( 'slider_home_loop' ),
'smartSpeed' => Bing_mpanel( 'slider_home_switch_speed' )
);
if( Bing_mpanel( 'slider_home_dots' ) ){
$args['dots'] = true;
$args['dotsClass'] = 'slider-dots';
$args['dotClass'] = 'dot';
}
if( Bing_mpanel( 'slider_home_auto_play' ) ){
$args['autoplay'] = true;
$args['autoplayTimeout'] = Bing_mpanel( 'slider_home_auto_play_speed' ) * 1000;
}
?>
<div class="span12">
<div class="panel transparent no-padding slider no-js-hide owl-carousel" data-owl-carousel="<?php echo esc_attr( wp_json_encode( $args ) ); ?>">
<?php
while( $query->have_posts() ):
$query->the_post();
?>
<article <?php post_class(); ?>>
<?php echo Bing_thumbnail( $thumbnail_width, $thumbnail_height ); ?>
<a href="<?php the_permalink(); ?>" class="slider-text" rel="bookmark">
<?php the_title( '<' . Bing_get_main_list_title_tag() . ' class="post-title">', '</' . Bing_get_main_list_title_tag() . '>' ); ?>
<p class="excerpt"><?php echo Bing_excerpt( $excerpt_length ); ?></p>
</a>
</article>
<?php endwhile; ?>
</div>
</div>
<?php
}
endif;
/**
* 获取幻灯片内容查询
*/
function Bing_slider_query(){
$query_args = array(
'posts_per_page' => Bing_mpanel( 'slider_home_number' ),
'ignore_sticky_posts' => true
);
switch( $query = Bing_mpanel( 'slider_home_query' ) ){
case 'sticky':
$query_args['post__in'] = get_option( 'sticky_posts' );
break;
case 'rand':
case 'comment_count':
$query_args['orderby'] = $query;
break;
case 'view_count':
$query_args['orderby'] = 'meta_value_num';
$query_args['meta_key'] = 'views';
break;
case 'category':
$query_args['category__in'] = Bing_mpanel( 'slider_home_query_categories' );
break;
}
return new WP_Query( $query_args );
}
//End of page.
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
@@ -0,0 +1,72 @@
<?php
/**
* 小工具:广告
*/
class Bing_widget_banner extends WP_Widget{
//默认设置
public $default_instance = array();
//初始化
function __construct(){
parent::__construct(
'banner',
THEME_WIDGET_PREFIX . __( '广告', 'Bing' ),
array( 'description' => __( '自定义广告代码', 'Bing' ) )
);
$this->default_instance = array(
'title' => __( '广告', 'Bing' ),
'code' => ''
);
}
//小工具内容
function widget( $args, $instance ){
if( empty( $instance ) ) $instance = $this->default_instance;
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
echo $args['before_widget'];
if( !empty( $title ) ) echo $args['before_title'] . $title . $args['after_title'];
echo $instance['code'];
echo $args['after_widget'];
}
//保存设置选项
function update( $new_instance, $old_instance ){
$instance = array();
//标题
$instance['title'] = strip_tags( $new_instance['title'] );
//广告代码
$instance['code'] = force_balance_tags( $new_instance['code'] );
$instance['code'] = do_shortcode( $instance['code'] );
return $instance;
}
//设置表单
function form( $instance ){
$instance = wp_parse_args( $instance, $this->default_instance );
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( '标题:', 'Bing' ); ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>"><?php _e( '广告代码:', 'Bing' ); ?></label>
<textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'code' ) ); ?>" rows="10"><?php echo esc_attr( $instance['code'] ); ?></textarea>
</p>
<?php if( !empty( $instance['code'] ) ): ?>
<p><?php _e( '广告预览:', 'Bing' ); ?></p>
<div style="margin: 13px 0; overflow: hidden;">
<?php echo $instance['code']; ?>
<div class="clear: both;"></div>
</div>
<?php endif; ?>
<?php
}
}
register_widget( 'Bing_widget_banner' );
//End of page.
@@ -0,0 +1,212 @@
<?php
/**
* 小工具:文章
*/
class Bing_widget_posts_list extends WP_Widget{
//默认设置
public $default_instance = array();
//初始化
function __construct(){
parent::__construct(
'posts_list',
THEME_WIDGET_PREFIX . __( '文章', 'Bing' ),
array( 'description' => __( '根据设置可以显示不同的文章', 'Bing' ) )
);
$this->default_instance = array(
'title' => __( '文章', 'Bing' ),
'orderby' => 'date',
'descending' => true,
'number' => 5,
'thumbnail' => true,
'date_limit' => 'unlimited',
'exclude_posts' => array(),
'exclude_tax' => array()
);
}
//小工具内容
function widget( $args, $instance ){
if( empty( $instance ) ) $instance = $this->default_instance;
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
echo $args['before_widget'];
if( !empty( $title ) ) echo $args['before_title'] . $title . $args['after_title'];
$query_args = array(
'ignore_sticky_posts' => true,
'orderby' => $instance['orderby'],
'order' => $instance['descending'] ? 'DESC' : 'ASC',
'posts_per_page' => $instance['number'],
'post__not_in' => $instance['exclude_posts']
);
if( $query_args['orderby'] == 'views' ){
$query_args['meta_key'] = 'views';
$query_args['orderby'] = 'meta_value_num';
}
if( $instance['date_limit'] != 'unlimited' ) $query_args['date_query'] = array( 'after' => $instance['date_limit'] );
if( !empty( $instance['exclude_tax'] ) ){
$query_args['tax_query'] = array( 'relation' => 'AND' );
foreach( $instance['exclude_tax'] as $tax => $term ) $query_args['tax_query'][] = array(
'taxonomy' => $tax,
'field' => 'id',
'terms' => $term,
'operator' => 'NOT IN'
);
}
Bing_sidebar_posts_list( $query_args, $instance['thumbnail'] );
echo $args['after_widget'];
}
//保存设置选项
function update( $new_instance, $old_instance ){
$instance = array();
//标题
$instance['title'] = strip_tags( $new_instance['title'] );
//文章排序
$all_orderby = array( 'date', 'comment_count', 'views', 'rand' );
$instance['orderby'] = in_array( $new_instance['orderby'], $all_orderby ) ? $new_instance['orderby'] : 'date';
//倒序排列
$instance['descending'] = !empty( $new_instance['descending'] );
//文章数量
$instance['number'] = absint( $new_instance['number'] );
if( $instance['number'] === 0 ) $instance['number'] = 1;
//显示缩略图
$instance['thumbnail'] = !empty( $new_instance['thumbnail'] );
//日期限制
$all_date_limit = array(
'unlimited',
'1 day ago',
'3 day ago',
'1 week ago',
'1 month ago',
'3 month ago',
'6 month ago',
'1 year ago',
'2 year ago',
'3 year ago'
);
$instance['date_limit'] = in_array( $new_instance['date_limit'], $all_date_limit ) ? $new_instance['date_limit'] : 'unlimited';
//排除文章
$instance['exclude_posts'] = array_map( 'absint', (array) $new_instance['exclude_posts'] );
if( !empty( $instance['exclude_posts'] ) ) $instance['exclude_posts'] = get_posts( array(
'post__in' => $instance['exclude_posts'],
'nopaging' => true,
'post_type' => 'post',
'post_status' => array( 'publish', 'future' ),
'fields' => 'ids',
'update_post_meta_cache' => false,
'update_post_term_cache' => false
) );
//排除分类法
$instance['exclude_tax'] = (array) $new_instance['exclude_tax'];
foreach( $instance['exclude_tax'] as $tax_name => $tax ){
if( !taxonomy_exists( $tax_name ) || !is_array( $tax ) || empty( $tax ) ){
unset( $instance['exclude_tax'][$tax_name] );
continue;
}
$instance['exclude_tax'][$tax_name] = (array) $instance['exclude_tax'][$tax_name];
foreach( $instance['exclude_tax'][$tax_name] as $key => $term_id ){
$instance['exclude_tax'][$tax_name][$key] = absint( $term_id );
if( !term_exists( $instance['exclude_tax'][$tax_name][$key], $tax_name ) ) unset( $instance['exclude_tax'][$tax_name][$key] );
}
if( empty( $instance['exclude_tax'][$tax_name] ) ) unset( $instance['exclude_tax'][$tax_name] );
}
return $instance;
}
//设置表单
function form( $instance ){
$instance = wp_parse_args( $instance, $this->default_instance );
$orderby = array(
'date' => __( '发布时间', 'Bing' ),
'comment_count' => __( '评论数量', 'Bing' ),
'views' => __( '浏览次数', 'Bing' ),
'rand' => __( '随机排列', 'Bing' )
);
$date_limit = array(
'unlimited' => __( '无限制', 'Bing' ),
'1 day ago' => __( '一天之内', 'Bing' ),
'3 day ago' => __( '三天之内', 'Bing' ),
'1 week ago' => __( '一周之内', 'Bing' ),
'1 month ago' => __( '一个月之内', 'Bing' ),
'3 month ago' => __( '三个月之内', 'Bing' ),
'6 month ago' => __( '半年之内', 'Bing' ),
'1 year ago' => __( '一年之内', 'Bing' ),
'2 year ago' => __( '两年之内', 'Bing' ),
'3 year ago' => __( '三年之内', 'Bing' )
);
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( '标题:', 'Bing' ); ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"><?php _e( '文章排序:', 'Bing' ); ?></label>
<select id="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'orderby' ) ); ?>">
<?php foreach( $orderby as $orderby_name => $orderby_title ): ?>
<option value="<?php echo $orderby_name; ?>"<?php selected( $instance['orderby'], $orderby_name ); ?>><?php echo $orderby_title; ?></option>
<?php endforeach; ?>
</select>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'descending' ) ); ?>"><?php _e( '倒序排列:', 'Bing' ); ?></label>
<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'descending' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'descending' ) ); ?>" value="1"<?php checked( $instance['descending'] ); ?> />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( '文章数量:', 'Bing' ); ?></label>
<input type="number" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" value="<?php echo $instance['number']; ?>" />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'thumbnail' ) ); ?>"><?php _e( '显示缩略图:', 'Bing' ); ?></label>
<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'thumbnail' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'thumbnail' ) ); ?>" value="1"<?php checked( $instance['thumbnail'] ); ?> />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'date_limit' ) ); ?>"><?php _e( '日期限制:', 'Bing' ); ?></label>
<select id="<?php echo esc_attr( $this->get_field_id( 'date_limit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'date_limit' ) ); ?>">
<?php foreach( $date_limit as $date_code => $date_title ): ?>
<option value="<?php echo $date_code; ?>"<?php selected( $instance['date_limit'], $date_code ); ?>><?php echo $date_title; ?></option>
<?php endforeach; ?>
</select>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'exclude_posts' ) ); ?>"><?php _e( '排除文章:', 'Bing' ); ?></label>
<select class="widefat" multiple="multiple" id="<?php echo esc_attr( $this->get_field_id( 'exclude_posts' ) ); ?>[]" name="<?php echo esc_attr( $this->get_field_name( 'exclude_posts' ) ); ?>[]">
<?php foreach( get_posts( 'nopaging=1&post_status=publish,future' ) as $post ): ?>
<option value="<?php echo esc_attr( $post->ID ); ?>"<?php if( in_array( $post->ID, $instance['exclude_posts'] ) ) echo ' selected="selected"'; ?>><?php echo get_the_title( $post ); ?></option>
<?php endforeach; ?>
</select>
</p>
<?php
foreach( get_taxonomies( array( 'show_tagcloud' => true ), false ) as $tax_name => $tax ):
if ( empty( $tax->labels->name ) || !in_array( 'post', $tax->object_type ) ) continue;
$trems = get_terms( $tax_name, 'hide_empty=0' );
if( is_wp_error( $trems ) ) continue;
if( empty( $instance['exclude_tax'][$tax_name] ) ) $instance['exclude_tax'][$tax_name] = array();
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'exclude_tax' ) ) . "[$tax_name]"; ?>"><?php printf( __( '排除%s:', 'Bing' ), $tax->labels->name ); ?></label>
<select class="widefat" multiple="multiple" id="<?php echo esc_attr( $this->get_field_id( 'exclude_tax' ) ) . "[$tax_name]"; ?>[]" name="<?php echo esc_attr( $this->get_field_name( 'exclude_tax' ) . "[$tax_name]" ); ?>[]">
<?php foreach( $trems as $trem ): ?>
<option value="<?php echo esc_attr( $trem->term_id ); ?>"<?php if( in_array( $trem->term_id, $instance['exclude_tax'][$tax_name] ) ) echo ' selected="selected"'; ?>><?php echo $trem->name; ?></option>
<?php endforeach; ?>
</select>
</p>
<?php endforeach; ?>
<?php
}
}
register_widget( 'Bing_widget_posts_list' );
//End of page.
@@ -0,0 +1,202 @@
<?php
/**
* 小工具:评论
*/
class Bing_widget_recent_comments extends WP_Widget{
//默认设置
public $default_instance = array();
//初始化
function __construct(){
parent::__construct(
'recent_comments',
THEME_WIDGET_PREFIX . __( '评论', 'Bing' ),
array( 'description' => __( '根据设置可以显示不同的评论', 'Bing' ) )
);
$this->default_instance = array(
'title' => __( '评论', 'Bing' ),
'number' => 5,
'exclude_users' => array(),
'exclude_administrator' => false,
'exclude_posts' => array(),
'descending' => true,
'date_limit' => 'unlimited'
);
}
//小工具内容
function widget( $args, $instance ){
if( empty( $instance ) ) $instance = $this->default_instance;
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
echo $args['before_widget'];
if( !empty( $title ) ) echo $args['before_title'] . $title . $args['after_title'];
$exclude_users = $instance['exclude_users'];
if( $instance['exclude_administrator'] ){
$administrator_ids = array_map( 'absint', get_users( 'fields=ids&role=administrator' ) );
$exclude_users = array_unique( array_merge( $instance['exclude_users'], $administrator_ids ) );
}
$date_query = $instance['date_limit'] == 'unlimited' ? null : array( 'after' => $instance['date_limit'] );
$comments = get_comments( array(
'number' => $instance['number'],
'author__not_in' => $exclude_users,
'post__not_in' => $instance['exclude_posts'],
'order' => $instance['descending'] ? 'DESC' : 'ASC',
'date_query' => $date_query,
'status' => 'approve',
'type' => 'comment'
) );
if( empty( $comments ) ):
?>
<div class="empty-recent-comments">
<p><?php _e( '什么评论都没有,赶紧去发表你的意见吧!' ); ?></p>
</div>
<?php
else:
$show_avatars = get_option( 'show_avatars' ) ? ' show-avatars' : '';
echo '<ul class="sidebar-comments-list' . $show_avatars . '">';
foreach( $comments as $comment ):
$a_title = sprintf( __( '发表在《%s》', 'Bing' ), get_the_title( $comment->comment_post_ID ) );
?>
<li>
<a href="<?php echo esc_url( get_comment_link( $comment ) ); ?>" title="<?php echo esc_attr( $a_title ); ?>">
<?php echo get_avatar( $comment, 36 ); ?>
<div class="right-box">
<span class="author"><?php echo get_comment_author( $comment ); ?></span>
<p class="comment-text"><?php echo htmlspecialchars( get_comment_text( $comment ) ); ?></p>
</div>
</a>
</li>
<?php
endforeach;
echo '</ul>';
endif;
echo $args['after_widget'];
}
//保存设置选项
function update( $new_instance, $old_instance ){
$instance = array();
//标题
$instance['title'] = strip_tags( $new_instance['title'] );
//评论数量
$instance['number'] = absint( $new_instance['number'] );
if( $instance['number'] === 0 ) $instance['number'] = 1;
//排除用户
$instance['exclude_users'] = array_map( 'absint', (array) $new_instance['exclude_users'] );
if( !empty( $instance['exclude_users'] ) ){
$instance['exclude_users'] = get_users( array(
'include' => $instance['exclude_users'],
'fields' => 'ids'
) );
$instance['exclude_users'] = array_map( 'absint', $instance['exclude_users'] );
}
//排除所有管理员
$instance['exclude_administrator'] = !empty( $new_instance['exclude_administrator'] );
//排除文章
$instance['exclude_posts'] = array_map( 'absint', (array) $new_instance['exclude_posts'] );
if( !empty( $instance['exclude_posts'] ) ) $instance['exclude_posts'] = get_posts( array(
'post__in' => $instance['exclude_posts'],
'nopaging' => true,
'post_type' => 'post',
'post_status' => array( 'publish', 'future' ),
'fields' => 'ids',
'update_post_meta_cache' => false,
'update_post_term_cache' => false
) );
//倒序排列
$instance['descending'] = !empty( $new_instance['descending'] );
//日期限制
$all_date_limit = array(
'unlimited',
'1 day ago',
'3 day ago',
'1 week ago',
'1 month ago',
'3 month ago',
'6 month ago',
'1 year ago',
'2 year ago',
'3 year ago'
);
$instance['date_limit'] = in_array( $new_instance['date_limit'], $all_date_limit ) ? $new_instance['date_limit'] : 'unlimited';
return $instance;
}
//设置表单
function form( $instance ){
$instance = wp_parse_args( $instance, $this->default_instance );
$users = get_users( array(
'orderby' => 'registered',
'fields' => array( 'ID', 'display_name' )
) );
$date_limit = array(
'unlimited' => __( '无限制', 'Bing' ),
'1 day ago' => __( '一天之内', 'Bing' ),
'3 day ago' => __( '三天之内', 'Bing' ),
'1 week ago' => __( '一周之内', 'Bing' ),
'1 month ago' => __( '一个月之内', 'Bing' ),
'3 month ago' => __( '三个月之内', 'Bing' ),
'6 month ago' => __( '半年之内', 'Bing' ),
'1 year ago' => __( '一年之内', 'Bing' ),
'2 year ago' => __( '两年之内', 'Bing' ),
'3 year ago' => __( '三年之内', 'Bing' )
);
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( '标题:', 'Bing' ); ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( '评论数量:', 'Bing' ); ?></label>
<input type="number" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" value="<?php echo $instance['number']; ?>" />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'exclude_users' ) ); ?>"><?php _e( '排除用户:', 'Bing' ); ?></label>
<select class="widefat" multiple="multiple" id="<?php echo esc_attr( $this->get_field_id( 'exclude_users' ) ); ?>[]" name="<?php echo esc_attr( $this->get_field_name( 'exclude_users' ) ); ?>[]">
<?php foreach( $users as $user ): ?>
<option value="<?php echo esc_attr( $user->ID ); ?>"<?php if( in_array( $user->ID, $instance['exclude_users'] ) ) echo ' selected="selected"'; ?>><?php echo $user->display_name; ?></option>
<?php endforeach; ?>
</select>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'exclude_administrator' ) ); ?>"><?php _e( '排除所有管理员:', 'Bing' ); ?></label>
<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'exclude_administrator' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'exclude_administrator' ) ); ?>" value="1"<?php checked( $instance['exclude_administrator'] ); ?> />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'exclude_posts' ) ); ?>"><?php _e( '排除文章:', 'Bing' ); ?></label>
<select class="widefat" multiple="multiple" id="<?php echo esc_attr( $this->get_field_id( 'exclude_posts' ) ); ?>[]" name="<?php echo esc_attr( $this->get_field_name( 'exclude_posts' ) ); ?>[]">
<?php foreach( get_posts( 'nopaging=1&post_status=publish,future' ) as $post ): ?>
<option value="<?php echo esc_attr( $post->ID ); ?>"<?php if( in_array( $post->ID, $instance['exclude_posts'] ) ) echo ' selected="selected"'; ?>><?php echo get_the_title( $post ); ?></option>
<?php endforeach; ?>
</select>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'descending' ) ); ?>"><?php _e( '倒序排列:', 'Bing' ); ?></label>
<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'descending' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'descending' ) ); ?>" value="1"<?php checked( $instance['descending'] ); ?> />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'date_limit' ) ); ?>"><?php _e( '日期限制:', 'Bing' ); ?></label>
<select id="<?php echo esc_attr( $this->get_field_id( 'date_limit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'date_limit' ) ); ?>">
<?php foreach( $date_limit as $date_code => $date_title ): ?>
<option value="<?php echo $date_code; ?>"<?php selected( $instance['date_limit'], $date_code ); ?>><?php echo $date_title; ?></option>
<?php endforeach; ?>
</select>
</p>
<?php
}
}
register_widget( 'Bing_widget_recent_comments' );
//End of page.
@@ -0,0 +1,135 @@
<?php
/**
* 小工具:标签云
*/
class Bing_widget_tag_cloud extends WP_Widget{
//默认设置
public $default_instance = array();
//初始化
function __construct(){
parent::__construct(
'tag_cloud',
THEME_WIDGET_PREFIX . __( '标签云', 'Bing' ),
array( 'description' => __( '显示任意分类法的条款', 'Bing' ) )
);
$this->default_instance = array(
'title' => __( '标签云', 'Bing' ),
'number' => 45,
'taxonomy' => 'post_tag',
'orderby' => 'name',
'order' => 'DESC'
);
}
//小工具内容
function widget( $args, $instance ){
if( empty( $instance ) ) $instance = $this->default_instance;
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
echo $args['before_widget'];
if( !empty( $title ) ) echo $args['before_title'] . $title . $args['after_title'];
ob_start();
wp_tag_cloud( array(
'taxonomy' => $this->_get_current_taxonomy( $instance ),
'number' => $instance['number'],
'unit' => 'px',
'smallest' => 12,
'largest' => 12,
'orderby' => $instance['orderby'],
'order' => $instance['order']
) );
$tag_cloud_code = ob_get_clean();
echo empty( $tag_cloud_code ) ? '<p>' . __( '什么标签都没有,赶紧去创建吧!' ) . '</p>' : '<div class="list-box">' . $tag_cloud_code . '</div>';
echo $args['after_widget'];
}
//保存设置选项
function update( $new_instance, $old_instance ){
$instance = array();
//标题
$instance['title'] = strip_tags( $new_instance['title'] );
//标签数量
$instance['number'] = absint( $new_instance['number'] );
//分类法
$instance['taxonomy'] = $this->_get_current_taxonomy( $new_instance );
//标签排序
$all_orderby = array( 'name', 'count' );
$instance['orderby'] = in_array( $new_instance['orderby'], $all_orderby ) ? $new_instance['orderby'] : 'name';
//排序规则
$all_order = array( 'ASC', 'DESC', 'RAND' );
$instance['order'] = in_array( $new_instance['order'], $all_order ) ? $new_instance['order'] : 'DESC';
return $instance;
}
//设置表单
function form( $instance ){
$instance = wp_parse_args( $instance, $this->default_instance );
$taxonomy = $this->_get_current_taxonomy( $instance );
$orderby = array(
'name' => __( '标签名称', 'Bing' ),
'count' => __( '文章数量', 'Bing' )
);
$order = array(
'ASC' => __( '正序排列', 'Bing' ),
'DESC' => __( '倒序排列', 'Bing' ),
'RAND' => __( '随机排列', 'Bing' )
);
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( '标题:', 'Bing' ); ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</p>
<p title="<?php esc_attr_e( '设置为 0 则全部显示', 'Bing' ); ?>">
<label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( '标签数量:', 'Bing' ); ?></label>
<input type="number" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" value="<?php echo $instance['number']; ?>" />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>"><?php _e( '分类法:', 'Bing' ); ?></label>
<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'taxonomy' ) ); ?>">
<?php
foreach( get_taxonomies( array( 'show_tagcloud' => true ), false ) as $tax ):
if ( empty( $tax->labels->name ) ) continue;
?>
<option value="<?php echo esc_attr( $tax->name ); ?>"<?php selected( $taxonomy, $tax->name ); ?>><?php echo $tax->labels->name; ?></option>
<?php endforeach; ?>
</select>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"><?php _e( '标签排序:', 'Bing' ); ?></label>
<select id="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'orderby' ) ); ?>">
<?php foreach( $orderby as $orderby_name => $orderby_title ): ?>
<option value="<?php echo $orderby_name; ?>"<?php selected( $instance['orderby'], $orderby_name ); ?>><?php echo $orderby_title; ?></option>
<?php endforeach; ?>
</select>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"><?php _e( '排序规则:', 'Bing' ); ?></label>
<select id="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'order' ) ); ?>">
<?php foreach( $order as $order_name => $order_title ): ?>
<option value="<?php echo $order_name; ?>"<?php selected( $instance['order'], $order_name ); ?>><?php echo $order_title; ?></option>
<?php endforeach; ?>
</select>
</p>
<?php
}
//获取当前分类法
function _get_current_taxonomy( $instance ){
$taxonomy = stripslashes( $instance['taxonomy'] );
return !empty( $taxonomy ) && taxonomy_exists( $taxonomy ) ? $taxonomy : 'post_tag';
}
}
register_widget( 'Bing_widget_tag_cloud' );
//End of page.