• Resolved rlinn

    (@rlinn)


    I want to modify the code in content.php for my child theme.

    In the source, lines 35-51, the search page displays the excerpt whereas the rest of the pages display the content. I would like to change this behaviour.

    I would like to change the code, lines 35-51, to display the search results differently. I would like the_excerpt for posts (is_singular( 'post' )) and pages (is_page()) but the_content for everything else.

    I have tried using these conditional statements but I haven’t been able to figure this out. Any help appreciated.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello rlinn

    Can you please add the below line of code by replacing code between line35-51.

    if ( is_search() ) : // Only display Excerpts for Search
    		 if ( is_singular( 'post' ) ){ ?>
    			  <div class="entry-summary">
    				  <?php the_excerpt(); ?>
    			   </div><!-- .entry-summary -->
    
    		 <?php }
    		 if ( is_page() ){ ?>
    			 <div class="entry-content">
    				  <?php the_content(); ?>
    			   </div><!-- .entry-content -->
    		<?php }
    		 ?>
    
          <?php else : ?>
          <div class="entry-content">
            <?php
                 /* translators: %s: Name of current post */
                   the_content( sprintf(
                      __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentythirteen' ),
                     the_title( '<span class="screen-reader-text">', '</span>', false )
                  ) );
    
                   wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) );
                ?>
            </div><!-- .entry-content -->
           <?php endif; ?>
    Thread Starter rlinn

    (@rlinn)

    Thanks for your reply. Your code gives neither the_content nor the_excerpt. I have a feeling that when is_search is TRUE then all the other conditionals (like is_singular and is_page) are FALSE.

    I think that I’m going to need to use get_post_type() somehow.

    Hello rlinn,

    Yes We need to check the condition like this:

    if ( get_post_type( get_the_ID() ) == "post" ) { ?>
    			  <div class="entry-summary">
    				  <?php the_excerpt(); ?>
    			   </div><!-- .entry-summary -->
    
    		 <?php }
    		 else { ?>
    			 <div class="entry-content">
    				  <?php the_content(); ?>
    			   </div><!-- .entry-content -->
    		<?php }
    		 ?>
    Thread Starter rlinn

    (@rlinn)

    Thanks for your reply. I had tried that previously except I had used = instead of == after looking at get_post_type().

    I have been able to modify your code to get the template working. Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Editing content.php for Twenty Thirteen child theme’ is closed to new replies.