Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

WordPress Widget Customization - Allow me to select which products I want to display rather than displaying all of them?

Hi everyone,

I am just on making with a little project but cant get my head around this certain bit. The theme I am using has its own widgets for the home page and one of them displays the pricing packages available.

My problem with this is it shows all of them :S

I want to customize this widget so that from the widget settings I can select from the pricing packages available, which ones I would like to display.

This is the current widget code:

<?php
/**
 * Price table populated by Price Options
 *
 * @since Jobify 1.0
 */
class Jobify_Widget_Price_Table extends Jobify_Widget {

    /**
     * Constructor
     */
    public function __construct() {
        $this->widget_cssclass    = 'jobify_widget_price_table';
        $this->widget_description = __( 'Output the price table (based on the "Price Table" widget area)', 'jobify' );
        $this->widget_id          = 'jobify_widget_price_table';
        $this->widget_name        = __( 'Jobify - Home: Price Table', 'jobify' );
        $this->settings           = array(
            'title' => array(
                'type'  => 'text',
                'std'   => __( 'Plans and Pricing', 'jobify' ),
                'label' => __( 'Title:', 'jobify' )
            ),
            'description' => array(
                'type'  => 'textarea',
                'rows'  => 4,
                'std'   => '',
                'label' => __( 'Description:', 'jobify' ),
            ),
            'nothing' => array(
                'type' => 'description',
                'std'  => __( 'Drag "Price Option" widgets to the "Price Table" widget area to populate this widget.', 'jobify' )
            )
        );

        parent::__construct();
    }

    /**
     * widget function.
     *
     * @see WP_Widget
     * @access public
     * @param array $args
     * @param array $instance
     * @return void
     */
    function widget( $args, $instance ) {
        if ( $this->get_cached_widget( $args ) )
            return;

        ob_start();

        extract( $args );

        $title        = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
        $description  = $instance[ 'description' ];
        $the_sidebars = wp_get_sidebars_widgets();
        $widget_count = count( $the_sidebars[ 'widget-area-price-options' ] );

        echo $before_widget;
        ?>

        <div class="container">

            <?php if ( $title ) echo $before_title . $title . $after_title; ?>

            <?php if ( $description ) : ?>
                <p class="homepage-widget-description"><?php echo $description; ?></p>
            <?php endif; ?>

            <div class="pricing-table-widget-<?php echo $widget_count; ?>">
                <?php dynamic_sidebar( 'widget-area-price-options' ); ?>
            </div>

        </div>

        <?php
        echo $after_widget;

        $content = apply_filters( 'jobify_widget_price_table', ob_get_clean(), $instance, $args );

        echo $content;

        $this->cache_widget( $args, $content );
    }
}

?>

I feel this may be more work that I am anticipating but who doesn't like a challenge :)

Craig