Sep 132013
 
 Posted by on 13/09/2013 How-To's Tagged with: , ,  5 Responses »

The problem: “Everything is working great except that I can’t for the life of me figure out how to control the order of the entries in the slider.”

WP_Query Prameters from WordPress Codex
WP_Query Parameters from WordPress Codex

 Yes, Suffusion come with two great Featured Content sliders bundled in it. The first, considered “static”, can be settled at Suffusion Options -> Other Graphical Elements -> Featured Content. Is considered static because can appear only on the top of main column on the pages where is settled to be. The other one, “dynamic”, is the Featured Content Widget. Dynamic because can be used in any widget area, so, can appear anywhere in the page. In this article I will explain how can order the slides in the STATIC slider.

The question from the top of this article was asked several times on the Suffusion Support Forum. Few years ago I also had this problem when we build BHZN site. Then I found a first solution – to change the publishing date of POST. So, I remain with the idea that this is the universal solution and will works for pages too. This was a wrong thought. I start to digg into the code and I discovered more interesting things.

First, and very important, the displaying of slides, including the order is controlled by featured-post.php file from “suffusion” folder. Why is important? The file is pluggable, can be copied into a child theme and edited there for preserving the changes in case of upgrades of theme. Now, studying the file can see that the function which display the slides is suffusion_display_featured_posts($echo = true) and the posts/pages are retrieved by WP_query class instances. Of course, WP_query will accept all allowed parameters specified in Codex: https://codex.wordpress.org/Class_Reference/WP_Query, including ‘order’ and ‘orderby’.

For POSTS is used this query:

 As you can see the ‘orderby’ parameter is not specified – so, is used the default value of this parameter which is ‘date’. So, for changing the order of slides based on posts still works the method of changing publishing date of posts selected as featured. If you need to sort the slides in other order than the date, simply add the orderby paramenter into the query args. By eg. for randomize the slides can change the above line with:

UPDATE: 11 March 2014. The query from above retrieve the latest posts. If you want to retrieve only posts from a single category or tag look for the next code and alter the args used in query:

 By eg., for retrivieng posts by date in ascending order, change the code to:

Can download the file changed to show posts from a category in ascending order from here: featured-posts.php

Now for PAGES is used this query:

Menu Order in Page Attributes panel
Menu Order in Page Attributes panel

Here we can see the ‘orderby’ parameter is present and it’s value is controlled by ‘menu_order’. So, immediately we can see the trivial solution – we can change the order in the Page Attributes panel, on the right of edit area in the Edit Page screen. If you are not happy with this kind of ordering can change the ‘orderby’ parameter. Again, as an example you can randomize the slides by changing the query to:

REMEMBER, before making changes in those queries, make a copy of featured-posts.php from suffusion folder into your child theme folder and edit the copy.

Read this post for learning how to make a child theme.

Note. If you use ‘orderby’ => ‘rand’ as in the above examples, the order of slides is randomized in the moment of page loading and will stay in the initial order until the page is refreshed – you will not see images shuffled at each cycle.