Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #17434

    Hey guys,

    The theme is awesome, but there is something I want to add to portfolio functionality.

    I need portfolio items on my main page be showcased randomly.

    Say, I have 12 portfolio items displayed out if 30, and I need them to change randomly each time someone visits/reloads that page.

    So how can I do this?

    Thanks in advance,

    Darina

    #95455

    Hi,

    try to add following code to the bottom of functions.php:

    function loop_portfolio_query( $location )
    {
    if ( $location == 'loop-portfolio' && (is_home() || is_front_page()) )
    {
    global $avia_config;
    if(isset($avia_config['new_query'])) {
    $avia_config['new_query']['orderby'] = "rand";
    $avia_config['new_query']['posts_per_page'] = "12";
    query_posts($avia_config['new_query']);
    }
    }
    }
    add_action( 'avia_action_query_check' , 'loop_portfolio_query', 10, 1 );

    #95456

    Hi Dude,

    thanks for your response! I pasted the code into functions.php but unfortunately it does nothing at all.

    Hope you can help me more with it. It is really crucial.

    #95457

    Hey keidgen,

    I’ve tagged Dude on this post so he should see it in his queue asap.

    Regards,

    Devin

    #95458

    Hey guys,

    so can I count on a reply about my case? Its been quite a while since I posted it.

    I know that might not be the simplest question, but still I doubt its something impossible to do…

    Or should I start looking for another theme that has this option?

    #95459

    Tbh I’m not sure why it doesn’t work but you can try following code instead:

    function loop_portfolio_query( $location )
    {
    global $avia_config;
    if ( $location == 'loop-portfolio' && !empty($avia_config['frontpage']) )
    {
    if(isset($avia_config['new_query'])) {
    $avia_config['new_query']['orderby'] = "rand";
    $avia_config['new_query']['posts_per_page'] = "12";
    query_posts($avia_config['new_query']);
    }
    }
    }
    add_action( 'avia_action_query_check' , 'loop_portfolio_query', 10, 1 );

    Then open up header.php and replace following code at the very top:

    global $avia_config;

    with:

    global $avia_config;
    $avia_config['frontpage'] = ( is_home() || is_front_page() ) ? 'frontpage' : '';

    #95460

    Hi Dude,

    thanks for your response!

    I pasted the code you suggested, but it does nothing at all yet again. Portfolio on Frontpage still sorts the latest items instead of random.

    Just for lulz I tried the code from “Portfolio Sort Order – reverse chronological” post to see if it will sort items in reversed order at least, and it works for all the pages, including the Main page, of course.

    So my suggestion is that it does not recognize that the page is Frontpage so it ignores the code completely.

    Just an idea, but maybe it is easier to try to set some sort of a condition – if number of portfolio items is 12 then sort randomly for portfolio items in general portfolio settings? And as I have 12 items set only for main page it will sort it there randomly? It sounds like an ugly solution, but for me it does not matter anymore. I just need it to work one way or another :)

    Or maybe the issue is that the general portfolio settings that allow items to be sorted in chronological/reverse order still override the random settings for Frontpage? Either way it just ignores this part of code like it never existed.

    I think that adding random sorting option to portfolio features in later releases of the theme would be a great idea. Am I really the only one needs or will need a feature like this?

    #95461

    As experiment I tried this:

    [pre]

    Code:
    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 );

    [/pre]

    and as expected it sorts all portfolio items randomly on all pages. So I suspect that what I wrote above is true. If only it is possible at least to sort all items when set as 12 per page, as I mentioned before, I think it might be suitable for me in this case.

    #95462

    Hi!

    I tagged this thread for Kriesi.

    Regards,

    Peter

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Portfolio random sorting’ is closed to new replies.