Need Help With the_content
-
<?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.
-
Use
the_excerpt()? By default, it won’t display images…Just a thought.
PAE
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.
<?php echo preg_replace("/<img[^>]+\>/i", "", the_content('<p class="serif">Read the rest of this entry »</p>')) ?>roscius,
Unfortunately it’s still pulling the image. Any other ideas?
Image For A Look: http://i39.tinypic.com/att2iq.jpg
Any other suggestions on how to accomplish this?
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
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?
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 tothe_content()as the last (3rd) parameter) of a call topreg_replace(). The call topreg_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
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 »'); ?>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
Well, that suggested code isn’t working and it’s still pulling the image. What code do I need to show you?
That is my index.php code. The excerpt code is just temporary and used to be
<?php the_content('Read more »'); ?>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
Is this a post thumbnail that’s being displayed. What happens if you comment out the code that displays the thumbnail?
Cheers
PAE
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.
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; ?>
The topic ‘Need Help With the_content’ is closed to new replies.