WordPress.org

Ready to get started?Download WordPress

Forums

Category Links (7 posts)

  1. njbair
    Member
    Posted 9 years ago #

    I made a post several days ago asking if there was a way to reconfigure the order in which the category links appear on the main page. Since then I've discovered that the order in which they are arranged in the database is irrelevant. It actually seems to load them alphabetically.
    This being the case, I'm assuming the query uses an "ORDER BY" to pull them up. does anybody know which PHP file contains this query? Thanks.

  2. codergurl
    Member
    Posted 9 years ago #

    template-functions-category.php

  3. aletheia
    Member
    Posted 9 years ago #

    read this http://wiki.wordpress.org/list_cats
    I think you'll find what you need

  4. Anonymous
    Unregistered
    Posted 9 years ago #

    wp_list_cats("sort_order=asc&sort_column=name") should do the trick.

  5. njbair
    Member
    Posted 9 years ago #

    Well I guess there's nothing WP can't do :)
    Thanks all

  6. andrew_h
    Member
    Posted 9 years ago #

    OK here's a related question. The context is the narchives.php hack but I don't think that is significant. If you are creating a page that lists post titles for each category you can set the category order to "asc" and "desc" but can you then define the sort order of the posts within each category (to desc or asc)?
    Andrew

  7. Anonymous
    Unregistered
    Posted 9 years ago #

    Andrew,
    Here's how I did that:
    1. Install the following plugin
    <?php
    /*
    Plugin Name: The Content Category
    Plugin URI: http://wordpress.org/#
    Description: Give you the posts from just one category
    Author: Stewart Ugelow
    Author URI: http://www.ugelow.com/
    Version: 1.0
    */
    function the_content_cat ($template_file, $cat_id, $order) {
    $filepath = get_settings('siteurl')."/".$template_file."?cat=$cat_id&order=$order";
    include($filepath);
    }
    ?>
    2. Create a new file "foo.php" (i.e. whatever you want to call it) with the following:
    <?php
    /* Don't remove this line. */
    require('./wp-blog-header.php');
    ?>
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    //Your content goes here
    //In andrew's case, it would
    //be something like:
    <?php the_title(); ?>
    <?php endforeach; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>
    3. From your main page, use the function from the plugin. If you wanted category #3 to be ascending, you would insert:
    <?php the_content_cat('foo.php',3,"ASC"); ?>
    Hope this helps.
    --Stewart

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.