Connect with us

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..

Random Search Terms

Title

Top Articles

powered by WassUp

Recent Posts: Fully Net Worth . com

Avani Gregg Net Worth: How Rich is the Tik Tok Superstar?

Avani Gregg Net Worth: How Rich is the Tik Tok Superstar?

Avani Gregg is an American social media personality who is best known for being a star in the lip-sync and dance platform called TikTok. Here, she has managed to gain an impressive following of over 8.2 million followers along with 420 million likes in her videos. As of 2020, Avani Gregg net worth is estimated […]

Roman Kemp Net Worth: How Rich is the Radio host Actually?

Roman Kemp Net Worth: How Rich is the Radio host Actually?

Roman Kemp is an English radio host and presenter. He presents for the national radio network Capital FM and is part of the nineteenth series of I’m a Celebrity…Get Me Out of Here!. As of 2019, Roman Kemp net worth is estimated to be £2 million. Kemp was born on 28 January 1993, in Los […]

Korey Wise Net Worth: How Rich is Central Park Five Member?

Korey Wise Net Worth: How Rich is Central Park Five Member?

Korey Wise is one of the members of the Central Park Five. Wise was only 16 years old when he was arrested in 1989 in connection to the rape of Trisha Meili. Korey Wise net worth is estimated to be $12 million. Korey Wise along with Yusef Salaam, Antron McCray, Raymond Santana, and Kevin Richardson […]