• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Sorting Category Posts Alphabetically

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Sorting Category Posts Alphabetically

This topic is: resolved

Tagged: alphabetically, archive, category, sorting

  • This topic has 13 replies, 4 voices, and was last updated 13 years, 4 months ago by Kent.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • December 11, 2012 at 8:53 am #4490
    Kent
    Participant

    Site I'm working on is here: http://www.ibsltd.ca/pub/fredericton_royals/

    I found this code over on in the old Forums to sort category posts alphabetically. What I'm lost on is how/what I insert to sort only SPECIFIC category archives alphabetically. I know I have to put in the category IDs, but my syntax knowledge isn't good enough to know where.

    add_action('template_redirect', 'child_conditional_actions');
    /** Loads Conditional Actions after the Query is formed before the template is loaded **/
    function child_conditional_actions() {
    if( is_category() ) {
    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'child_do_abc_loop');
    }
    }

    /**Loads Custom Loop to make query sort Alphabetically**/
    function child_do_abc_loop() {
    genesis_custom_loop( array( 'orderby' => 'title', 'order' => 'DESC' ) );
    }

    Also, I tried to use HTML on the code above to format it differently and it didn't work. What's the preferred/best practice for inserting snippets of code into these forums?

    Thanks,
    -Kent


    Dad. Biker. Designer. | kentfackenthall.com

    December 11, 2012 at 9:07 am #4495
    John
    Participant

    Hi Kent,

    When in doubt, I nearly always go to the WordPress Codex and search for the function or whatever it is I have a question on. I think you'll find your answer on this Codex page in the examples:ย http://codex.wordpress.org/Function_Reference/is_category

    And for inserting code here in the forums, after I type or paste it in I switch over to the HTML tab, select the code, and click on the "code" button in the toolbar. Your code needs to be single-spaced for it to work, but I've found that I can switch back and forth from Visual to HTML and the code styling stays there. Here's an example (from that Codex page):

    is_category( '9' );
    // When the archive page for Category 9 is being displayed.

    John


    John Sundberg | blackhillswebworks.com
    A WordPress developer’s toolbox: Firebug | WordPress Codex | Google ๐Ÿ˜‰

    December 11, 2012 at 9:29 am #4498
    Kent
    Participant

    John,

    Thanks for the scoop. I'm noticing some differences in the code.

    Does it matter if I use 'in_category' or 'is_category'? There's both in my functions.php already. I'm curious if there's a distinction or if they will both do the same thing.

    -Kent


    Dad. Biker. Designer. | kentfackenthall.com

    December 11, 2012 at 9:55 am #4502
    Kent
    Participant

    John,

    I've tried it out, it's actually breaking the archive. now the page isn't listing any posts from the category at all, rather all the posts from other categories. If you look atย http://www.ibsltd.ca/pub/fredericton_royals/category/players/a/, it's supposed to be an archive for category 51, but actually there's no posts from that category at all. Weird. Here's the code I put in functions.php:

    /** Sort Specific Category Posts Alphabetically **/
    add_action('template_redirect', 'child_conditional_actions');
    /** Loads Conditional Actions after the Query is formed before the template is loaded **/
    function child_conditional_actions() {
    if( is_category( array( '50', '51' ) )) {
    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'child_do_abc_loop');
    }
    }
    /**Loads Custom Loop to make query sort Alphabetically**/
    function child_do_abc_loop() {
    genesis_custom_loop( array( 'orderby' => 'title', 'order' => 'DESC' ) );
    }

    I'm going to keep hacking away at it.


    Dad. Biker. Designer. | kentfackenthall.com

    December 11, 2012 at 10:24 am #4509
    John
    Participant

    It looks like if you're using an array you need to NOT put the single-quote around the ID. Check out the example from the Codex:

    is_category( array( 9, 'blue-cheese', 'Stinky Cheeses' ) );
    // Returns true when the category of posts being displayed is either term_ID 9, or slug "blue-cheese", or name "Stinky Cheeses".


    John Sundberg | blackhillswebworks.com
    A WordPress developer’s toolbox: Firebug | WordPress Codex | Google ๐Ÿ˜‰

    December 11, 2012 at 10:40 am #4512
    Kent
    Participant

    Yep. Still not working.

    I've tried with and without quotes, using 'in' category and 'is' category. Nada. must be something else. I'm not sure what's up. Funny, because I have this function right above it and it works fine:

    // Customize the post info function
    add_filter('genesis_post_info', 'post_info_filter');
    function post_info_filter($post_info) {
    if (in_category( array( '4', '8', '5', '6', '7' ) )) {
    $post_info = '[post_date] [post_edit]';
    return $post_info;
    }}

    I'll keep digging. ๐Ÿ™‚


    Dad. Biker. Designer. | kentfackenthall.com

    December 11, 2012 at 11:29 am #4528
    John
    Participant

    in_category lets you check if a post or posts are in a specific category, then you can do stuff with those posts.

    is_category checks if a specific category (or categories) archive is being displayed, then lets you do stuff with those categories.


    John Sundberg | blackhillswebworks.com
    A WordPress developer’s toolbox: Firebug | WordPress Codex | Google ๐Ÿ˜‰

    December 11, 2012 at 12:03 pm #4535
    John
    Participant

    Kent,

    I would try this:

    Make a copy of page.php from your Genesis directory, and rename it category.php

    In that file, above the ending genesis(); function, add this code:

    if is_category( 'players' ) {
    // Customize the Loop
    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'players_category_order_custom_loop' );
    function players_category_order_custom_loop() {
    global $paged;
    $args = array( 'order' => 'ASC','orderby' => 'name','paged' => $paged );
    // Accepts WP_Query args (http://codex.wordpress.org/Class_Reference/WP_Query)
    genesis_custom_loop( $args );
    } // Endย players_category_order_custom_loop
    } // End is_category( 'players' )

    You could clean that up with some line breaks and indenting, but the code editor here won't let us do that.

    You may also want to flush your permalinks: go to Settings > Permalinks and click "Save Changes"

    John


    John Sundberg | blackhillswebworks.com
    A WordPress developer’s toolbox: Firebug | WordPress Codex | Google ๐Ÿ˜‰

    December 11, 2012 at 12:08 pm #4536
    John
    Participant

    Oh, and these two Codex articles on categories should be helpful:

    Alphabetizing Posts

    Category Templates


    John Sundberg | blackhillswebworks.com
    A WordPress developer’s toolbox: Firebug | WordPress Codex | Google ๐Ÿ˜‰

    December 11, 2012 at 2:58 pm #4560
    nickthegeek
    Member

    Something else to check out

    Customizing the WordPress Query with pre_get_posts

    January 10, 2013 at 4:46 pm #11054
    bluefrogj
    Member

    I must admit I'm trying the same thing and it's not working at all. I've been playing with it for 2 days and can't get it to work. I've read the Alphabetizing Posts codex before finding this thread created a template file named category-58.php with the following code:

     

    
    <?php
    get_header();
    ?>
    
    <div id="content">
    
    <?php
    // we add this, to show all posts in our
    // Glossary sorted alphabetically
    $posts = query_posts($query_string .
    '&orderby=title&order=asc&posts_per_page=-1');
    // here comes The Loop!
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    genesis();
    
    

    That's direct from WP's site. Breaks the page and I get a 500 error.

    I"ve read about category templates. Understand them. I just can't get this to work. I'm not great at this, but I was able to figure out enough to build some custom taxonomies and to widgetize a couple of page templates...and to sort order some custom post types. But not specific categories. <sigh> I'm doing something wrong too. Anyone found a solution yet?

     

    February 12, 2013 at 1:09 pm #19870
    Kent
    Participant

    @bluefrogj,

    I had to put this project down for awhile, but have to get back to it shortly. Did you ever get it working? I'll have to review the above and see how it goes.

    -Kent


    Dad. Biker. Designer. | kentfackenthall.com

    February 13, 2013 at 7:39 am #20055
    John
    Participant

    Hey Kent,

    Just checked out your blog - how are you liking the Pugsley? I've got a Salsa Fargo myself that I ride/commute with year-round here in South Dakota, swapping wheels/tires back and forth depending on the snow and ice conditions.

    John


    John Sundberg | blackhillswebworks.com
    A WordPress developer’s toolbox: Firebug | WordPress Codex | Google ๐Ÿ˜‰

    February 13, 2013 at 7:52 am #20056
    Kent
    Participant

    John,

    Nice! Those Fargos are pretty cool. I've been commuting a bunch of years now, mostly on a Cross Check but I've always lusted for the fatbike. I've only had it out twice so far, but it was a blast! I'm really looking forward to a regular commute on it.

    I don't know if you're on Google+ at all, but there's a real vibrant Bike Commuting Community over there sharing tips, tales and encouragement - a good deal of them hearty winter commuters as well. You might want to check it out! I spend my days over there! ๐Ÿ™‚

    Cheers!
    -Kent

     


    Dad. Biker. Designer. | kentfackenthall.com

  • Author
    Posts
Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble