• I am creating a blog for a friend here: https://cathyflorence.com, using a Child Theme of 2012.

    She is wanting the posts that show up when you search to show the picture that goes with the post. I can’t figure out how to either:

    1. make the excerpt show the picture
    OR
    2. just make the search show the whole post, because I am putting ‘read more’ tags in each post anyway (like the homepage and categories show), so when people scroll through, they won’t actually be scrolling through the whole post.

    I tried taking out this part of content.php:
    is_search() || is_home() || is_archive()
    but that was a mistake ??

    Then I tried taking this whole part out, and that was also a mistake!

    <?php if ( is_search() || is_home() || is_archive() ) :// Only display Excerpts for Search, Home, and Archives ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    			<a href="<?php echo get_permalink(); ?>" >Read More &rarr;</a>
    		</div><!-- .entry-summary -->

    Thanks for any help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • For the search not to show excerpt, Have you tried it like this?

    <?php if ( is_home() || is_archive() ) :// Only display Excerpts for Home, and Archives ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    			<a href="<?php echo get_permalink(); ?>" >Read More &rarr;</a>
    		</div><!-- .entry-summary -->

    It still depends on what comes aftermard in the rest of the file, it will only show the full post if afterward is the_content();

    This is the code to display the featured image:

    <?php if ( has_post_thumbnail() ) : ?>
    	<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    	<?php the_post_thumbnail(); ?>
    	</a>
    <?php endif; ?>

    So put it all together it’s like this:

    <?php if ( is_home() || is_archive() ) :// Only display Excerpts for Home, and Archives ?>
    		<div class="entry-summary">
    
    <?php if ( has_post_thumbnail() ) : ?>
    	<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    	<?php the_post_thumbnail(); ?>
    	</a>
    <?php endif; ?>
    
    			<?php the_excerpt(); ?>
    			<a href="<?php echo get_permalink(); ?>" >Read More &rarr;</a>
    		</div><!-- .entry-summary -->

    One other thing, the read more tag might prevent the above code from working right.

    Thread Starter 7Farmgirls

    (@7farmgirls)

    Thank you santeven!

    I replaced the_excerpt with the_content in this part:

    <?php if ( is_home() || is_archive() ) :// Only display Excerpts for Home, and Archives ?>
    		<div class="entry-summary">
    			<?php the_content(); ?>
    			<a href="<?php echo get_permalink(); ?>" >Read More &rarr;</a>
    		</div><!-- .entry-summary -->

    and it did exactly what I wanted it to! Yay!

    Now my problem is that for some reason I have my ‘Read More’ tag that I insert into each post, as well as a (more…) link. You can see it here: https://cathyflorence.com

    I tried taking out this part:

    <a href="<?php echo get_permalink(); ?>" >Read More &rarr;</a>

    but it took away the ‘Read More→’ and left the less attractive (more…) tag.

    Any ideas where that is to get it out? ??

    Thanks again for your help!

    Thread Starter 7Farmgirls

    (@7farmgirls)

    And another, very small detail. It would be nice if ‘Read More→’ was on the right hand side instead of the left. Any idea how to work that? I tried using the ‘align-right’ button in the editor and that did nothing ??

    The text “(more…)” is defined in the function “get_the_content” [1] and is printed when the first parameter of that function is set as NULL so an easy way to get rid of that text is to call “the_content” function with an empty string or an invisible Unicode character [2].

    As for your last request to align the “Read More” text to the right side of the content block, you will have to edit the link to add a CSS class or an inline style that displays the link as a “block” and then force the alignment to the right.

    The full code would be something like this [3].

    [1] https://codex.www.ads-software.com/Function_Reference/get_the_content
    [2] <?php the_content( "\x20" ); ?>
    [3] https://cixtor.com/pastio/4ztmd0

    Thread Starter 7Farmgirls

    (@7farmgirls)

    Thank you, Yorman!

    The first one worked! Yay!

    I tried adding no. 3, but no changes?

    Do I need to add something in the style.css to make it work?

    I just accessed your website and it displays the “Read More” text on the right-side of the content block of each post, here is a screenshot [1], maybe you have to clear the cache of your browser or something like that.

    Edit. I just checked the source code of the site and it seems that the “style” attribute is not separated from the previous text, it is looking like this [2] and it should be like this [3] (note the extra white space), some web browsers do not understand code like this, that may be the reason of why you are not seeing the text in the correct alignment.

    [1] https://i.imgur.com/iaMn10h.png

    [2] a href="..."style="...">Read More →</a
    [3] a href="..." style="...">Read More →</a
    Thread Starter 7Farmgirls

    (@7farmgirls)

    Oh yay! You are right…it was just that the cache needed cleared. It looks just like it should now.
    I will fix the code how you described, too, just to be safe.

    Woohoo! Thank you SO much ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Search to show full post’ is closed to new replies.