Build Your Own Business Website header image

Welcome to our Members Only Forum

You are welcome to view the content on our Forum, just scroll down to view this forum post.
If you like what you find and want to be able to post a question, please check out our subscription options.
Please feel free to search the forum using either the Google Site Search above or the forum search below.

Avatar
Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Auto Featured Image Box (3rd party) - Only works for a query box, not WP Loop
Avatar
Isaac Moan
Member
Members

Community Member
Forum Posts: 16
Member Since:
December 1, 2014
sp_UserOfflineSmall Offline
1
June 20, 2016 - 9:53 am
sp_Permalink sp_Print sp_EditHistory

Hello,

I found 3rd party box called "auto featured image", which display the first image of a post if no featured image is explicitly set.

It works fine for a thesis query box, but it doesn't work when I put it in the main WP Loop.

Here is the function that catches the first image:

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);
if(count($matches [1]))$first_img = $matches [1] [0];
return $first_img;
}

Can anyone tell me how to tweak this so that it also grabs the first image of a post in the WP loop as well as still functioning within a query box (as it does now)?

Thanks

Avatar
Pierre Cote
Moderator
Members

Moderators

Community Member
Forum Posts: 1160
Member Since:
September 21, 2014
sp_UserOfflineSmall Offline
2
June 20, 2016 - 1:21 pm
sp_Permalink sp_Print

Hi

Contact Matthew Horne : http://store.diywpblog.com/dow.....red-image/

Pierre ( postrophe )

Forum Timezone: America/Los_Angeles

Most Users Ever Online: 228

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Keith W Jones: 1428

Brian Tozer: 1004

Carolin: 982

Heidi Hafner: 508

John Cunningham: 423

Reece Morrel: 353

Newest Members:

emma62755

sharonmarks

emma80233

Tijs de Jong

Daniel Frey

mutek

Forum Stats:

Groups: 8

Forums: 46

Topics: 6995

Posts: 34796

 

Member Stats:

Guest Posters: 6

Members: 6761

Moderators: 2

Admins: 2

Administrators: Rick Anderson, Rick Anderson

Moderators: Pierre Cote, Laura Nugent