get( 'ThemeURI' ) );
define( 'THEME_DIR', get_template_directory() );
define( 'THEME_URL', get_template_directory_uri() );
define( 'THEME_VER', wp_get_theme()->get( 'Version' ) );
define( 'STATIC_DIR', THEME_DIR . '/static' );
define( 'STATIC_URL', THEME_URL . '/static' );
define( 'AJAX_URL', admin_url( 'admin-ajax.php' ) );
load_theme_textdomain( THEME_NAME, __DIR__ . '/languages/' );
/* customize */
$anice_defaults = array(
// global.
'site_icon' => STATIC_URL . '/images/icon.ico',
'theme_color' => '#0099FF #007bff #99CCFF',
'static_lib_cdn' => '',
'page_width' => '1200px',
'enable_back_to_top' => false,
'service_qq' => '',
// header.
'site_logo' => STATIC_URL . '/images/logo.png',
'show_search' => true,
'show_login_button' => true,
// footer.
'delete_theme_copyright' => false,
'icp_number' => '',
// slides.
'enable_slides' => true,
'slides_image_1' => STATIC_URL . '/images/anice_slide_1.jpg',
'slides_url_1' => 'https://www.xenice.com',
'slides_title_1' => __( 'OneNice Theme', 'anice' ),
'slides_description_1' => __( 'OneNice is a super concise WordPress theme, supporting both Chinese and English, free open source, no encryption, no redundant code, no authorization restrictions, can be used freely.', 'anice' ),
'slides_image_2' => STATIC_URL . '/images/anice_slide_2.jpg',
'slides_url_2' => 'https://www.xenice.com',
'slides_title_2' => __( 'OneNice Theme', 'anice' ),
'slides_description_2' => __( 'OneNice is a super concise WordPress theme, supporting both Chinese and English, free open source, no encryption, no redundant code, no authorization restrictions, can be used freely.', 'anice' ),
'slides_image_3' => STATIC_URL . '/images/anice_slide_3.jpg',
'slides_url_3' => 'https://www.xenice.com',
'slides_title_3' => __( 'OneNice Theme', 'anice' ),
'slides_description_3' => __( 'OneNice is a super concise WordPress theme, supporting both Chinese and English, free open source, no encryption, no redundant code, no authorization restrictions, can be used freely.', 'anice' ),
// archive.
'list_style' => 'text',
'excerpt_length' => 50,
'site_thumbnail' => STATIC_URL . '/images/thumbnail.png',
'site_loading_image' => STATIC_URL . '/images/loading.png',
'archive_show_date' => true,
'archive_show_author' => true,
// posts.
'single_show_date' => true,
'single_show_author' => true,
'single_show_tags' => true,
'single_show_previous_next' => true,
'show_related_posts' => true,
'single_show_share' => false,
'single_disable_share_buttons' => 'weibo,wechat,qq,douban,qzone,tencent,linkedin,diandian,google,twitter,facebook',
'single_enable_highlight' => false,
);
/**
* Get option
*
* @param string $name option name.
*/
function anice_get( $name ) {
global $anice_defaults;
return get_theme_mod( $name, $anice_defaults[ $name ] );
}
/**
* Register customize options
*
* @param object $wp_customize wp customize object.
*/
function anice_customize( $wp_customize ) {
require __DIR__ . '/includes/class-anice-options.php';
new Anice_Options( $wp_customize );
}
add_action( 'customize_register', 'anice_customize' );
/**
* Breadcrumb
*
* @return string Output breadcrumb html.
*/
function anice_breadcrumb() {
/**
* Get breadcrumb
*
* @param int $cid Category id.
* @param string $taxonomy Category taxonomy name.
* @return string Return the breadcrumb html.
*/
function anice_get_greadcrumb( $cid, $taxonomy ) {
if ( is_date() ) {
echo '' . esc_html( get_the_date() ) . '';
return;
}
if ( is_author() ) {
echo '' . esc_html( get_the_author() ) . '';
return;
}
$row = get_term( $cid, $taxonomy );
$pid = $row->parent;
if ( $pid ) {
anice_get_greadcrumb( $pid );
}
echo '' . esc_html( $row->name ) . '';
}
if ( is_single() ) {
global $post;
global $wpdb;
$cats = wp_get_post_categories( $post->ID );
echo '' . esc_html__( 'Home', 'anice' ) . '';
$cid = $cats[0];
if ( $cid ) {
$taxonomy = wp_cache_get( 'taxonomy_' . $cid, 'anice_cache_group' );
if ( false === $taxonomy ) {
$taxonomy = $wpdb->get_var( $wpdb->prepare( "SELECT taxonomy FROM {$wpdb->term_taxonomy} WHERE term_id=%d", $cid ) );
wp_cache_set( 'taxonomy_' . $cid, $taxonomy, 'anice_cache_group' );
}
anice_get_greadcrumb( $cid, $taxonomy );
}
echo '' . esc_html( $post->post_title ) . '';
return;
} elseif ( is_archive() ) {
global $wpdb;
$cid = get_queried_object_id();
$taxonomy = wp_cache_get( 'taxonomy_' . $cid, 'anice_cache_group' );
if ( false === $taxonomy ) {
$taxonomy = $wpdb->get_var( $wpdb->prepare( "SELECT taxonomy FROM {$wpdb->term_taxonomy} WHERE term_id=%d", $cid ) );
wp_cache_set( 'taxonomy_' . $cid, $taxonomy, 'anice_cache_group' );
}
echo '' . esc_html__( 'Home', 'anice' ) . '';
anice_get_greadcrumb( $cid, $taxonomy );
}
}
/**
* Login
*/
function anice_login() {
global $current_user;
$user = $current_user->data;
echo '
';
if ( isset( $user->ID ) ) {
?>
' . esc_html__( 'Login', 'anice' ) . '';
}
echo '
';
}
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'title-tag' );
add_theme_support( 'automatic-feed-links' );
}
register_nav_menus( array( 'main-menu' => __( 'Main Menu', 'anice' ) ) );
/**
* Register sidebars
*/
function anice_register_sidebars() {
register_sidebar(
array(
'id' => 'home',
'name' => __( 'Home', 'anice' ),
'before_title' => '',
'after_title' => '
',
)
);
register_sidebar(
array(
'id' => 'single',
'name' => __( 'Posts', 'anice' ),
'before_title' => '',
'after_title' => '
',
)
);
register_sidebar(
array(
'id' => 'archive',
'name' => __( 'archive', 'anice' ),
'before_title' => '',
'after_title' => '
',
)
);
}
add_action( 'widgets_init', 'anice_register_sidebars' );
/**
* Ignore sticky posts
*
* @param object $query query object.
*/
function anice_exclude_sticky_posts( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'ignore_sticky_posts', 1 );
}
}
add_action( 'pre_get_posts', 'anice_exclude_sticky_posts' );
/**
* Clean excerpt html
*
* @param string $str query object.
* @return string Return to the overworry excerpt.
*/
function anice_excerpt( $str ) {
return wp_strip_all_tags( $str );
}
add_filter( 'the_excerpt', 'anice_excerpt' );
/**
* Change excerpt length
*
* @param int $length Excerpt length.
* @return string Returns the modified excerpt length.
*/
function anice_excerpt_length( $length ) {
return anice_get( 'excerpt_length' );
}
add_filter( 'excerpt_length', 'anice_excerpt_length' );
/**
* Change the content at the end of the excerpt
*
* @param string $more Later original content.
* @return string Returns the modified content at the end of the excerpt.
*/
function anice_excerpt_more( $more ) {
return ' ...';
}
add_filter( 'excerpt_more', 'anice_excerpt_more' );
/**
* Set the default thumbnail url
*
* @param string $thumbnail_url Original thumbnail url.
* @return string Returns the modified thumbnail url.
*/
function anice_post_thumbnail_url( $thumbnail_url ) {
if ( ! $thumbnail_url ) {
return anice_get( 'site_thumbnail' );
}
return $thumbnail_url;
}
add_filter( 'post_thumbnail_url', 'anice_post_thumbnail_url', 99999999, 1 );
/**
* Set the number of tag clouds and sort by count
*
* @param array $args Tag cloud args.
* @return string Returns the modified tag cloud args.
*/
function anice_tag_cloud_args( $args ) {
$newargs = array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 30,
);
return array_merge( $args, $newargs );
}
add_filter( 'widget_tag_cloud_args', 'anice_tag_cloud_args' );
if ( ! is_admin() ) {
/**
* Load script and style
*/
function anice_load_scripts() {
$cdn_url = anice_get( 'static_lib_cdn' );
if ( $cdn_url ) {
wp_enqueue_style( 'font-awesome', $cdn_url . '/font-awesome/4.7.0/css/font-awesome.min.css', array(), '4.7.0' );
wp_enqueue_style( 'bootstrap', $cdn_url . '/twitter-bootstrap/4.4.1/css/bootstrap.min.css', array(), '4.4.1' );
wp_enqueue_script( 'popper', $cdn_url . '/popper.js/1.15.0/umd/popper.min.js', array(), '1.15.0', true );
wp_enqueue_script( 'bootstrap', $cdn_url . '/twitter-bootstrap/4.4.1/js/bootstrap.min.js', array( 'jquery' ), '4.4.1', true );
wp_enqueue_script( 'gifffer', $cdn_url . '/gifffer/1.5.0/gifffer.min.js', array(), '1.5.0', true );
} else {
wp_enqueue_style( 'font-awesome', STATIC_URL . '/css/font-awesome.min.css', array(), '4.7.0' );
wp_enqueue_style( 'bootstrap', STATIC_URL . '/libs/bootstrap/css/bootstrap.min.css', array(), '4.4.1' );
wp_enqueue_script( 'popper', STATIC_URL . '/libs/popper/popper.min.js', array(), '1.15.0', true );
wp_enqueue_script( 'bootstrap', STATIC_URL . '/libs/bootstrap/js/bootstrap.min.js', array( 'jquery' ), '4.4.1', true );
wp_enqueue_script( 'gifffer', STATIC_URL . '/libs/gifffer/gifffer.min.js', array(), '1.5.0', true );
}
wp_enqueue_style( 'style', STATIC_URL . '/css/style6.css', array(), THEME_VER );
wp_enqueue_script( 'lazyload', STATIC_URL . '/libs/lazyload/lazyload.min.js', array(), '2.0.0', true );
if ( is_single() ) {
if ( anice_get( 'single_enable_highlight' ) ) {
if ( $cdn_url ) {
wp_enqueue_style( 'highlight', $cdn_url . '/highlight.js/10.1.2/styles/vs.min.css', array(), '10.1.2' );
wp_enqueue_script( 'highlight', $cdn_url . '/highlight.js/10.1.2/highlight.min.js', array(), '10.1.2', true );
wp_enqueue_script( 'line-numbers', $cdn_url . '/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js', array(), '2.8.0', true );
} else {
wp_enqueue_style( 'highlight', STATIC_URL . '/libs/highlight/styles/vs.css', array(), '9.9.0' );
wp_enqueue_script( 'highlight', STATIC_URL . '/libs/highlight/highlight.pack.js', array(), '9.9.0', true );
wp_enqueue_script( 'line-numbers', STATIC_URL . '/libs/highlight/line-numbers.min.js', array(), '1.0.0', true );
}
}
if ( anice_get( 'single_show_share', true ) ) {
if ( $cdn_url ) {
wp_enqueue_style( 'share', $cdn_url . '/social-share.js/1.0.16/css/share.min.css', array(), '1.0.16' );
wp_enqueue_script( 'share', $cdn_url . '/social-share.js/1.0.16/js/jquery.share.min.js', array(), '1.0.16', true );
} else {
wp_enqueue_style( 'share', STATIC_URL . '/libs/share/css/share.min.css', array(), '1.0.16' );
wp_enqueue_script( 'share', STATIC_URL . '/libs/share/js/jquery.share.min.js', array(), '1.0.16', true );
}
}
}
}
add_action( 'wp_enqueue_scripts', 'anice_load_scripts' );
/**
* Add style
*/
function anice_head() {
// set theme color.
$colors = explode( ' ', anice_get( 'theme_color' ) );
list($a1, $a2, $a3) = $colors;
$styles = array(
'a:hover' => "{color:$a1;}",
'.breadcrumb a:hover' => "{color:$a1;}",
'.comment-form .submit,.btn-custom,.badge-custom' => "{color:#fff!important;background-color:$a1;border-color:$a1;}",
'.comment-form .submit:hover,.btn-custom:hover,.badge-custom:hover' => "{color:#fff;background-color:$a2;border-color:$a2}",
'.form-control:focus' => "{border-color: $a3!important;}",
'.navbar-nav .current-menu-item a' => "{color:$a1}",
'.fa-search:hover' => "{color:$a1;}",
'.post-content a' => "{color:$a1;}",
'.post-content a:hover' => "{color:$a2;}",
'.rollbar .rollbar-item:hover' => "{background-color: $a3;}",
);
// #set theme color.
// set page width.
$styles['.container, .container-lg, .container-md, .container-sm, .container-xl'] = '{max-width: ' . anice_get( 'page_width' ) . ';}';
// #set page width.
echo '';
if ( anice_get( 'single_enable_highlight' ) ) {
?>
';
if ( anice_get( 'enable_back_to_top' ) ) {
?>
';
},
99
);
}