如何注册和显示自定义分类的小部件

时间:2015-07-11 作者:user235377

我已经注册了一个名为Album的自定义分类法,现在我想注册并显示一个自定义小部件类的类别,以便在侧边栏上显示最近的“x”相册以及缩略图。下面是一段代码,但它像标记云一样显示它。

<?php 
add_action("widgets_init", array(\'Widget_Custom_tax_tag_cloud\', \'register\'));
class Widget_Custom_tax_tag_cloud {
    function control(){
        echo \'No control panel\';
    }
    function widget($args){
        echo $args[\'before_widget\'];
        echo $args[\'before_title\'] . \'Your widget title\' . $args[\'after_title\'];
        $cloud_args = array(\'taxonomy\' => \'Your taxonomy here\');
        wp_tag_cloud( $cloud_args ); 
        echo $args[\'after_widget\'];
    }
    function register(){
        register_sidebar_widget(\'Widget name\', array(\'Widget_Custom_tax_tag_cloud\', \'widget\'));
        register_widget_control(\'Widget name\', array(\'Widget_Custom_tax_tag_cloud\', \'control\'));
    }
}
?>
这是我的网站URL:http://pagalworldmp.com/

1 个回复
SO网友:Brad Dalton

至少有3种选择:

您可以将代码作为本机代码recent posts widget 并在子主题中修改它以使用自定义分类法WP_Query 使用税务参数widget_posts_args 修改本机“最近发布”小部件的默认输出,以便它输出自定义分类法我建议您查看核心,找到本机的“最近发布”小部件或“类别”小部件,并查看代码。试试wp includes/default小部件。php。

结束

相关推荐

widgets not working

我粘贴了我的siderbar小部件代码widgets.php 文件 function right_sidebar_widget() { register_sidebar( array( \'name\' => \'Right Siderbar\', \'id\' => \'right-siderbar\', \'description\' => \'Right Sidebar\',