Jump to content

brandnucreative

New Members
  • Posts

    1
  • Joined

  • Last visited

brandnucreative's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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 ); } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.