inkthemes_main_image

Function to call first uploaded image in functions file -----------------------------------------------------------------------------------.

Description

inkthemes_main_image(); 

Usage

  1. if ( !function_exists( 'inkthemes_main_image' ) ) { 
  2. require_once '/functions/inkthemes-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = inkthemes_main_image(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/functions/inkthemes-functions.php  
  1. function inkthemes_main_image() { 
  2. global $post, $posts; 
  3. //This is required to set to Null 
  4. $id = ''; 
  5. $the_title = ''; 
  6. // Till Here 
  7. $permalink = get_permalink($id); 
  8. $homeLink = get_template_directory_uri(); 
  9. $first_img = ''; 
  10. ob_start(); 
  11. ob_end_clean(); 
  12. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); 
  13. if (isset($matches [1] [0])) { 
  14. $first_img = $matches [1] [0]; 
  15. if (empty($first_img)) { //Defines a default image  
  16. } else { 
  17. print "<a href='$permalink'><div class='img_thumb'><span></span><img src='$first_img' width='270px' height='200px' class='postimg wp-post-image' alt='$the_title' /></div></a>";