ThemeShaper Forums » Thematic

[closed]

a function to change the order of posts in a category?

(10 posts)
  • Started 4 years ago by lastraw
  • Latest reply from butters81
  • This topic is resolved
  1. Hi all,

    I have this code on a template page to put posts from a single category (16 in this case)in a multi column layout, and it works, except it arranges the posts by date instead of alpha. I'm assuming there is a function for this kind of thing?

    Thank you!

    Leslie

    <div id="column_01">
    
    <!-- FIRST LOOP: display posts 1 thru 5-->
    <?php query_posts('showposts=5&cat=16'); ?>
    <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>
    <div style="entry-title"><?php the_title(); ?></div>
    <?php the_content(); ?>
    <?php $count1++; } ?>
    <?php endforeach; ?>
    </div>
    
    	<div id="column_02">
    
    <!-- SECOND LOOP: display posts 6 thru 10-->
    <?php query_posts('showposts=5&cat=16'); ?>
    <?php $posts = get_posts('numberposts=5&offset=5'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count2 = 0; if ($count2 == "5") { break; } else { ?>
    <div style="entry-title"><?php the_title(); ?></div>
    <?php the_content(); ?>
    <?php $count2++; } ?>
    <?php endforeach; ?>
    </div>
    <div id="column_03">
    
    <!-- THIRD LOOP: display posts 11 thru 15-->
    <?php query_posts('showposts=6&cat=16'); ?>
    <?php $posts = get_posts('numberposts=5&offset=10'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count3 = 0; if ($count3 == "5") { break; } else { ?>
    <div style="entry-title"><?php the_title(); ?></div>
    <?php the_content(); ?>
    <?php $count3++; } ?>
    <?php endforeach; ?>
    </div>
    Posted 4 years ago #
  2. I found this in the codex but I can't seem to combine it with the above code to make it work. If anyone has any ideas I would REALLY appreciate it.

    Thanks,
    Leslie

    <?php
    // we add this, to show all posts in our
    // Glossary sorted alphabetically
    if (is_category('Glossary'))
    {
         $posts = query_posts($query_string .
    '&orderby=title&order=asc');
    }
    // here comes The Loop!
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    Posted 4 years ago #
  3. Just add

    &orderby=title&order=asc

    to the query_posts functions.

    <?php query_posts('showposts=5&cat=16&orderby=title&order=asc'); ?>
    Posted 4 years ago #
  4. Hi arturkim,

    I appreciate you responding, but it still isn't working.

    Here is the first part of the file, I wonder if it has something to do with using query_posts outside the main loop?

    <?php
    /*
    Template Name: Clients
    
    */
    ?>
    <?php
    
        // calling the header.php
        get_header();
    
        // action hook for placing content above #container
        thematic_abovecontainer();
    
    ?>
    	<div id="container-full">
    		<div id="content-full">
    <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class() ?>">
          <?php // creating the post header
                    thematic_postheader();
    ?>
          <div class="entry-content">
            <?php the_content();
                         ?>
    
          </div>
        </div>
    Posted 4 years ago #
  5. Sorry to bump this, but my deadline approacheth!
    arturkim's suggestion should have worked?

    Posted 4 years ago #
  6. Hi lastraw-

    It's always challenging coming in in the middle of an issue and getting it right. Zip and email the template in question & I'll take a look.

    -Gene

    Posted 4 years ago #
  7. Thank you Gene, I sent the template and the function file. I really appreciate you taking the time to take a look.

    Leslie

    Posted 4 years ago #
  8. Hi Leslie,

    I took a look at your functions.php and there's nothing in there that is at odds with what you are trying to do here.

    Try this variation of the code you multicolumn loop that you posted:

    <!-- FIRST LOOP: display posts 1 thru 5-->
    <?php query_posts('showposts=5'); ?>
    <?php $posts = get_posts('numberposts=5&offset=0&orderby=title&order=asc&cat=16'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>
    <div class="entry-title"><?php the_title(); ?></div>
    <?php the_content(); ?>
    <?php $count1++; } ?>
    <?php endforeach; ?>
    </div>
    
    <div id="column_02">
    
    <!-- SECOND LOOP: display posts 6 thru 10-->
    <?php query_posts('showposts=5'); ?>
    <?php $posts = get_posts('numberposts=5&offset=5&orderby=title&order=asc&cat=16'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count2 = 0; if ($count2 == "5") { break; } else { ?>
    <div class="entry-title"><?php the_title(); ?></div>
    <?php the_content(); ?>
    <?php $count2++; } ?>
    <?php endforeach; ?>
    </div>
    <div id="column_03">
    
    <!-- THIRD LOOP: display posts 11 thru 15-->
    <?php query_posts('showposts=6'); ?>
    <?php $posts = get_posts('numberposts=5&offset=10&orderby=title&order=asc&cat=16'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count3 = 0; if ($count3 == "5") { break; } else { ?>
    <div class="entry-title"><?php the_title(); ?></div>
    <?php the_content(); ?>
    <?php $count3++; } ?>
    <?php endforeach; ?>
    </div>
    Posted 4 years ago #
  9. YAY! Thank you sooooo much Gene.

    Leslie

    Posted 4 years ago #
  10. butters81
    Member

    I ran into the similar problem trying to get WP/Thematic to sort a couple of my categories alphabetically.

    This is a nice little filter function I found elsewhere on the forum, which displays all the posts for one category (54) and I've added alphabetical sorting for categories 5 and 10. Add this to your functions.php:

    function show_all_post_in_cat() {
      if (is_category('54')) {
    query_posts('cat=54&posts_per_page=-1&order=asc&orderby=title');
      }
      if (is_category(array(5,10))) { //order alphabetically
      global $query_string;
    query_posts($query_string . '&order=asc&orderby=title');
      }
    }
    add_action('thematic_above_categoryloop','show_all_post_in_cat');

    Useful info about $query_string here:
    http://codex.wordpress.org/Function_Reference/query_posts#Usage_Note

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.