ThemeShaper Forums » Thematic

[closed]

automatically check for new categories

(2 posts)
  • Started 3 years ago by janis
  • Latest reply from janis
  • This topic is resolved
  1. janis
    Member

    hi

    I'm trying to group my post by category and display them all on the the same page. the code below functions the way I would like, but I would really like it if i didn't have go back and manually add a group each time a new category is created?

    is there any way to get the code below to check for new categories and add a group each time a category is created?

    --what i have figured out so far.--

    function test5_loop(){
    echo '<div class="group1">';
    $my_query = new WP_Query('cat=5');
    while ($my_query->have_posts()) : $my_query->the_post();
    echo '<div class="TB1">';
    echo get_the_post_thumbnail(NULL, 'thumbnail');
    echo '</div>';
    //echo "group1";
    endwhile;
    echo '</div>';
    
    echo '<div class="group2">';
    $my_query = new WP_Query('category_name=bathrooms');
    while ($my_query->have_posts()) : $my_query->the_post();
    echo '<div class="TB2">';
    echo get_the_post_thumbnail(NULL, 'thumbnail');
    echo '</div>';
    //echo "group 2";
    endwhile;
    echo '</div>';
    }
    
    add_action('thematic_indexloop', 'test5_loop');

    thanks for the help
    j

    Posted 3 years ago #
  2. janis
    Member

    hi everyone,

    With some major guessing :) i figured out.

    <?php
    function test6_loop(){
    $category_ids = get_all_category_ids();
    	foreach($category_ids as $cat_id) {
    	$cat_name = get_cat_name($cat_id);
    	echo $cat_id . ': ' . $cat_name;
    
    	$topic=$cat_name;
    
    echo '<div class="gallery_';
    echo $cat_name;
    echo'">'; 
    
    query_posts('category_name='.$topic.'&posts_per_page=10');
    	while (have_posts()) : the_post();
    		echo '<div class="TB_';
    		echo $cat_name;
    		echo '">';
    
           	the_post_thumbnail();
    
            echo '</div><!--closethumbnail-->';
    
            //the_content();
    	endwhile;
    
    echo '</div><!--closegallery-->';
    }
    }
    
    add_action('thematic_indexloop', 'test6_loop');
    ?>
    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.