Tagged: Latest news widget, sort blog posts
-
AuthorPosts
-
April 22, 2015 at 5:09 am #432538
I have 30 blog posts in several main categories. I have placed lists of posts in the sidebars via widgets, the latest news widget with icon. The same posts always sort to the top and it would be much more interesting if I could randomize the sort. Possible? I don’t want to create a sh@t-ton of widgets.
See:
http://www.boulderhardwoodfloors.com/wood-basics/wood-cut/riftsawn-wood/
and:
http://www.boulderhardwoodfloors.com/flooring-types/reclaimed-wood-floor/Want to randomize the left column so it doesn’t appear the same each time you surf to a different post..
Thanks in advance for your kind support.
April 22, 2015 at 6:20 am #432559This might be helpful. The masonry blog on this page has a setting and is set to randomize.:
http://www.boulderhardwoodfloors.com/blog/April 22, 2015 at 8:44 pm #433107Hi!
Try opening up /enfold/framework/php/class-framework-widgets.php and change line 452 from this.
$additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);
To this.
$additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count."&orderby=rand");
Regards,
ElliottApril 22, 2015 at 9:17 pm #433128This worked perfectly for lists of posts in the sidebars via widgets, the latest news widget with icon—in the sidebar on a post page.
Thank you.It does not randomize in the sidebar widget on a portfolio page. See:
http://www.boulderhardwoodfloors.com/portfolio-item/bamboo-install-sand-and-finish/
and:
http://www.boulderhardwoodfloors.com/portfolio-item/american-cherry/Can we add a little more code to make it work on a portfolio page, in addition to working on a post page?
Thank you in advance.
April 24, 2015 at 4:25 pm #434199Hey!
Try doing the same thing on lines 461 and 471 as well.
Cheers!
ElliottApril 24, 2015 at 6:32 pm #434328Doesn’t seem to be working.
Here’s what I got starting on line 450:
if(empty($this->avia_term)) { $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count."&orderby=rand"); } else { $catarray = explode(',', $cat); if(empty($catarray[0])) { $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type); $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count."&orderby=rand"); } else { if($this->avia_new_query) { $new_query = $this->avia_new_query; } else $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count."&orderby=rand"); { $new_query = array( "posts_per_page"=>$count, 'tax_query' => array( array( 'taxonomy' => $this->avia_term, 'field' => 'id', 'terms' => explode(',', $cat), 'operator' => 'IN') ) ); } } $additional_loop = new WP_Query($new_query); }
Could you please take another gander to see if I am putting in the code correctly?
April 27, 2015 at 4:30 pm #435377Hey!
It should look like this.
if(empty($this->avia_term)) { $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count."&orderby=rand"); } else { $catarray = explode(',', $cat); if(empty($catarray[0])) { $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type, "orderby"=>"rand"); } else { if($this->avia_new_query) { $new_query = $this->avia_new_query; } else { $new_query = array( "orderby"=>"rand","posts_per_page"=>$count, 'tax_query' => array( array( 'taxonomy' => $this->avia_term, 'field' => 'id', 'terms' => explode(',', $cat), 'operator' => 'IN') ) ); } } $additional_loop = new WP_Query($new_query); }
Regards,
ElliottApril 27, 2015 at 5:49 pm #435464This reply has been marked as private.April 28, 2015 at 6:44 am #435801 -
AuthorPosts
- You must be logged in to reply to this topic.