• I am using wordpress to build my portfolio site. Each section is a category. All posts (projects) have only one category (such as “print” or “motion”), unless they are featured on the homepage, in which case, they will have a second category applied to them: “featured.” (Except “sketchbook” which won’t be featured.)

    When you click on a project and are on the single post page, in the sidebar, it lists the other projects that are in the same category. You can also navigate through that category using prev/next buttons.

    The problems:
    1. When you click on a project directly from the homepage (from the featured slideshow), the single posts page is displaying the “featured category” and is listing the featured projects in the sidebar. Instead, I’d like clicking on a project to take you right to the OTHER category it’s in, not the featured category.

    2. When you go directly to a category, say interactive, when you click on a project in the sidebar which is in both interactive AND featured, the sidebar stops displaying the list of interactive projects, and now shows the “featured” list. Again, I’d like featured to be excluded.

    3. Prev/Next buttons in a category start navigating through the featured category as soon as they hit a project that is in both featured and something else, even if you were previously browsing a the other category that project was in.

    In short, the only time I want the “featured” category to be in play and recognized is on the homepage, where it’s being featured, all other times, I’d like wordpress to default to the other category it’s in and forget the “featured” category. I feel like on my single post page, in the sidebar, I need some sort of conditional statement that can loop through all my categories and says, if it’s “category x” AND “featured category”, set it to “category x” but I don’t know how to write that…

    Does anyone have an ideas about this? or know how to write that loop…? I tried to exclude the id of the featured category in the query but that didn’t seem to do anything.

    My site url is
    http://www.ankatankdesign.com/makes

    (I realize that the featured images are all the same and don’t correspond to the post, but the text beneath them does, and this is just for testing..)

    Here is the code that’s in my sidebar:

    <?php 	
    
    		$IDOutsideLoop = $post->ID;
    		global $post;
    		$category = get_the_category();
    
    		$myposts = get_posts('showposts=-1&exclude=202&category_name=' . $category[0]->cat_name);
    
    		foreach($myposts as $post) : ?>
    
           <?php
                    if(is_single() && $IDOutsideLoop == $post->ID) { ?>
    
                       <li class="sidebarLINKS"><span class="current"><?php the_title(); ?></span>
    
                    <?php } else { ?> 
    
                       <li class="sidebarLINKS"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    
                    <?php } ?> 
    
            </li> <br />
    
    		<?php endforeach; ?>
    </ul>

    Thanks in advance!

  • The topic ‘Exclude A Category From Single Post Page List in Sidebar’ is closed to new replies.