• Resolved corelli

    (@corelli)


    Hi folks.. this has had me stumped for a bit now.

    I am trying code a special kind of sidebar for a gallery page. I want the sidebar to call the posts in a specific category, and display a thumb of that post (using custom fields).

    I can get this to work with limited results. In the following code, it seems that the first “if” statement is the only one being executed. When I click on category-4 the content of said sidebar will display the content of the first “if” statement (category-3)

    Here is my markup:

    <div id="gallery_sidebar">
    			<ul>
    			<?php 	/* Widgetized sidebar, if you have the plugin installed. */
    					if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    
    			<!-- Author information is disabled per default. Uncomment and fill in your details if you want to use it.
    			<li><h2>Author</h2>
    			<p>A little something about you, the author. Nothing lengthy, just an overview.</p>
    			</li>
    			-->
    		<div class="widget">
    			<div class="inside">
    
    			<li>
    				<h2>Personal Animation</h2>
    				<ul>
    
    				<!-- this handy doo-dad displays posts only from a user specified category in the custom sidebar, STUPENDOUS!  -->
    				<?php /* If this is a category archive */ if (in_category('3'))  {?>
    				<?php $recent = new WP_Query("cat='3'&showposts=10"); while($recent->have_posts()) : $recent->the_post(); ?>
    <div class="galthumb">
    <li><a href="<?php the_permalink() ?>" rel="bookmark">
    <img src="<?php echo get_post_meta($post->ID, "Post_Thumb", true);?>" />	<!-- this will call a custom field from WP to display a thumbnail dynamically in the corresponding post title in the gallery sidebar -->
    
    </a></li>
    </div> 
    
    <?php endwhile; ?>
    <?php } ?>
    
    				<?php /* If this is a category archive */ if (in_category('4'))   {?>
    				<?php $recent = new WP_Query("cat='4'&showposts=10"); while($recent->have_posts()) : $recent->the_post();   ?>
    <div class="galthumb">
    <li><a href="<?php the_permalink() ?>" rel="bookmark">
    <img src="<?php echo get_post_meta($post->ID, "Post_Thumb", true);?>" />	<!-- this will call a custom field from WP to display a thumbnail dynamically in the corresponding post title in the gallery sidebar -->
    
    </a></li>
    </div>
    <?php endwhile; ?>
    <?php } ?>
    				</ul>
    			</li>
    
    <?php endif; ?>			
    
    		</ul>
    	</div>
Viewing 1 replies (of 1 total)
  • Thread Starter corelli

    (@corelli)

    Well, i believe i’ve solved this if anyone is wondering.

    <?php rewind_posts(); ?>

    that code needed to be present before each if statement. I’m sure someone much smarter than I will be able to post why this is the case. But for now, I’m not going to look a gift-horse in the mouth ??

Viewing 1 replies (of 1 total)
  • The topic ‘different posts by category in sidebar’ is closed to new replies.