WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post from category in sidebar (2 posts)

  1. gurupidal
    Member
    Posted 6 years ago #

    Hi,

    I'm building a review site that is about Disney theme parks. Each resort is a category (ie 7 cats). I've been searching an not getting far for the past 2 weeks trying to solve the problem, so here it is.
    I have 2 versions of the same sidebar. One version displays recent posts from a category. The other the intention is to display posts from the same category the current post is on.
    I've been using is_category and in_category on the 2 versions.
    The main problem I have hit is that on the in-category version I end up with lists of all categorys or none.
    the link is http://www.disney-links.com/linksreview
    If you click on a post from the WDW category you'll get a list from WDW and DLR and DLRP in the sidebar. In the loop these are assigned as in_category all other cats are assigned as is_category.
    DLRP seems to work fine possibly as this is the last in the run being in_category.

    <?php
    // Walt Disney World
     	 if (in_category('6')) : ?>
            <u>Walt Disney World related sites</u>
            <?php
        $my_query = new WP_Query('cat=6&showposts=15'); ?>
            <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <li><a>" href="<?php the_permalink() ?>"><?php the_title(); ?></a><br/></li>
          <?php endwhile; ?>
          <?php endif; ?>
          <?php
    // Disneyland Resort
     	 if (in_category('7')): ?>
        <u>Disneyland Resort related sites</u>
    <?php
        $my_query = new WP_Query('cat=7&showposts=15'); ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <li><a>" href="<?php the_permalink() ?>"><?php the_title(); ?></a><br/></li>
          <?php endwhile; ?>
          <?php endif; ?>
          <?php
    // Disneyland Resort Paris
     	if (in_category('8')) : ?>
          <u>Disneyland Resort Paris related sites</u>
        <?php
        $my_query = new WP_Query('cat=8&showposts=15'); ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <li><a>" href="<?php the_permalink() ?>"><?php the_title(); ?></a><br/></li>
              <?php endwhile; ?>
          <?php endif; ?>
          <?php
    // Toyko Disneyland
     	if (is_category('9')) : ?>
          <u>Tokyo Disneyland related sites</u>
       <?php
        $my_query = new WP_Query('cat=9&showposts=15'); ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <li><a>" href="<?php the_permalink() ?>"><?php the_title(); ?></a><br/></li>
              <?php endwhile; ?>
          <?php endif; ?>
          <?php
    // Hong Kong Disneyland
     	if (is_category('10')) : ?>
          <u>Hong Kong Disneyland related sites</u>
        <?php
        $my_query = new WP_Query('cat=10&showposts=15'); ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <li><a>" href="<?php the_permalink() ?>"><?php the_title(); ?></a><br/></li>
              <?php endwhile; ?>
          <?php endif; ?>
          <?php
    // Disney Cruise Lins
     	if (is_category('11')) : ?>
          <u>Disney Cruise Line related sites</u>
          <?php
        $my_query = new WP_Query('cat=11&showposts=15'); ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <li><a>" href="<?php the_permalink() ?>"><?php the_title(); ?></a><br/></li>
              <?php endwhile; ?>
          <?php endif; ?>
          <?php
    // Disney Vacation Club
     	if (is_category('12')) : ?>
          <u>      Disney Vacation Club related sites</u>
         <?php
        $my_query = new WP_Query('cat=12&showposts=15'); ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <li><a>" href="<?php the_permalink() ?>"><?php the_title(); ?></a><br/></li>
              <?php endwhile; ?>
          <?php endif; ?>
  2. gurupidal
    Member
    Posted 6 years ago #

    I added the rewind loop tag and it seems to half solve the problem.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags