- This topic has 12 replies, 2 voices, and was last updated 1 year, 6 months ago by
David.
-
AuthorPosts
-
August 8, 2019 at 5:33 pm #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
August 9, 2019 at 2:36 am #979647David
StaffCustomer SupportHi 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 useis_category( 'cat-slug' )
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 13, 2019 at 12:22 pm #983322Nanette
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
August 13, 2019 at 12:38 pm #983340David
StaffCustomer SupportSo 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' );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 13, 2019 at 1:07 pm #983366Nanette
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
August 13, 2019 at 1:15 pm #983374Nanette
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
August 13, 2019 at 3:53 pm #983473David
StaffCustomer SupportSo 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.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 13, 2019 at 6:06 pm #983529Nanette
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
August 14, 2019 at 3:36 am #983754David
StaffCustomer SupportWPSP = 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
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 14, 2019 at 6:06 am #983850Nanette
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 1Nanette
August 14, 2019 at 6:30 am #983860David
StaffCustomer SupportSorry my bad it should read:
db_abc_modify_query_order_2
ie. replace the hyphen with an underscore.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 15, 2019 at 1:28 pm #985149Nanette
YEA! Thanks, Dave, Alls Well the ends Well.
Nanette
August 16, 2019 at 3:48 am #985530David
StaffCustomer SupportAwesome – glad to be of help
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.