Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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, 2 months ago by DavyE.
    #164378

    Hi 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,
    Peter

    #165263

    If 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?

    #165402

    Hi!

    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,
    Ismael

    #165801

    I’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

    #166209

    Figured 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 );
    #166348

    Hey!

    Glad you figured it out.

    Best regards,
    Ismael

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Portfolio order’ is closed to new replies.