WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Posts listing order (5 posts)

  1. Mariusz
    Member
    Posted 4 years ago #

    Hi I have the loop begining with:

    `<?php if (have_posts()) :

    $counter = 2;

    while (have_posts()) : the_post();

    $the_div_class = alternating_css_class($counter,2,' col_first');
    ?>`

    I have a problems sorting these posts in the loop.

    I have no get_posts(); tag in the loop...

    I would love to have a possibility to sort posts with postsmash

    Suggestions how to sort posts?

    Thanks!

  2. Mariusz
    Member
    Posted 4 years ago #

    anyone?

  3. MichaelH
    Member
    Posted 4 years ago #

    Before this line:
    while (have_posts()) : the_post();

    use the template tag, query_posts():

    query_posts($query_string . '&orderby=title&order=ASC');

  4. Mariusz
    Member
    Posted 4 years ago #

    ok I put

    <?php if (have_posts()) :

    $counter = 2;

    query_posts($query_string .'&orderby=title&order=ASC');

    while (have_posts()) : the_post();

    $the_div_class = alternating_css_class($counter,2,' col_first');
    ?>

    but it seem not to work. Something else is determining the order of posts... - I'm sure these are sorted by date...

  5. Mariusz
    Member
    Posted 4 years ago #

    o make use of this chosen order you will need to modify your template code:
    Open wp-content/themes/your-theme-name/index.php and find the beginning of ‘the loop’. Which will start:

    if(have_posts())

    Then add the following code directly before this:
    view plaincopy to clipboardprint?

    1. <?php
    2. $wp_query->set('orderby', 'menu_order');
    3. $wp_query->set('order', 'ASC');
    4. $wp_query->get_posts();
    5. ?>

    <?php
    $wp_query->set('orderby', 'menu_order');
    $wp_query->set('order', 'ASC');
    $wp_query->get_posts();
    ?>

    This just tells WP to get the posts ordered according to their ‘menu_order’ position. Therefore you can get the posts ordered anytime you use a function such as get_posts simply by giving it the required arguments:

    <?php get_posts('orderby=menu_order&order=ASC'); ?>

    Checkout the get_posts() function in the wordpress codex for more info.
    Note that it says menu_order is only useful for pages, posts have a menu_order position too, it just isn’t used. postMash provides you with an iterface so that you can use it.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags