• How easy would it be to make a category page into an index page showing each sub category and 1 post from that sub category.

    Ie a bit more like a home page.

    If you read this and dont quite understand my question but would like to help, please post up and Ill try to reword it to explain better.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Something like this could work:

    <?php
    //for child categories of category id 7, show 1 post
    $cat_args=array(
      'child_of' => 7
       );
    $categories=get_categories($cat_args);
      foreach($categories as $category) {
        $args=array(
          'showposts' => 1,
          'category__in' => array($category->term_id),
          'caller_get_posts'=>1
        );
        $posts=get_posts($args);
          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
    ?>

    Thread Starter kilpatrick

    (@kilpatrick)

    Thankyou Michael, I am working on quite a large project to tie several wordpress installations and some htms pages together and put them all in one installation.

    some of My category pages will need to be an index page for the sub categories in that category. Whilst other categories wont have sub categories so will just show the most recent posts.

    Will your suggestion do this. I will be getting on with the project in the coming days. I have no understanding of coding but am able to edite, cut and paste stuff into template files.

    Cheers – Glenn

    You will need to review Template Hierarchy and Category Templates to get a feel for how WordPress determines what template to use when displaying posts.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates

    Thread Starter kilpatrick

    (@kilpatrick)

    Looks kind of interesting although Im sure it will be really difficult for me. Having read your links it looks like I can use category slugs in wp2.9 to direct WP to use a certain template.

    So with this in mind I can set up category themes for certain categories and call them in using the slugs ?

    i AM THINKING i CAN THEN USE YOUR SUPPLIED CODE ABOVE to make some category pages that show posts exceprts from each sub category, or selected sub cataegories. As my news category has about 20 sub categories I would probably just want to show about 10 of them on news category page

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to make the category page into an index page’ is closed to new replies.