Tagged: devin-docs
-
AuthorPosts
-
September 20, 2013 at 4:58 pm #164114
I have a portfolio grid with all portfolio items, they are in an alphabetical order, which is good. On another page I like to show 3 or 4 portfolio items, but would like those to be random from the full list instead of always the same 3-4 first of the list. Is this possible?
EDIT: or instead of random, even being able to choose which 3-4.
- This topic was modified 11 years, 3 months ago by DavyE.
September 21, 2013 at 10:07 am #164378Hi DavyE!
Actually you can change the order with a filter – i.e. add following code to the bottom of functions.php:
function custom_post_grid_query( $query, $params ) { $query['orderby'] = 'rand'; return $query; } add_filter( 'avia_post_grid_query', 'custom_post_grid_query', 10, 2);
and all portfolio grids will use a random order for the entries. However the tricky part is to change the order of some grids only. I recommend to change the order based on the current page id – in your case the code would look like
function custom_post_grid_query( $query, $params ) { if(is_page(array(42,50,45))) $query['orderby'] = 'rand'; return $query; } add_filter( 'avia_post_grid_query', 'custom_post_grid_query', 10, 2);
and instead of 42, 50, 45 insert the page ids of those pages which should display the portfolio grid(s) in a random order. You can separate the ids with a comma.
Regards,
PeterSeptember 23, 2013 at 7:40 pm #165263If I can piggyback on this question – I’d like to randomize the portfolio items displayed using the Frontpage Template (created with the Template Builder). This code doesn’t seem to affect those items; can you tell me what condition I should be using to target ONLY the query for portfolio items using the Frontpage custom template?
September 24, 2013 at 3:14 am #165402Hi!
You’re not using Enfold, right? Probably you can add this on your functions.php:
function loop_portfolio_query( $location ) { if ( $location == 'loop-portfolio' ) { global $avia_config; if(isset($avia_config['new_query'])) { $avia_config['new_query']['orderby'] = "rand"; query_posts($avia_config['new_query']); } } } add_action( 'avia_action_query_check' , 'loop_portfolio_query', 10, 1 );
Regards,
IsmaelSeptember 24, 2013 at 8:10 pm #165801I’m using Flagship. This works, but it randomizes all of the portfolio items on every page. I need to target just the home page, which uses the dynamic template. I’ve tried the following and none seem to affect the home page only: is_home, is_front_page, is_page(28). Is there some other way to target it conditionally?
The page I’m working on is here: http://csam.awfulcool.com
September 25, 2013 at 7:22 pm #166209Figured out a solution – here’s the code I used to target the dynamic template but exclude regular portfolio pages:
function loop_portfolio_query( $location ) { if(avia_is_dynamic_template_active()) { global $avia_config; if(isset($avia_config['new_query'])) { $avia_config['new_query']['orderby'] = "rand"; query_posts($avia_config['new_query']); } } } add_action( 'avia_action_query_check' , 'loop_portfolio_query', 10, 1 );
September 26, 2013 at 2:28 am #166348 -
AuthorPosts
- The topic ‘Portfolio order’ is closed to new replies.