WordPress.org

Ready to get started?Download WordPress

Forums

Controlling Image display in post excerpts (28 posts)

  1. wrightj999
    Member
    Posted 2 years ago #

    Hello,

    I'm wondering if there is some sort of tag that can be used (or some other methodology) to make it so that images in a post do not appear in the post excerpt. I just want certain posts to have images within the post, but to not display an image in the post excerpt.

    Thanks!!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    If your theme uses the_excerpt() all images will be removed from the post teaser.

  3. wrightj999
    Member
    Posted 2 years ago #

    is there any chance I can apply that code to a single post? I want thumbnail images on some posts, and not on others. Where could I add this to get that effect? in the html of the actual posting?

  4. wrightj999
    Member
    Posted 2 years ago #

    so putting that in the posting html does nothing, so that answers that. hmm, so it seems there is no way to customize this, it's all or nothing? image thumbs on all post excerpts (with posts containing images) or none at all?

  5. esmi
    Forum Moderator
    Posted 2 years ago #

    I want thumbnail images on some posts, and not on others.

    So don't add images to some posts...

  6. wrightj999
    Member
    Posted 2 years ago #

    i guess i want more control over things than are possible, according to your feedback. I will give you an example of what I was trying to do, so you can at least understand where I am coming from. For my most recent post, there were no images needed in it. However, I wanted to punctuate the end of the post with the company logo.. it looked nice. However, I didn't want it to appear in a thumbnail in the blog excerpt because right beneath the header of the blog, would be kinda redundant logo wise (as the logo is prominently featured in the header.) So I guess I should just give up on this desire? Not do-able?

  7. esmi
    Forum Moderator
    Posted 2 years ago #

    In that particular instance, using <?php the_excerpt();?> should work as it will strip out the image along with any other text formatting tags. The problem arises when you want some post teasers to include images and others to be just plain text. If you do want mix'n'match, then the only real option is to use <?php the_content();?> in conjunction with the <!--more--> tag. Then you can use:

    - No images in teaser = insert images after the <!--more-->

    - Want images in teaser = insert images before the <!--more-->

    Does that make sense?

  8. wrightj999
    Member
    Posted 2 years ago #

    hmmm, so your suggesting to use <?php the_content();?>. Would I put this code into the actual post, similarly to how we use the <!--more--> tag? And if so, does it matter where I place it within the post?

    So if I get what your saying. Using <?php the_content();?> gives me the option to put images before or after <!--more-->, in order to get my desired result, as you've detailed above. That sounds pretty good, I'm just going to have to get straight, where exactly to place <?php the_content();?>.

  9. esmi
    Forum Moderator
    Posted 2 years ago #

    Would I put this code into the actual post

    What does the relevant theme template currently use?

    Would I put this code into the actual post,

    No - it's strictly a template tag.

  10. wrightj999
    Member
    Posted 2 years ago #

    right, okay.. so this is a part where maybe you can school me. So I'd be going to Appearance>Editor in the WP Dash and inserting this tag into one of the available php templates that make up the theme.

    These are what is available for options. Which template would I typically put a tag like this?:

    404 Template
    (404.php)
    Archives
    (archive.php)
    Archives Page Template
    (archives.php)
    Comments
    (comments.php)
    Footer
    (footer.php)
    Header
    (header.php)
    Image Attachment Template
    (image.php)
    Links Page Template
    (links.php)
    Main Index Template
    (index.php)
    Page Comment Page Template
    (page-comment.php)
    Page Template
    (page.php)
    Search Form
    (searchform.php)
    Search Results
    (search.php)
    Sidebar
    (sidebar.php)
    Single Post
    (single.php)
    Theme Functions
    (functions.php)
    theme-options.php
    (theme-options.php)

    Styles

    Stylesheet
    (style.css)

    Thanks!!

  11. wrightj999
    Member
    Posted 2 years ago #

    oh yeah... and does it matter where in the template? Can I just add it within the php code that already exists, maybe at the end of it?

  12. esmi
    Forum Moderator
    Posted 2 years ago #

    Which template would I typically put a tag like this?

    Which page do you want this to appear in? You can find a generic list of what template is used in which page on the Codex's Theme_Development page.

  13. wrightj999
    Member
    Posted 2 years ago #

    awesome, I will refer to that resource. Thanks man, you've been quite a help, I know my needs have been somewhat basic.. but I guess that's what makes the WP Forums great! When I get this implemented successfully, I will let you know :)

  14. wrightj999
    Member
    Posted 2 years ago #

    okay, so upon doing that research I've determined that I have to add <?php the_content();?> within the "the loop" on the main index template: index.php. I'm wondering where to add it within the loop.

    So I was guessing to add it right before this code at the end of the loop:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    Do I need to pass any parameters, or will just adding this tag add that extra functionality to the "more" tag that I am looking for concerning these image thumbs.

    After I get this figured out I will probably be adding at least one parameter to this tag in order to change the post excerpt display text of "more" to "read more".

  15. esmi
    Forum Moderator
    Posted 2 years ago #

    Drop a copy of the theme's index.php into the WordPress pastebin and post the pastebin url here, so we can have a look at it.

    You can just use <?php the_content();?> but it is also possible to customise the Read More link to suit your needs.

  16. wrightj999
    Member
    Posted 2 years ago #

    Okay, here is a link to the paste:
    http://pastebin.com/rxSvnwcV

  17. wrightj999
    Member
    Posted 2 years ago #

    so just to follow up... I have tried inserting <?php the_content();?>, where I said I would in the previous post.. but to no avail. It must need to go somewhere particular.. I will wait for your advice :)

  18. esmi
    Forum Moderator
    Posted 2 years ago #

    Try replacing:

    <?php
    $content = get_the_content('read more');
    $content = apply_filters('the_content', $content);
    $content = preg_replace('|<img (.+?)>|i', '', $content);
    $content = preg_replace('|<div id="attachment_(.+?)" class="wp-caption(.+?)<\/div>|i', '', $content);
    echo $content;      ?>

    with:

    <?php the_content();?>

  19. wrightj999
    Member
    Posted 2 years ago #

    okay, so swapped out that code. To test if it worked, I went ahead and inserted an image at the end of the post. Alas, it is still appearing in the post excerpt. hmm...

  20. esmi
    Forum Moderator
    Posted 2 years ago #

    There are multiple Loops in that file. Try replacing:

    <p><?php $texter = get_the_excerpt();
    if(strlen($texter ) > 300) {
    	$texter = substr($texter , 0, 300);
    }
    echo ''.$texter.'[...]';
    ?></p>

    instead.

  21. wrightj999
    Member
    Posted 2 years ago #

    okay, I will reset the changes I made previously, try this option and be back with results.

  22. wrightj999
    Member
    Posted 2 years ago #

    okay, same result, no cigar. Do you think we need to get rid of both of those codes? I put back the code I had previously swapped out, for the purpose of this test.

  23. wrightj999
    Member
    Posted 2 years ago #

    One thing that I noticed that changed with that most recent code swap, was the "more" text display on page excerpts. It now says "read more" instead of "more" on the main highlighted excerpt. On the secondary excerpts instead of "..." it says "(more...)". So that's kinda cool i guess.

  24. esmi
    Forum Moderator
    Posted 2 years ago #

    okay, same result, no cigar.

    Well you have yet a third Loop with the same code block that you could try replacing further down the file.

  25. wrightj999
    Member
    Posted 2 years ago #

    yeah, so did that and same deal. Do you thing all of those codes need to be replaced simultaneously? Maybe getting rid of one isn't enough to override the others... of course this is me speaking from a purely speculative view based off what we've done here.

    Do I lose any real functionality by getting rid of the code I have replaced in these different sections?

  26. wrightj999
    Member
    Posted 2 years ago #

    whoever originally designed this theme seems to have overcomplicated things, lol.. that's just my opinion that doesn't mean a whole lot though :)

  27. Jauhari
    Member
    Posted 2 years ago #

    so the problem has been solved?

  28. wrightj999
    Member
    Posted 2 years ago #

    No, it has not been solved. While it's not the biggest deal, and I can live with things as they are, for my own knowledge I'd still really like to know how to get what is discussed above to work. If you could shed some light on the subject, it would be much appreciated. Love the theme, you designed.. just ignore the above comment as I was maybe a tad frustrated, you did a wonderful job on the theme, lol :)

Topic Closed

This topic has been closed to new replies.

About this Topic