0

我正在创建一个类别小部件,这样我就可以只在我想要的页面上拥有博客类别,因此它更适合我的主题:)

无论如何,这里是小部件编码,我认为还可以,但我无法测试它,因为我不确定如何调用链接,调用哪一列。

class ubl_blog_cats extends WP_Widget {

    public function __construct() {
        parent::__construct(
          'ubl_blog_cats',
          'UBL Blog Categories',
          array( 'description' => __( 'Displays The Bog Categories'))
        );
    }

    public function form( $instance ) { 

        $title = (isset( $instance[ 'title' ])) ? $instance['title' ] : 'Blog Categories'; ?> 

        <p>
            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
        </p>

<?php }

    public function update( $new_instance, $old_instance ) {
        $instance = array();
        $instance['title'] = strip_tags( $new_instance['title'] );
        return $instance;
    }

    public function widget( $args, $instance ) {

        global $wpdb;

        extract( $args );

        $title = apply_filters( 'widget_title', $instance['title'] );

        if ( ! empty( $title ) ) echo '<div class="widget_title" id="widget">' . $title . '</div>';

        $ublmostpop = new $wpdb->get_results("
        SELECT * 
        FROM wp_term_relationships 
        LEFT JOIN wp_term_taxonomy 
        ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) 
        LEFT JOIN wp_terms on wp_term_taxonomy.term_taxonomy_id = wp_terms.term_id 
        WHERE wp_term_taxonomy.taxonomy = 'category' 
        GROUP BY wp_term_taxonomy.term_id");

        echo '<div class="navcat"><ul>';

        foreach($ublmostpop as $ublmp){ ?>

                <li><a href="" title=""></a></li>

        <?php } ?>

        </ul></div>

<?php 
        wp_reset_postdata();
        echo $after_widget;

    }

}

register_widget( 'ubl_blog_cats' );

?>

另外请让我知道这个小部件是否不起作用:)

4

0 回答 0