• I’m certainly no expert on PHP, but I’m attempting to create some conditional logic in sidebar.php to change the CSS class of the sidebar based on the post format of the 1st page.

    Here is what I have so far:

    if ( 'content' != $current_layout ) : ?>
    	<?php if( $wp_query->current_post == 0 && !is_paged() ) : ?>
             <?php if ( has_post_format('video')) :?>
    		<div id="secondary" class="widget-area" role="complementary">
             <?php else: ?>
    
                    <div id="secondary" class="widget-area" role="complementary">
    	<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
    
    				<aside id="archives" class="widget">
    					<h3 class="widget-title"><?php _e( 'Archives', 'twentyeleven' ); ?></h3>
    					<ul>
    						<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
    					</ul>
    				</aside>
    
    				<aside id="meta" class="widget">
    					<h3 class="widget-title"><?php _e( 'Meta', 'twentyeleven' ); ?></h3>
    					<ul>
    						<?php wp_register(); ?>
    						<li><?php wp_loginout(); ?></li>
    						<?php wp_meta(); ?>
    					</ul>
    				</aside>
    
    			<?php endif; // end sidebar widget area ?>
                <?php endif; ?>
                <?php endif; ?>
                <?php endif; ?>
    		</div><!-- #secondary .widget-area -

    As you can see I’m trying to change the CSS class for the sidebar based on whether or not the 1st post on the blog is in the video format.

    Any help or advice would be greatly appreciated!

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

    (@reginalds)

    After further investigation, I have narrowed the code down to:

    <?php if( $wp_query->current_post == 0 && !is_paged() && has_post_format ('video')) :?>

    But this does not seem to work. If I change the code to:
    <?php if( $wp_query->current_post == 0 || !is_paged() || has_post_format ('video')) :?>

    I can get the opposite result but neither is what I am looking for. Could anyone point me to what I’m doing wrong?

Viewing 1 replies (of 1 total)
  • The topic ‘Sidebar class depending on post format of 1st post’ is closed to new replies.