How to make function for call first image, first url, and post title from Next/P
-
How to make function for call first image, first url, and post title from Next/Previous posts?
These are custom function for call first image and first url in my functions.php but it using in loop at index.php only.
// Get URL of first image in a post 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]; // no image found display default image instead if(empty($first_img)){ $first_img = "/images/default.jpg"; } return $first_img; } // Get URL of first url in a post function catch_that_url() { global $post, $posts; $first_url= ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<a.+href=[\'"]([^\'"]+)[\'"].* title="Go to Store">/i', $post->post_content, $matches); $first_url = $matches [1] [0]; // no image found display default image instead if(empty($first_url)){ $first_url = "/404.php"; } return $first_url; }
However, after I using both function in single.php. It display in an single from itself id product only.
How can I make something changes that make it using as loop as index.php in single.php?
Thanks!
- The topic ‘How to make function for call first image, first url, and post title from Next/P’ is closed to new replies.