Articles
Echo Images inside a Post into the Loop
Here is a useful trick. Want to call or echo an image into your blog post with our using the custom fields? Well this could be tricky, but I know of a way.
All you have to do is print these lines of code into your
index.php
or home.php
inside the loop:
<?php $id =$post->ID; $the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id"); $home = get_option('home'); $pattern = '!<img.*?src="'.$home.'(.*?)"!'; preg_match_all($pattern, $the_content, $matches); $image_src = $matches['1'][0]; ?>
then after write:
<?php if($image_src != '') { ?> <a href="<?php echo the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a><br /> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $image_src; ?>" alt="<?php the_title(); ?>" /></a> <?php } ?>
That’s all! This will look for the first image in your post and echo it in the loop, could be used to show off those pretty thumbnails for the post..
News
The new design in progress
Okay, so by now you may notice something. You may be thinking “the site looks a lot different”, and you are correct. Over the past few weeks I’ve decided that the site needed a different flare and feel. While many and most site’s these days are popping up with featured posts, and jQuery sliders, I wanted to steer away from that and go old school. While I had some trouble’s activating the theme today which didn’t allow me to fully finish the theme, 99% of it is done.
The site is still build on the powerful Hybrid theme framework. Enjoy.
News
Bar Camp Los Angles 7
Hello from BarCampLA in beautiful Culver City. It’s a bit early and presentation’s don’t start till after lunch. While I hadn’t planned on making a presentation, I got an email from Shen asking if I’d do a collaboration presentation, and I guess i agreed.
So at this time Shen, myself and possibly Michael Dorausch. will be doing a panel presntation at 6:00pm in track 3 of the BarCamp room here in the OTX facility.
Links
- Austin Passy
- Twitter: @TheFrosty
Personal Blog: TheFrosty.com - Shen Deshayne
- Twitter: @shennyg
Site: Shen Deshayne - Michael Dorausch
- Twitter: @Chiropractic
Site: Michael Dorausch
Child
New theme release: CULT[i]VATE
Doing theme modification and even custom template files has brought me to this point. Today I’ve created my first premium theme, and since I am a huge fan of Hybrid, I decided that a child theme would be an appropriate starting point.
So after some time playing with many options and idea’s I’ve finally released a premium theme. This theme, which I am calling CULT[i]VATE is a child theme.
Unfamiliar with child themes? You may want to check out this post Ian Stewart wrote.
CULT[i]VATE is a child theme of the Hybrid:
Hybrid is a user-friendly, search-engine optimized theme framework, featuring 14 custom page templates and 9 widget-ready areas, allowing you to create any type of site you want.
CULT[i]VATE includes four new widget-ready area’s and one custom accordion widget for one of the area’s. It also includes two front page templates.
This theme is for sale for $12.00 which you can purchase here. Looking for a demo?
[wp_eStore:product_id:1:end]
-
Tips & Tricks4 months ago
WordPress Security Hacks
-
Pages1 month ago
Write For Us – Guest Post
-
Showcase2 months ago
StylizedWeb.com
-
News1 month ago
How to: Show/Hide any div box with jQuery in WordPress
-
Tips & Tricks2 weeks ago
Remove the title attribute using jQuery
-
Tips & Tricks3 months ago
How to: show/hide a widget in WordPress with jQuery
-
Plugins3 months ago
Top Membership plugins
-
Tips & Tricks2 months ago
Limit the characters that display on the_title
Austin
December 8, 2008 at 3:54 am
Assuming the image has been added using the WP uploader, here’s a way of doing the same thing using the WP API, which might have a performance advantage:
<?php $attachments = (array) get_children(array(‘post_parent’ => get_the_ID(), ‘post_type’ => ‘attachment’));
if ( ! empty( $attachments ) ) :
$attmt = array_shift($attachments);
$image_thumb = wp_get_attachment_thumb_url($attmt->ID); ?>
<a href=”<?php echo the_permalink() ?>” rel=”bookmark” title=”Link to <?php the_title(); ?>”><?php the_title(); ?></a><br />
<a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><img src=”<?php echo $image_thumb; ?>” alt=”<?php the_title(); ?>” /></a>
<?php endif; ?>
frosty
December 8, 2008 at 10:59 am
Thanks for that one!
Picsbuzz
January 7, 2009 at 9:57 pm
This is great script, it helps me a lots!!! Thank you so much!!
I wonder if this script can grab the first image in the post which hosted on share host like: flickr or imagesharkus?
frosty
January 7, 2009 at 10:05 pm
Your welcome, I am not sure. If we could find out details to their database it may be possible.
Nick
January 15, 2009 at 12:38 pm
That can be useful
Nick’s last blog post..Montana Library
Thomas
August 10, 2009 at 11:00 am
Hi all,
First of all, very nice script. I noticed that the output was in html (ie, img src and thumbnailing).
Does anyone know of any snippet to be able to echo the image via php, without having to name the actual individual image file (eg. tree.jpg), and instead using a variable from a database that names photos in a directory.?
thanks
tom
Maor
September 5, 2009 at 5:33 pm
Thanks for the tip, liked it!
.-= Maor´s last blog ..וורדפרס 2.8+: איך לא להציג קטגוריות מסוימות בתפריט הצדדי? =-.