Coder, Need little Code Change in my Wordpress Blog

Status
Not open for further replies.

Ryza

Banned
Banned
278
2011
0
0
Ok, I dont know where should I start but I guess should try my best to make it clear.

here's the story,

When I want to post in my wordpress blog. I need to upload the image so it will appear as thumbnail of the post..

like these:
[slide]http://www.imgcafe.com/view/uploads/edit20tft.jpg[/slide]
[slide]http://www.imgcafe.com/view/uploads/downloadin.jpg[/slide]

Ok here's what I want.

Instead of uploading pic to make it a thumbnail of every post.
I want to make my [ IMG ] [ /IMG ] in the top of my post template to automatically make it the thumbnail..

For more information or clarification please post here.

also please tell me how much for this to be changed.

Thank you.
 
33 comments
after deleting what u said and adding the code..

here's the effect..
[slide]http://www.imgcafe.com/view/uploads/untitlldl.jpg[/slide]

complete broke my blog..

Please help.
 
Undo what you did then so the blog fix's

First off have you got "timbthumb" on your theme that you are using, like so.

Os7Pr.png


ProtoWorker basically layed it out on a plate for you.
That is what i done for my blog & it works perfectly, i done mine a while ago though.
 
Yeah thats right..
I don't see why it isn't working for you then, are you sure you are following the steps above correctly.
Have you tried chmodded the script to 777, i didn't have to do this but you never know with you.
 
Have you set your "media settings" ?

[slide]http://i.imgur.com/Dx7D8.png[/slide]

Make sure you have this as follows:

Now open up index.php of your WordPress theme and inside the WordPress loop, add the following lines of code to get the path of thumbnail image of the first image in the post.

<?php
  1. //Get images attached to the post
  2. $args = array(
  3. 'post_type' => 'attachment',
  4. 'post_mime_type' => 'image',
  5. 'numberposts' => -1,
  6. 'order' => 'ASC',
  7. 'post_status' => null,
  8. 'post_parent' => $post->ID
  9. );
  10. $attachments = get_posts($args);
  11. if ($attachments) {
  12. foreach ($attachments as $attachment) {
  13. $img = wp_get_attachment_thumb_url( $attachment->ID );
  14. break;
  15. }
  16. //Display image
  17. }
  18. ?>
Code Explanation: Firstly we fetch the images attached to the post in the order they were added to the post and if images are there we fetch the path to the thumbnail image of the first image in the post using wp_get_attachment_thumb_url function.
Now you have path of the image in $img which you can use to display the post thumbnail using img tag.


try this out also, might work for you, doesn't use the timthumb .. just another method.

Another method of foing this would be as follows:

First, paste this function on your functions.php file.
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];

if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
Once done, you can simply call the function within the loop to display the first image from the post:
<?php echo catch_that_image() ?>
 
Inside the Post Ive got my image..

[slide]http://www.imgcafe.com/view/uploads/sky20angel.jpg[/slide]

but in homepage..

[slide]http://www.imgcafe.com/view/uploads/downlogwg.jpg[/slide]

still same..no thumbnail.

brazzo can you please do it for me I would be willing to pay for all the trouble Ive cause you..

Please.
 
Hi can you let me know your index.php structure? Also please let me know the URL to your blog.

Mate, you need to add the snippet at the place where you want the resized image to be placed, not at the top of the page :S Noobish act :P
 
I can work this out for you if its easy and don't take me long ill do it free otherwise ill need to make a little something for my time...
 
ok sure please add my Y!M: nixshare@yahoo.com

Also If it really works perfect I'm willing to donate a few bucks. I just really need help here..

Thank you.

__________________
Added after 9 Hours 8 minutes:

Can someone please tell me how to wrap image with text??
cause the text is below in the image and overlapping in the border.. can someone please tell me what to change in the code so the text will stay in the right of the image..

downlogcg.jpg


Code:
<?php $cti = catch_that_image(); if(isset($cti)){ ?>
<div style="display: inline;"><img src="<?php  bloginfo('template_url'); ?>/timthumb.php?src=<?php echo $cti;  ?>&h=150&w=150&zc=1" alt="Link to <?php  the_title(); ?>" class="thumbnail"/></div>
<?php } else {} ?>
 
Last edited:
well its working perfectly fine with me now but I just notice it works only in homepage but not in categories..

can someone please make this work for categories too..

Thank you.
 
Status
Not open for further replies.
Back
Top