• I’m creating a website that has two menus – a main header menu and a side menu. The side menu changes according to the category of the current post.

    The current category setup is:
    Products
    -Product 1
    –Description
    –Advantages
    -Product 2
    –Description
    –Advantages
    -Product 3
    –Description
    –Advantages

    If I’m in a post that is in Description, I would like to show the side menu as the current and sibling category – Description and Advantages of that product.

    Next, once I show the the Description and Advantages, I’d like for each of them to link to the first post in that category (rather than to the category itself).

    Until now, I’ve used a combination of different codes from different areas. This is what I’d like to create:

    <br />
    <?php List current and sibling category of current post (subcategories of parent) ?><br />
    	<href="1st post of subcategory"><?php Subcategory name ?></a><br />

    This is where I am (which isn’t very far!):

    </p>
    <ul>
    <?php<br />
    $category = get_the_category();<br />
    echo $category[0]->cat_name;</p>
    <p>wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=0&child_of='.$category->post_parent.'&echo=0'); ?>
    </ul>
    <p>

    I’m great at understanding how the code works, but not very good at devising it!!
    Any help would be greatly appreciated!

Viewing 1 replies (of 1 total)
  • Thread Starter aputt

    (@aputt)

    So far, I’ve gotten to the point of showing the current and sibling categories. Still need to apply the link to the first post.

    <ul style="list-style:none;">
    	<?php
    	foreach($category as $cat)
    	{
    		if($cat->category_parent!='0')
    		{
    
    			$this_category = wp_list_categories('orderby=id&hide_empty=0&title_li=&child_of='.$cat->category_parent."&echo=0");
    			//echo "<pre>";print_r($this_category);die("hhhhh");
    		}
    
    		?>
    			<?php
    			if($cat->category_parent=='0') {
    			?>
    			<li><?php echo get_cat_name($cat->cat_ID);?>
    			<?php } ?>
    			<li>
    			<?php   if($this_category && $cat->category_parent!='0') { ?>
    			<ul style="list-style:none;">
    			<?php echo $this_category;?>
    			</ul>
    			<?php } ?>
    			</li>
    	<?php }
    	?>
    
    </ul>
Viewing 1 replies (of 1 total)
  • The topic ‘Listing current and sibling categories and creating a link to the first post’ is closed to new replies.