Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #227963

    Hi there,
    I’m using the Masonry Entries to display posts on several pages on my site. In most cases I want these sorted by most recent first, which I achieved by editing masonry_entries.php. For one page, however, I would like the entries sorted alphabetically. Is it possible to do this by addind some code to the masonry_entries.php? Or even in the shortcode on that page?

    Thanks!

    #228561

    Hey topergarden!

    No not that I know of. I’ll tag the topic for the head of support who may know of a filter that will work on an individual page.

    Cheers!
    Devin

    #228895

    Hi!

    You can use this code – insert it into the functions.php file:

    
    add_filter('avia_masonry_entries_query', 'avia_random_image_query', 10, 2);
    function avia_random_image_query($query, $params)
    {
        if(is_page(array(20)))
        {
            $query['orderby'] = "ASC";
            $query['order'] = "title";
        }
    
        return $query;
    }
    

    Replace 20 with the id of the page where you want to sort the entries alphabetically.

    Regards,
    Peter

    #228908

    Thanks! I made the mistake of pasting that in my functions.php of enfold, rather than in my child theme functions.php. This broke the site (just returns a blank page, even for the dashboard). I got back in through ftp and edited functions.php back to how it was, still broken. I even downloaded the theme again and replaced functions.php and it’s still broken. Help!!!

    #228915

    UPDATE: I’ve managed to fix it – learnt about debugging and found the syntax error.

    I’ve now added the code to my child theme functions.php but I get the error…

    Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home4/chrisga3/public_html/bodyboard/wp-content/themes/enfold-child/functions.php on line 29

    Line 29 is this bit… function avia_random_image_query($query, $params)

    Any ideas?

    #229066

    I just tried it out with my live child them and didn’t any errors. The query values were reversed so it should be the following:

    
    add_filter('avia_masonry_entries_query', 'avia_random_image_query', 10, 2);
    function avia_random_image_query($query, $params)
    {
        if(is_page(array(5173)))
        {
            $query['orderby'] = "title";
            $query['order'] = "ASC";
        }
    
        return $query;
    }
    

    but it shouldn’t cause any errors. Just make sure your functions file has an opening ‘<?php’ and the function is after that.

    #229190

    Thanks very much! Hmmm, still can’t work out what is going on though. Here’s my current child functions.php…

    <?php
    
    /*
    * Add your own functions here. You can also copy some of the theme functions into this file. 
    * WordPress will use those functions instead of the original functions then.
    */
    //Add title attribute back to gallery images 
    function my_image_titles($atts,$img) { 
    
            $atts['title'] = trim(strip_tags( $img->post_title )); 
         
        return $atts; 
    } 
    add_filter('wp_get_attachment_image_attributes','my_image_titles',10,2);  
    
    add_filter('avf_title_args', 'fix_single_post_title', 10, 2);
    function fix_single_post_title($args,$id)
    {
    if (is_single())
    {
    $args['title'] = get_the_title($id);
    $args['link'] = get_permalink($id);
    }
    
    return $args;
    }

    I simply pasted your code at the bottom of this and it still breaks it. Strange!

    #229391

    Hi,

    I tried with your exact functions.php file + the avia_random_image_query function and got no errors so far, can you create an administrator account and post it here as a private reply?

    Regards,
    Josue

    #229455
    This reply has been marked as private.
    #229729

    Added the code:
    http://www.bodyboard.co.nz/wp-admin/theme-editor.php?file=functions.php&theme=enfold-child&scrollto=162&updated=true

    No errors so far, please check if the changes have been applied to your Masonry elements.

    Cheers!
    Josue

    #229759

    Cheers! it’s working perfectly and has ordered the page alphabetically.

    Thanks very much for the outstanding support!

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Order of Masonry Entries’ is closed to new replies.