WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Make Featured Stories widget in Arras Theme display posts in random order (2 posts)

  1. Shaun Scovil
    Member
    Posted 3 years ago #

    This is more or less a WP_Query question...

    I'm currently using Arras Theme v1.5 on one website and Arras Theme v1.4 on another.

    In both versions, there is a widget called 'Featured Stories' that displays a list of posts with thumbnails and excerpts on the sidebar. However, the code for this widget is different in each version.

    I was able to successfully display the 'Featured Stories' posts in random order in v1.4, by modifying the code in widgets.php as follows:

    function widget($args, $instance) {
    		global $wpdb;
    		extract($args, EXTR_SKIP);
    
    		if ($instance['no_display_in_home'] && is_home()) return;
    
    		$title = apply_filters('widget_title', $instance['title']);
    		$cat = (int)strip_tags($instance['featured_cat']);
    
    		echo $before_widget;
    		echo $before_title . $title . $after_title;
    
    		$r = new WP_Query( array('showposts' => $instance['postcount'], 'orderby' => 'rand', 'cat' => $cat ) );
    		if ($r->have_posts()) {
    
    		echo '<ul class="featured-stories">';
    		while ($r->have_posts()) : $r->the_post();
    		?>

    The change was made to line 236, where I added 'orderby' => 'rand',:

    $r = new WP_Query( array('showposts' => $instance['postcount'], 'orderby' => 'rand', 'cat' => $cat ) );

    Now I am trying to achieve the same effect with v1.5, but am having no luck due to a lack of coding skill! :-/

    Here is the code as it appears in Arras Theme v1.5:

    function widget($args, $instance) {
    		global $wpdb;
    		extract($args, EXTR_SKIP);
    
    		if ($instance['no_display_in_home'] && is_home()) {
    			return false;
    		}
    
    		$title = apply_filters('widget_title', $instance['title']);
    
    		echo $before_widget;
    		echo $before_title . $title . $after_title;
    
    		$q = arras_parse_query($instance['featured_cat'], $instance['postcount'] );
    		$r = new WP_Query($q);
    		if ($r->have_posts()) {
    
    		echo '<ul class="featured-stories">';
    		while ($r->have_posts()) : $r->the_post();
    		?>

    The whole $q = arras_parse_query bit is screwing me up. Can anyone help me out?

  2. Shaun Scovil
    Member
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic