Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1489036

    Hello,

    I would like to sort my posts two different ways on two different pages, and I’m wondering if there is an easy way to do it.

    On my songs page, I post the songs I write in chronological order. Each song is a blog post, and I organized them on my songs page by posting excerpts in order. The oldest song is at the bottom, the newest at the top.

    On my blog page, however, I would like to present a different order, because I tend to write about each song out of chronological order. So if I decide to write about the fifth song I ever posted, for example, I would like its blog post to appear as the first blog post, whereas on the song page, it would be remain in order. But if I update the date on the blog post, it reorders it in both places. Is there a way, maybe using page IDs, to keep the order the same on the Songs page but fluid on the Blog page? T

    Hoping this makes sense lol. Thank you!

    #1489079

    Hey tonyska,

    Thank you for the inquiry.

    Which blog layout (Grid, Small, Multi-author, List etc.) did you select? If it’s set to Grid Layout, you should be able to use the avia_post_slide_query filter to adjust the sorting of the items and utilize conditional functions to apply different sorting for specific pages or templates.

    Example:

    add_filter('avia_post_slide_query', 'avia_post_slide_query_mod');
    function avia_post_slide_query_mod($query) {
        if (is_page(123)) {
            $query['orderby'] = 'menu_order';
            $query['order'] = 'ASC';
        }
        elseif (is_home()) {
            $query['orderby'] = 'date';
            $query['order'] = 'DESC';
        }
    
        return $query;
    }
    

    Replace 123 with the actual ID of the song page.

    Each song is a blog post, and I organized them on my songs page by posting excerpts in order.

    How do you post excerpts in a specific order?

    Best regards,
    Ismael

    #1489257

    Sorry for the delayed response, and thanks so much for your reply!

    To answer your questions: my Songs page is set up using Single Author, big preview, Excerpt with read more link.

    I do not post the excerpts in a specific order; they are currently organized by date which works for now. This way the most recent post is at the top, the oldest post is as the bottom.

    On the “Blog” page, I add to the song posts with a diary of how the song was made. But I do that randomly, and I’d like the most recent blog post to come to the top of the Blog page filter.

    However, if I change the publish date on the blog post of an older song, it will affect its ordering on the “Songs” page, which I don’t want. I want the older songs to stay at the bottom even if I update the entry.

    So essentially, same blog posts, but two different orderings on two different pages.

    I enclosed links below so you can see how I have it right now. I’d like to be able to change the date on the blog entry, which would bring new blog entries to the top, but also somehow keep the list on the Songs page as-is.

    I’m sorry if this sounds confusing. I honestly think I’m confusing myself lol.

    #1489268

    Hi,

    Thank you for the update.

    Try to add this code to the functions.php file to sort items on the blog page by modified date and on the songs page by published date:

    function ava_pre_get_posts_mod($query) {
        if (!is_admin() && $query->is_main_query()) {
            if (is_page(1230)) {
                $query->set('orderby', 'date');
                $query->set('order', 'DESC');
            }
    
            if (is_page(574)) {
                $query->set('orderby', 'modified'); 
                $query->set('order', 'ASC');
            }
        }
    }
    add_action('pre_get_posts', 'ava_pre_get_posts_mod');
    
    

    Best regards,
    Ismael

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.