brandnucreative Posted February 28, 2015 Share Posted February 28, 2015 (edited) Hi All, I'm currently trying to find a solution to a problem within a wordpress template I am using. On the homepage, Im using a widget to display recent posts. However, the widget displays all posts, whereas I want it to only display posts from a particular category. What do I need to edit within the php to make this happen? Heres the widget php: <?php /** * List Blog Posts * * @since Jobify 1.0 */ class Jobify_Widget_Blog_Posts extends Jobify_Widget { /** * Constructor */ public function __construct() { $this->widget_cssclass = 'jobify_widget_blog_posts'; $this->widget_description = __( 'Jobify - Display recent blog posts.', 'jobify' ); $this->widget_id = 'jobify_widget_blog_posts'; $this->widget_name = __( 'Jobify - Home: Blog Posts', 'jobify' ); $this->settings = array( 'title' => array( 'type' => 'text', 'std' => __( 'Recent News Article', 'jobify' ), 'label' => __( 'Title:', 'jobify' ) ), 'description' => array( 'type' => 'textarea', 'rows' => 4, 'std' => '', 'label' => __( 'Description:', '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' ]; $posts = new WP_Query( apply_filters( 'widget_jobify_blog_posts', array( 'posts_per_page' => 3, 'ignore_sticky_posts' => true ) ) ); 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="content-grid row"> <?php if ( $posts->have_posts() ) : ?> <?php while ( $posts->have_posts() ) : $posts->the_post(); ?> <?php get_template_part( 'content', 'grid' ); ?> <?php endwhile; ?> <?php endif; ?> </div> </div> <?php echo $after_widget; $content = apply_filters( 'jobify_widget_blog_posts', ob_get_clean(), $instance, $args ); echo $content; $this->cache_widget( $args, $content ); } } Edited February 28, 2015 by brandnucreative Quote Link to comment https://forums.phpfreaks.com/topic/294958-wordpress-widget-how-to-display-one-post-category-rather-than-all/ Share on other sites More sharing options...
blacknight Posted April 13, 2015 Share Posted April 13, 2015 hard to help the main guts of the plugin are hidden as the filter widget_jobify_blog_posts makes the query and you would need to edit that function in the plugin Quote Link to comment https://forums.phpfreaks.com/topic/294958-wordpress-widget-how-to-display-one-post-category-rather-than-all/#findComment-1508876 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.