[Resolved] list category in alpha order

Home Forums Support list category in alpha order

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #979456
    Nanette

    I have snippet code but finding it hard to set up a code to have this page in alpha order
    https://nir-for-food.com/category/applications/

    How can I do that?

    Nanette

    #979647
    David
    Staff
    Customer Support

    Hi there,

    i provide a PHP snippet here for ABC ordering:

    https://generatepress.com/forums/topic/posts-and-post-length-and-filters/

    Instead of the is_home() conditional you can use is_category( 'cat-slug' )

    #983322
    Nanette

    I did it and made the change in conditional but got this:
    Don’t Panic
    The code snippet you are trying to save produced a fatal error on line 6:

    Cannot redeclare db_abc_modify_query_order() (previously declared in /www/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code:1)
    The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

    Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.

    Nanette

    #983340
    David
    Staff
    Customer Support

    So your code should look like this:

    function db_abc_modify_query_order( $query ) {
        if ( $query->is_category( 'applications' ) && $query->is_main_query() ) {
            $query->set( 'orderby', 'title' );
            $query->set( 'order', 'ASC' );
        }
    }
    add_action( 'pre_get_posts', 'db_abc_modify_query_order' );
    #983366
    Nanette

    This is weird, I have this site on my local for testing and it works on that one. But when I put it in my live site, I still get the same message:
    Don’t Panic
    The code snippet you are trying to save produced a fatal error on line 6:

    Cannot redeclare db_abc_modify_query_order() (previously declared in /www/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code:1)
    The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

    Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.

    Nanette

    #983374
    Nanette

    Okay on a whim, I changed the priority to 9 and it works, but it works on this page:
    https://nir-for-food.com/applications/

    But not on this page:
    https://nir-for-food.com/category/applications/

    Nanette

    #983473
    David
    Staff
    Customer Support

    So on the site you’re seeing the error, can you check to make sure you don’t have two snippets that are declaring the same function. That is what the error is saying.

    the /appications is a page built with WPSP you can set the order that they are displayed in the Settings tab of the list.

    Fix the error above and see of the /category/applications/ is working.

    #983529
    Nanette

    I am so flattered that you think I would understand what WPSP is. :-), but I don’t. I do have another snippet I used for another category for the blog home page called industries. But the error did go away when I made the category for applications at a lower priority than 10 like the other one was. It worked for this page
    https://nir-for-food.com/applications/

    But not for the page you said was built on WSPS, you say I can set the order that they are displayed “in the Settings tab of the list”, could you expound on that for my ignorant ears? Where is that tab?

    Nanette

    #983754
    David
    Staff
    Customer Support

    WPSP = WP Show Posts 🙂
    So Dashboard > WP Show Posts > And edit the lists you want to display alphabetically and within its Settings you can select the order.

    So the other snippet being used is order the Industry archive correctly?

    If that is the case then in your second snippet you need a unique function name ie.

    db_abc_modify_query_order

    there are two instances of this in the code just change them both to eg.

    db_abc_modify_query_order_2

    #983850
    Nanette

    I did change them on top and bottom, like so:
    function db_abc_modify_query_order-2( $query ) {
    if ( $query->is_category( ‘applications’ ) && $query->is_main_query() ) {
    $query->set( ‘orderby’, ‘title’ );
    $query->set( ‘order’, ‘ASC’ );
    }
    }
    add_action( ‘pre_get_posts’, ‘db_abc_modify_query_order-2’ );

    The first instance gave These errors:
    parse error : syntax error, unexpected ‘-‘, expecting ‘(‘ on line 1
    parse error : syntax error, unexpected ‘-‘, on line 1
    parse error : syntax error, unexpected ‘-‘, expecting ‘)’ on line 1
    parse error : syntax error, unexpected ‘-‘, expecting ‘{‘ on line 1
    parse error : syntax error, unexpected ‘{‘, expecting ‘;’ on line 1

    Nanette

    #983860
    David
    Staff
    Customer Support

    Sorry my bad it should read:

    db_abc_modify_query_order_2 ie. replace the hyphen with an underscore.

    #985149
    Nanette

    YEA! Thanks, Dave, Alls Well the ends Well.

    Nanette

    #985530
    David
    Staff
    Customer Support

    Awesome – glad to be of help

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