Home / Forums / DynamiX Support / Sort blog posts alphabetic

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts

  • Stefan G.
    Participant

    Hello, where can i change the order of blog posts with template blog.php?
    I want to sort the posts alphabetic ‘ascending’ or ‘descending’.

    I don’t see any options for that or variables in de code..
    Please help!


    Stefan G.
    Participant

    Sorry, it’s about a custom posttype i made. It uses archive.php. But nowhere i can set the orderby and order for that posttype..
    Because there is no ‘get_posts’ function, does it?

    Andy
    Andy
    Keymaster

    Hi Stefan,

    You should be able to add a bit of code like query_posts($query_string . "&order=ASC"); – try placing just before this line:

    if (have_posts()) :


    Stefan G.
    Participant

    Thanks. i figured it out and added a function in custom-functions.php to make it work:`function alpha_order_classes( $query ) {

    if ( !is_admin() && $query->is_main_query() ) {

    if($query->query_vars[‘doc-category’]) {

    $query->set( ‘orderby’, ‘title’ );
    $query->set( ‘order’, ‘ASC’ );
    }
    }
    }

    add_action( ‘pre_get_posts’, ‘alpha_order_classes’ );`

    • This reply was modified 2 years, 9 months ago by  Stefan G..
    • This reply was modified 2 years, 9 months ago by  Stefan G..
    • This reply was modified 2 years, 9 months ago by  Stefan G..
    Andy
    Andy
    Keymaster

    Awesome, that works better. I was looking for the query_vars function, I’ve done something similar to it before but couldn’t remember what it was called.

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

You must be logged in to reply to this topic.