WordPress 常用函数篇

//WordPress 已发布文章数量

$count_posts = wp_count_posts(); echo $published_posts =$count_posts->publish;

functions.php:

/*
    Widgets小工具调用
*/
function adademy_widgets_init() {
    if ( !function_exists('register_sidebars') )
        return;

    $p = array(
        'before_widget'  =>   "\n\t\t\t" . '
  • ', 'after_widget' => "\n\t\t\t
  • \n", 'before_title' => "\n\t\t\t\t". '

    ', 'after_title' => "

    \n" ); // Table for how many? Two? This way, please. register_sidebars( 2, $p ); $widget_ops = array( 'classname' => 'widget_search', 'description' => __( "A search form for your blog ", "academy" ) ); wp_register_sidebar_widget( 'search', __( 'Search', 'academy' ), 'academy', $widget_ops ); unregister_widget_control('search'); wp_register_widget_control( 'search', __( 'Search', 'academy' ), 'academy' ); // adademy Meta widget $widget_ops = array( 'classname' => 'widget_meta', 'description' => __( "Log in/out and administration links (academy)", "academy" ) ); wp_register_sidebar_widget( 'meta', __( 'Meta', 'academy' ), 'academy', $widget_ops ); unregister_widget_control('meta'); wp_register_widget_control( 'meta', __( 'Meta', 'academy' ), 'wp_widget_meta_control' ); } add_action( 'init', 'adademy_widgets_init' );
    /*
     * 打开自定义页面(生成seo链接)
     * */
    function load_single_template($template) {
        $new_template = '';
        if( is_single() ) {
            global $post;
            if( has_term('seodata-zh', 'category', $post) ) {
                $new_template = locate_template(array('single-seodata-zh.php' ));
            }
            if( has_term('seodata-en', 'category', $post) ) {
                $new_template = locate_template(array('single-seodata-en.php' ));
            }
        }
        return ('' != $new_template) ? $new_template : $template;
    }
    add_action('template_include', 'load_single_template');
    

    你可能感兴趣的:(WordPress 常用函数篇)