Support » Fixing WordPress » My "is_archive" seems to be not working right

  • Resolved David Borrink

    (@davidborrink)


    I have my loop set up to have excerpts for home, search, and categories. My featured image is to be centered below the title and above the excerpt. This works for home, for search, but for categories my image is to the left.

    What baffles me is that my code clearly uses several if/elseif statements with conditional tags, yet my category is not working right. I use “is_archive()” for the category portion, but no change. I’ve even tried “is_category()”.

    Could someone help point out what I’m missing here? I know I’m missing the obvious, but it says on the Conditional Tags page…

    Any Archive Page

    is_archive()
    When any type of Archive page is being displayed. Category, Tag, other Taxonomy Term, custom post type archive, Author and Date-based pages are all types of Archives.

    Here’s my code for that section from content.php……

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    	<div class="entry-summary">
    	<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'aligncenter')); ?></a><?php the_excerpt(); ?>
    </div><!-- .entry-summary -->
    
    <?php elseif ( is_home() ) : // Only display Excerpts for Search ?>
    	<div class="entry-summary">
    	<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'aligncenter')); ?></a><?php the_excerpt(); ?>
    </div><!-- .entry-summary -->
    
    <?php elseif ( is_archive() ) : // Only display Excerpts for Search ?>
    	<div class="entry-summary">
    	<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'aligncenter')); ?></a><?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    
    <?php else : ?>
    <div class="entry-content">
    	<?php the_content( __( 'continue reading <span class="meta-nav">→</span>', 'twentytwelve' ) ); ?>
    	<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    </div><!-- .entry-content -->
    
    <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Vernon Grant

    (@vernonrant)

    Hi David,

    I think I might have miss read your question lol. So your using this peace of code as an include file to run across your themes files, archive.php, search.php… Let me take a look and get back to you.

    Thanks, Vernon

    Vernon Grant

    (@vernonrant)

    Hi David.

    I placed your code into a single PHP file. After that I included the file into the loop of the following files: index.php, archive.php and search.php I also places a unique echo statement in each condition and got back the expected results. Your code seems to work just fine for me.

    Thanks, Vernon

    David Borrink

    (@davidborrink)

    Strange. This isn’t working here. Well, here’s the full content.php file (this is a child theme off of TwentyTwelve), and here’s a link to the site.

    Try the category links in the bottom widgets (center column) and you’ll see that I get a alignleft image. I cannot figure out why.

    <?php
    /**
     * The default template for displaying content
     *
     * Used for both single and index/archive/search.
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    ?>
    	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
    		<div class="featured-post">
    			<?php _e( 'Featured post', 'twentytwelve' ); ?>
    		</div>
    		<?php endif; ?>
    		<header class="entry-header">
    			<?php the_post_thumbnail(); ?>
    			<?php if ( is_single() ) : ?>
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    
    			<div class="entry-meta">
    				<?php twentytwelve_posted_on(); ?>
    			</div><!-- .entry-meta -->
    
    			<?php else : ?>
    			<h1 class="entry-title">
    				<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
    			</h1>
    
    			<div class="entry-meta">
    				<?php twentytwelve_posted_on(); ?>
    			</div><!-- .entry-meta -->
    
    			<?php endif; // is_single() ?>
    
    		</header><!-- .entry-header -->
    
    		<?php if ( is_search() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'aligncenter')); ?></a><?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    		<?php elseif ( is_home() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'aligncenter')); ?></a><?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    		<?php elseif ( is_archive() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'aligncenter')); ?></a><?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    		<?php else : ?>
    		<div class="entry-content">
    			<?php the_content( __( 'continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>
    
    		<?php if ( is_single() ) : // Subscription box only on single pages ?>
    		<div id="header-widget">
    <?php
                            /* ad sidebar */
                            if ( ! is_404() ) : ?>
                                    <div id="ad-widget" class="widget-area-nine-content">
                                            <?php if ( is_active_sidebar( 'sidebar-11' ) ) : ?>
                                                    <?php dynamic_sidebar( 'sidebar-11' ); ?>
                                            <?php endif; ?>
                                    </div><!-- #ad-widget-->
                    <?php endif; ?>
     </div><!-- #header-widget -->
            <?php endif; ?>
    
    		<?php if ( comments_open() ) : ?>
    				<div class="comments-link">
    					<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a comment', 'twentytwelve' ) . '</span>', __( '1 Comment', 'twentytwelve' ), __( '% Comments', 'twentytwelve' ) ); ?>
    				</div><!-- .comments-link -->
    			<?php endif; // comments_open() ?>
    
                <footer class="entry-meta">
    			<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
    			<?php if ( is_singular() && get_the_author_meta( 'description' ) && is_multi_author() ) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
    				<div class="author-info">
    					<div class="author-avatar">
    						<?php
    						/** This filter is documented in author.php */
    						$author_bio_avatar_size = apply_filters( 'twentytwelve_author_bio_avatar_size', 68 );
    						echo get_avatar( get_the_author_meta( 'user_email' ), $author_bio_avatar_size );
    						?>
    					</div><!-- .author-avatar -->
    					<div class="author-description">
    						<h2><?php printf( __( 'About %s', 'twentytwelve' ), get_the_author() ); ?></h2>
    						<p><?php the_author_meta( 'description' ); ?></p>
    						<div class="author-link">
    							<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
    								<?php printf( __( 'View all posts by %s <span class="meta-nav">&rarr;</span>', 'twentytwelve' ), get_the_author() ); ?>
    							</a>
    						</div><!-- .author-link	-->
    					</div><!-- .author-description -->
    				</div><!-- .author-info -->
    			<?php endif; ?>
    		</footer><!-- .entry-meta -->
    	</article><!-- #post -->
    Michael

    (@alchymyth)

    what files are in your (child) theme?

    does category.php call the same content.php as archive.php?

    David Borrink

    (@davidborrink)

    Hey, that was it! I did have a content-category.php file in my theme, and I obviously overlooked that category.php was involved for this situation. I found the spot in that file and changed the code.

    I KNEW I was overlooking something. Thanks for pointing me in the right direction. All set.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘My "is_archive" seems to be not working right’ is closed to new replies.