WordPress.org

Ready to get started?Download WordPress

Forums

Need Help With the_content (16 posts)

  1. teckn1caLity
    Member
    Posted 2 years ago #

    <?php the_content('<p class="serif">Read the rest of this entry »</p>'); ?

    That's currently in my single post.php file. I need that for my index but I want it to not display the images because I'm gonna use add_image_size for the main page. Any help is appreciated.

  2. peredur
    Member
    Posted 2 years ago #

    Use the_excerpt()? By default, it won't display images...

    Just a thought.

    PAE

  3. teckn1caLity
    Member
    Posted 2 years ago #

    Well, I want it to display the flash I put in the post as well as links and all that good stuff that comes with using the_content. Any other suggestions? Would be GREATLY appreciated.

  4. Roscius
    Member
    Posted 2 years ago #

    <?php
    echo preg_replace("/<img[^>]+\>/i", "", the_content('<p class="serif">Read the rest of this entry »</p>'))
    ?>
  5. teckn1caLity
    Member
    Posted 2 years ago #

    roscius,

    Unfortunately it's still pulling the image. Any other ideas?

    Image For A Look: http://i39.tinypic.com/att2iq.jpg

  6. teckn1caLity
    Member
    Posted 2 years ago #

    Any other suggestions on how to accomplish this?

  7. peredur
    Member
    Posted 2 years ago #

    If the image is still being included then the chances are that you're not altering the PHP in the correct template. Even if the regular expression wasn't perfect (and it looks OK to me) it should still modify the <img> tag sufficiently to show some sort of result. If you're getting no change at all, my money would be on the template file.

    HTH

    PAE

  8. teckn1caLity
    Member
    Posted 2 years ago #

    With that code that roscius linked, I use that in place of the original the_content code or is that like a function where I just place it in the file and it will work its magic?

  9. peredur
    Member
    Posted 2 years ago #

    I'm not 100% sure exactly what you have in your template file, but I assume it's something like:

    the_content('<p class="serif">Read the rest of this entry »</p>')

    What you are being asked to do is to surround that with the call to preg_replace(). In other words you need to replace that existing call with the code given to you. This leaves the existing call to the_content() as the last (3rd) parameter) of a call to preg_replace(). The call to preg_replace() means:

    Find any string of characters contained in the 3rd parameter (the string returned by the call to the_content()) that conforms to the regular expression pattern that's contained in the first parameter, and replace it with the string contained in the 2nd parameter (the NULL string).

    The result of all that is to replace the <img> element with the NULL string (i.e. nothing).

    HTH

    PAE

  10. teckn1caLity
    Member
    Posted 2 years ago #

    I'm waiting here for assistance so my apologies for such a quick response. I understand what you're saying but I'm not sure how to execute it, even if you're spoon feeding it to me. The code he gave me, from what it sounds like, is the right code. But, it's not doing the job. the content code being used is
    <?php the_content('Read more »'); ?>

    <?php
    echo preg_replace("/<img[^>]+\>/i", "", the_content('<p class="serif">Read the rest of this entry »</p>'))
    ?>

    So this is basically what I use instead of...

    <?php the_content('Read more »'); ?>
  11. peredur
    Member
    Posted 2 years ago #

    Yeah. There's nothing magic about the "Read the rest of this entry..." and stuff. Just wrap the call to the_content(). So this should be fine:

    <?php
    echo preg_replace("/<img[^>]+\>/i", "", the_content('Read more »'));
    ?>

    The only difference between the two is that the code suggested to you will output a different string as the text for the rest of the content, and will output it in a new paragraph. You don't have to do that if you prefer the string you already have. It's just that we can't see what's in your template file.

    HTH

    PAE

  12. teckn1caLity
    Member
    Posted 2 years ago #

    Well, that suggested code isn't working and it's still pulling the image. What code do I need to show you?

    http://pastebin.com/UGJSy27f

    That is my index.php code. The excerpt code is just temporary and used to be <?php the_content('Read more »'); ?>

  13. peredur
    Member
    Posted 2 years ago #

    Well, there's a couple of things. First of all, I don't see a call to the_content() anywhere in the code you posted.

    EDIT: oops, sorry. I just re-read what you wrote....

    Secondly, looking back at your original post, I see that you talk about a "single post.php" file. So, what page type are we dealing with here? Are we talking about a single post, or a blog list/category list?

    Cheers

    PAE

  14. peredur
    Member
    Posted 2 years ago #

    Is this a post thumbnail that's being displayed. What happens if you comment out the code that displays the thumbnail?

    Cheers

    PAE

  15. teckn1caLity
    Member
    Posted 2 years ago #

    Basically what I want to achieve is having a custom thumbnail size with some meta info underneath it with a twitter button floated left with the content on the right of it. I have everything laid out how I want it except I have the excerpt in there temporarily but I want to have it get all the content, flash and hyperlinks. Like this image.

    http://i41.tinypic.com/28hft6g.jpg

    tldr;

    All I want is the_content (only in my index) to not show any images so I can supply my own custom size thumbnail for the index. But when I go to a single post it displays normally.

  16. teckn1caLity
    Member
    Posted 2 years ago #

    Well, after about 10mins of googling I found the solution. Though, it was touched on here, I found it in it's entirety.

    <?php
       ob_start();
       the_content('Read the full post',true);
       $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
       ob_end_clean();
       echo $postOutput;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.