WordPress.org

Ready to get started?Download WordPress

Forums

Custom page with subcategories (4 posts)

  1. LeRah
    Member
    Posted 1 year ago #

    Hi all,

    i would like to make a custom page showing all subcategories of a certain category. also i want to show the latest 5 posts in the subcategory under the subcategory title.

    can anyone help me with this?

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

  3. LeRah
    Member
    Posted 1 year ago #

    thanks i'll check them out, but im no php expert so more help is appreciated.

    using the twentytwelve theme

  4. LeRah
    Member
    Posted 1 year ago #

    nvm i got it working with this code:

    <?php
    	$categories = get_categories('child_of=2');
    
    	foreach ($categories as $cat) {
    		echo "<h3>" . $cat->name . "</h3>";
    
    		query_posts('cat=' . $cat->term_id);
    
    		while (have_posts()) : the_post();
    			?>
    			<a href="<? the_permalink(); ?>" title="<? the_title(); ?>"><? the_title(); ?></a><br />
    			<?php
    		endwhile;
    	};
    ?>

    but when i change the while loop to only show 5 posts it shows the parent category's name instead :S

    is there a better way of doing this??

Topic Closed

This topic has been closed to new replies.

About this Topic