Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter anshul1304

    (@anshul1304)

    My archive.php page has this code:
    <?php if (have_posts()) : query_posts(“cat=” . $cat . “&orderby=menu_order&order=ASC”); while (have_posts()) : the_post(); ?>

    Is this an issue related to archive page or is it related to query.php page? Any ideas.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Please don’t create duplicates of your thread. If you have any additional information you can post it here.

    Thread Starter anshul1304

    (@anshul1304)

    Ok Andrew, I will take care of this.

    the problem is caused by your query; review http://codex.wordpress.org/Pagination

    if you want to change the sorting parameter of your category archive posts, consider to use 'pre_get_posts' action; http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    example code (to be added into functions.php of your theme):

    function category_archive_sorting( $query ) {
        if ( is_admin() || ! $query->is_main_query() )
            return;
    
        if ( is_category() ) {
            $query->set( 'orderby', 'menu_order' );
            $query->set( 'order', 'ASC' );
            return;
        }
    }
    add_action( 'pre_get_posts', 'category_archive_sorting', 1 );
    Thread Starter anshul1304

    (@anshul1304)

    Hello Alchymyth,

    Thanks for your message.

    This however did not solve the issue. I added the function in the php file but there was no effect.

    I still get same posts on the next page.

    Regards,
    Anshul

    did you remove this query code query_posts("cat=" . $cat . "&orderby=menu_order&order=ASC"); from your loop?

    Thread Starter anshul1304

    (@anshul1304)

    Hello Alchymyth,

    No, I did not do that. What do I put there in place of the above query?

    Sorry for the trouble, but am more towards designing and less towards programming.

    Regards,
    Anshul

    Thread Starter anshul1304

    (@anshul1304)

    Also, as of now, my functions.php file just has this code:
    <?php
    if ( function_exists(‘register_sidebars’) )
    register_sidebars(1);
    ?>

    Thread Starter anshul1304

    (@anshul1304)

    Hello Alchymyth,

    Ok, I removed the query and it seems to be working fine.

    Do I need to add the sorting function in functions.php file?

    Please advise.

    Regards,
    Anshul

    Thread Starter anshul1304

    (@anshul1304)

    Thanks for your help Alchymyth!

    Much appreciated.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Archive shows same posts on all pages’ is closed to new replies.