Post emergency WordPress questions for fast help... ...Or answer questions first & win prize money.

$50
List Title of posts in subcategories

Example:

Sports is a parent category. Soccer is a sub cat of Sports, as is Baseball. I have multiple posts in each (sub) category, and I need the title of those posts to appear as links, grouped by their sub category - with a heading of that sub category name.

This page should display all subcategories which are under the Sports parent category. This is not fixed- it needs to be flexible, so it can't be hard coded. Even a query for the subcats can't be hard coded because if there are no posts for Soccer, then soccer shouldn't show up. If someone starts a frisbee team tomorrow, it needs to show up automatically.

Something like the following:


<h2>Sports</h2>

<h4>Baseball</h4>
<ul>
<li><a href="#">Baseball Team A</a></li>
<li><a href="#">Baseball Team B</a></li>
<li><a href="#">Baseball Team C</a></li>
<li><a href="#">Baseball Team D</a></li>
</ul>

<h4>Frisbee</h4>
<ul>
<li><a href="#">Frisbee Team A</a></li>
<li><a href="#">Frisbee Team B</a></li>
<li><a href="#">Frisbee Team C</a></li>
<li><a href="#">Frisbee Team D</a></li>
</ul>

<h4>Soccer</h4>
<ul>
<li><a href="#">Soccer Team A</a></li>
<li><a href="#">Soccer Team B</a></li>
<li><a href="#">Soccer Team C</a></li>
<li><a href="#">Soccer Team D</a></li>
</ul>


My current code, which I've peiced together based on varius help forms and articles is this:

<?php
global $options;
foreach ($options as $value) {
if (get_option( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; }
else { $$value['id'] = get_option( $value['id'] ); }
}
?>
<?php

if ( is_page('Sports') ) { ?>

<?php query_posts('showposts=0&cat=6'); ?>

<?php global $post; $count = 1;
while ( have_posts() ) : the_post() ?>
<?php $category = get_the_category();
// Get the ID of a given category
$category_id = get_cat_ID( $category[0]->cat_name );

// Get the URL of this category
$category_link = get_category_link( $category_id ); ?>

<h4> <a href="<?php echo $category_link; ?>" title="<?php echo $category[0]->cat_name; ?>"><?php echo $category[0]->cat_name; ?>
<span>view only <?php echo $category[0]->cat_name; ?> &rarr;</span>
</a>

</h4>
<ul>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?>
<?php // This is the implementation of custom write panels.
$data = get_post_meta( $post->ID, 'module', true ); ?>
<span class="listing-entry organization"><?php echo $data[ 'organization' ]; ?></span>
<span class="read-more">(read more)</span>
</a></li>
</ul>
<?php endwhile; ?>

<?php } ?>


And what comes out is each listed title is within it's own <ul>, so rather than all the soccer posts listed together, they are separate, as seen here: http://yatescommunitycenter.org/dev/sports .

Meredith Marsh | 12/27/09 at 8:55pm | RSS Answers | Tags

(2) Possible Answers Submitted...

You must be logged in to view answers or answer this question.