WordPress.org

Ready to get started?Download WordPress

Forums

Limiting a slider to a specific category (1 post)

  1. nickforddesign
    Member
    Posted 2 years ago #

    I'm trying to alter an existing plugin, Arconix Flexslider, which currently pulls a specified number of all recent posts. I want it to limit the posts that are pulled to a specific category, named "Featured". Below is my best guess of where this would need to happen... This plugin is actually a widget, also.

    /**
         * Widget Output
         *
         * @param type $args Display arguments including before_title, after_title, before_widget, and after_widget.
         * @param type $instance The settings for the particular instance of the widget
         * @since 0.1
         * @version 0.2
         */
        function widget( $args, $instance ) {
    
    	extract( $args );
    
    	/** Merge with defaults */
    	$instance = wp_parse_args( ( array )$instance, $this->defaults );
    
    	/** Before widget (defined by themes) */
    	echo $before_widget;
    
    	/** Title of widget (before and after defined by themes) */
    	if( ! empty( $instance['title'] ) )
    	    echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
    
    	$query_args = array(
    	    'post_type' => $instance['post_type'],
    	    'posts_per_page' => $instance['post_num'],
    	    'meta_key' => '_thumbnail_id' /** Should pull only posts with featured images */
    	);
    
    	$flex_posts = new WP_Query( $query_args );
    
    	if ( $flex_posts->have_posts() ) {
    	    echo '<div class="flex-container">
                    <div class="flexslider">
                    <ul class="slides">';
    
                    while ( $flex_posts->have_posts() ) : $flex_posts->the_post();
    
                        echo '<li><a href="';
                        the_permalink();
                        echo '" rel="bookmark">';
                        the_post_thumbnail( $instance['image_size'] );
    
    		    switch( $instance['show_caption'] ) {
    			case 'post title':
    			    echo '<p class="flex-caption">';
    			    the_title();
    			    echo '</p>';
    			    break;
    
    			case 'image title':
                                global $post;
                                echo '<p class="flex-caption">' . get_post( get_post_thumbnail_id( $post->ID ) )->post_title . '</p>';
    			    break;
    
    			case 'image caption':
                                global $post;
                                echo '<p class="flex-caption">' . get_post( get_post_thumbnail_id( $post->ID ) )->post_excerpt . '</p>';
    			    break;
    
    			default:
    			    break;
    
                        }
    
                        echo '</a></li>';
    
                    endwhile;
    
                echo '</ul></div></div>';
            }

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by nickforddesign
  • This topic is not resolved
  • WordPress version: 3.4.1