I’m working on a child theme from twentythirteen.
Twentythirteen has support fro thumbnails:
add_theme_support( 'post-thumbnails' );
But when I use:
the_post_thumbnail_url()
I get a fatal error.
All the google answers say that add_theme_support( ‘post-thumbnails’ ) has to be in the parent theme functions.php, well, in this case it is there but I’m getting the fatal error anyway.
I have even duplicated the support sentence in the child functions.php (just in case) but still in trouble with this.
The code:
query_posts('category_name=curso&showposts=3');
?>
<?php if (have_posts()) : ?>
<h2>Cursos</h2>
<?php while ( have_posts() ) : the_post(); ?>
<div class = "ficha curso">
<?php
if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="ficha-thumbnail" style = "background: url('<?php the_post_thumbnail_url('large'); ?>') no-repeat; background-size: 300px auto"></div>
<?php endif; ?>
<h3 class="ficha-title"><?php the_title(); ?></h3>
<div class="ficha-resumen">
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
</div>
<?php endwhile; endif;
Try this Logic if it does anything for you:
Hope this does the trick for you… 😉
With the excellent help of Poiz I have finally found a solution. The one suggested by him works, but I needed to get the large thumbnail rather than the attachment.
This is doing the trick for me:
I will mark Poiz answer as the correct one as he deserves the reputation.
Have you tried removing single quotation marks around php tags in your markup? It seems like these are the source of a parsing problem.
You might like this simple function to do the job.
It checks if there is a post thumbnail, if there is it looks for the post thumbnail ID, and then using the $size and wp_get_attachement_image_src’s first part of the answer (the src) the response.
I was able to retrieve the post featured image url with the following: