• Hi

    I run a town site at:
    Lostwithiel.

    The site lists businesses under categories and sub-cats. For instance we have Shops as the main cat and Antiques as a sub cat. Currently in the sidebar when a main cat is clicked a fold down list reveals the sub cats. In the content at the same time are listed all the businesses within the main cat. What I would like to do if possible is on clicking on a main cat we still get the fold down list in the sidebar but in the content we get a list of the sub cats and the businesses associated with those sub cats.

    For an idea on what currently happens take a look at:
    Lostwithiel Services

    I hope this is possible please and thanks for your help.

    Rich

Viewing 1 replies (of 1 total)
  • Thread Starter Richard Brown

    (@cregy)

    Hi

    I found my answer. After looking in the forums I turned to Google and found the answer immediately (in this forum). Sorry.
    List posts by child categories (11 posts)

    The only trouble I’m now having is combining the code in that post:

    <?php
    global $wpdb;
    $categories = $wpdb->get_results("SELECT $wpdb->terms.term_id AS id, name, description from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE parent = '$cat' ORDER BY name ASC");
    foreach($categories as $category) :
    ?>
    
    <h2><?php echo $category->name; ?></h2>
    <a href="<?php echo get_category_link($category->id);?>"><b><?php echo $category->description; ?></b></a>
    <?php global $post;
    $myposts = get_posts("category=$category->id");
    foreach($myposts as $post) : setup_postdata($post);
    ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
    <?php endforeach; ?>
    <?php endforeach; ?>

    With this code which I use to make two columns:

    <h2>Emergency Services</h2>
    
    <?php $column = 1; ?>
    
    	<?php if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    
    <?php if ($column == 1) echo "<div class=\"row\">"; ?>
    
    <div class="post column<?php echo $column;?>" id="post-<?php the_ID(); ?>">
    <h3><?php the_title(); ?></h3>
    <a href="<?php the_permalink(); ?>"><img src="<?php post_image('https://lostwithiel.org.uk/wp-content/themes/blank3/images/posticon.png', false, false); ?>" width="60" height="80" /></a>
    <?php the_content() ?>
    </div>
    
    <?php if ($column == 1) echo "</div>"; (($column==1) ? $column=2 : $column=1); endwhile; ?>
    
    <?php else : ?>

    Can anybody help please?

    Thanks

    Rich

Viewing 1 replies (of 1 total)
  • The topic ‘Directory Hack’ is closed to new replies.