• Resolved balux

    (@balux)


    Hi,

    I am having issue with get_the_post_thumbnail() function. Basically it returns the thumbnail but with some of the code (from firebug I can feel it’s an issue with quotes but it looks like some parameters are added from the function as they are not in my code).

    You can see it here: https://test.assatena.it/#service

    scroll around and you will see that every image (except the ones in the first section after the jumbotron because they are hardcoded without using the function and the media logo at the bottom)

    code sample that I am using

    <section id="service" class="bg-green">
    	<?php
    	$ser = array( 'numberposts' => '1', 'category_name' => 'service');
    	$recent_service = wp_get_recent_posts( $ser );
    	foreach( $recent_service as $my_service ):
    		$service_title = $my_service["post_title"];
    		$service_id = $my_service["ID"];
    		$service_img_src = get_the_post_thumbnail($service_id, 'full');
    		$service_content = get_post_field('post_content', $service_id);
    	?>	
    	<div class="container">
    		<div class="row">
    			<div class="my_post_content">
    				<div class="col-lg-6 text-left">
    					<h3 class="service-heading"><?php echo $service_title; ?></h3>
    					<p><?php echo $service_content; ?></p>
    				</div>
    				<div class="col-lg-1">
    				</div>
    				<div class="col-lg-5 text-left">
    					<img id="service_img" class="img-responsive img-centered img-rounded" src="<?php echo $service_img_src ?>" />
    				</div>
    			</div>
    			<?php
    			endforeach;
    			?>
    		</div>
    	</div>
    </section>

    thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code works fine on my site. You do know that “thumbnails” in this context are featured images only, right? Regular thumbnail images inserted into content is not what this function is for.

    If so, you may have a theme or plugin conflict. Have you tried the deactivate all plugins and switch to twentysixteen troubleshooting process?

    Thread Starter balux

    (@balux)

    Hi, yes I know, it’s the feature image that I want to display.

    I don’t get why I read this with firebug

    <img class="img-responsive img-circle" alt="" src="<img width=" 1024"="" srcset="https://test.assatena.it/wp-content/uploads/2017/01/castelnuovo.jpg 1024w, https://test.assatena.it/wp-content/uploads/2017/01/castelnuovo-300x225.jpg 300w, https://test.assatena.it/wp-content/uploads/2017/01/castelnuovo-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" height="768">

    and clearly there’s an error here src="<img width=" 1024"="" which I guess it’s likely to be the error I am looking for, but I don’t understand where all this stuff’s coming from. I deleted all the plugins I had but nothing :/
    what do you mean by “switch to twentysixteen troubleshoot”?
    Thanks

    • This reply was modified 7 years, 10 months ago by balux.

    Based on the html code snippet that you provided you only want to get url. Use get_the_post_thumbnail_url instead of the get_the_post_thumbnail that you’re now using. This will give you only the url to the image.

    More info, check this https://developer.www.ads-software.com/reference/functions/get_the_post_thumbnail_url/

    Moderator bcworkz

    (@bcworkz)

    I had a feeling you wanted only featured images but I had to be sure.

    Yes, the img src attribute is a syntax error. If you have no plugins active and this happens, either the data for the image itself is corrupted or your theme is inappropriately filtering the img src.

    Please try switching to the twentysixteen theme and insert you test snippet on one of its templates. If you still get syntax errors, the DB content is corrupted. If the error is resolved, there is a problem with your theme.

    Thread Starter balux

    (@balux)

    using get_the_post_thumbnail_url made it!

    thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_the_post_thumbnail() issue’ is closed to new replies.