• Resolved calebo

    (@calebo)


    Can someone help me with the code below, I’m a designer and not too familiar with php.

    <ul>
    				<?php
    				// get all the categories from the database
    				$cats = get_categories(); 
    
                    // loop through the categries
                    foreach ($cats as $cat) {
                        // setup the category ID
                        $cat_id = $cat->term_id;
                        // Make a header for the cateogry
                        echo "<li>".$cat->name."</li>";
                        // create a custom wordpress query
                        query_posts("cat=$cat_id&post_per_page=10");
                        // start the wordpress loop!
                        if (have_posts()) : while (have_posts()) : the_post(); ?>
                            <?php // create our link now that the post is setup ?>
                            <li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
                        <?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
                    <?php } // done the foreach statement ?>
    			</ul>

    I actually want it to print…
    – Link to category
    – Instead of post title, just increments of 1,2,3.
    – post nested within category.

    How can I get it to print like the below….

    <ul>
    	<li><a href="">category name</a>
                 <ul>
                      <li><a href="/">1</a></li>
                      <li><a href="/">2</a></li>
                      <li><a href="/">3</a></li>
                 </ul>
            </li>
    	<li><a href="">category name 2</a>
                 <ul>
                      <li><a href="/">1</a></li>
                      <li><a href="/">2</a></li>
                      <li><a href="/">3</a></li>
                 </ul>
            </li>
    </ul>

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to link to category and list post under category’ is closed to new replies.