user997593 user997593 - 6 months ago 39
PHP Question

the_post_thumbnail_url() causes fatal error with thumbnail support active

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;

Answer

Try this Logic if it does anything for you:

        <?php
            if ( has_post_thumbnail() && ! post_password_required() ) : 
                $imgURL = wp_get_attachment_url( get_post_thumbnail_id(get_the_ID()) );
        ?>
                <div class="ficha-thumbnail" style = "background: url('<?php echo $imgURL; ?>') no-repeat; background-size: 300px auto"></div>
                <?php endif; ?>

Hope this does the trick for you... ;-)