• I am using the the query_posts() function as I want to use orderby=rand

    I am using this on the category template but all my posts show up. How would I be able to add the cat ID dynamically to this:

    <?php $my_querycat = new WP_Query('orderby=rand&cat=');

    Thank you,
    Steve

Viewing 1 replies (of 1 total)
  • You can’t as there is no support for ordering posts by category in query_posts().

    But might use something like this:

    <?php
    $categories=get_categories('orderby=name&order=ASC');
      foreach($categories as $category) {
          $posts=get_posts('showposts=-1&cat='. $category->term_id);
          if ($posts) {
            echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
            foreach($posts as $post) {
              setup_postdata($post); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
              <?php
            } // foreach($posts
          } // if ($posts
        } // foreach($categories
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘How to add cat id to loop’ is closed to new replies.