Home User profile
tagDiv Member
This user did not write anything. So we are just showing here some random text to make the profile page look nice :)
HanSho
tagDiv Member

Hello,
Someone help me?
Thanks!

HanSho
tagDiv Member

Thank you Lucian.
I found get_image function in file: includes\modules\module_modifier\td_module_blog.php and I edit it.
I’m change line (in this function):
return ''; //the post has no thumb
To
echo '<img src="' . get_first_image() . '" alt="' . the_title(). '" />';
And add this function:

function get_first_image() {
					  global $post, $posts;
					  $first_img = '';
					  ob_start();
					  ob_end_clean();
					  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
					  $first_img = '';
					  if (isset($matches[1][0])) {$first_img = $matches[1][0];}
					  return $first_img;
			}

Results:

/**
     * get_image v010 - modified on wp_010 - returns the featured image of a single post
     * @param $thumbType
     * @return string
     */
    function get_image($thumbType) {
        global $page;

        //show only on the first page when we have posts with pages
        if (!empty($page) and $page > 1) {
            return;
        }

        //do not show the featured image if the global setting is set to hide - show the video preview regardless of the setting
        if (td_util::get_option('tds_show_featured_image') == 'hide' and get_post_format($this->post->ID) != 'video') {
            return;
        }

        //do not show the featured image on gallery post format
        if (get_post_format($this->post->ID) == 'gallery') {
            return;
        }

        //handle video post format
        if (get_post_format($this->post->ID) == 'video') {
            //if it's a video post...
            $td_post_video = get_post_meta($this->post->ID, 'td_post_video', true);
            $td_video_support = new td_video_support();

            //render the video if the post has a video in the featured video section of the post
            if (!empty($td_post_video['td_video'])) {
                return $td_video_support->renderVideo($td_post_video['td_video']);
            }
        } else {
            //if it's a normal post, show the default thumb

            if ($this->post_has_thumb) {
                //get the featured image id + full info about the 640px wide one
                $featured_image_id = get_post_thumbnail_id($this->post->ID);
                $featured_image_info = td_util::attachment_get_full_info($featured_image_id, $thumbType);

                //get the full size for the popup
                $featured_image_full_size_src = td_util::attachment_get_src($featured_image_id, 'full');

                $buffy = '';

                $show_td_modal_image = td_util::get_option('tds_featured_image_view_setting') ; //@todo read this setting from theme panel
                if ($show_td_modal_image != 'no_modal') {
                    //wrap the image_html with a link + add td-modal-image class
                    $image_html = '<a href="' . $featured_image_full_size_src['src'] . '" data-caption="' . htmlentities($featured_image_info['caption'], ENT_QUOTES) . '">';
                    $image_html .= '<img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" itemprop="image" class="entry-thumb td-modal-image" src="' . $featured_image_info['src'] . '" alt="' . $featured_image_info['alt']  . '" title="' . $featured_image_info['title'] . '"/>';
                    $image_html .= '</a>';
                } else { //no_modal
                    $image_html = '<img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" itemprop="image" class="entry-thumb" src="' . $featured_image_info['src'] . '" alt="' . $featured_image_info['alt']  . '" title="' . $featured_image_info['title'] . '"/>';
                }

                $buffy .= '<div class="td-post-featured-image">';

                // caption - put html5 wrapper on when we have a caption
                if (!empty($featured_image_info['caption'])) {
                    $buffy .= '<figure>';
                    $buffy .= $image_html;

                    $buffy .= '<figcaption class="wp-caption-text">' . $featured_image_info['caption'] . '</figcaption>';
                    $buffy .= '</figure>';
                } else {
                    $buffy .= $image_html;
                }

                $buffy .= '</div>';

                return $buffy;
            } else {
                echo '<img src="' . get_first_image() . '" alt="' . the_title(). '" />';
            }
            function get_first_image() {
					  global $post, $posts;
					  $first_img = '';
					  ob_start();
					  ob_end_clean();
					  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
					  $first_img = '';
					  if (isset($matches[1][0])) {$first_img = $matches[1][0];}
					  return $first_img;
			}
        }
    }

But it not work. Can you help me fix it!
I want to get first image on post and set it as featured image.
Thank you!

  • This reply was modified 12 years by HanSho.
HanSho
tagDiv Member

Hello,
Someone help me?

Viewing 3 posts - 1 through 3 (of 3 total)