最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Multiple Post Thumbnails Not Returning URL for Background Image

matteradmin5PV0评论

I've been using the Multiple Post Thumbnail plugin with my custom post types to use a secondary, smaller image on my archive pages, while I have a larger hero image in the header of the single post (these are two different images, not a smaller and larger version of the same image).

Previously, the code worked well, but suddenly it stopped returning the post thumb url.

The code in my functions.php file:

if (class_exists('MultiPostThumbnails')) {
    new MultiPostThumbnails(
        array(
            'label'     => 'Secondary Image',
            'id'        => 'secondary-image',
            'post_type' => 'episodes'
        )
    );
}
if (class_exists('MultiPostThumbnails')) {
    new MultiPostThumbnails(
        array(
            'label'     => 'Secondary Image',
            'id'        => 'secondary-image',
            'post_type' => 'resources'
        )
    );
}

The code in the loops on my custom post types' archive pages:

<?  $custhumburl = MultiPostThumbnails::get_post_thumbnail_url('episodes', 'secondary-image', NULL, 'secondary-image'); ?>

<div id="post-<?php the_ID(); ?>" <?php post_class('grid-box inline-item thumb') ?> itemscope itemtype="">

                <a href="<?php the_permalink(); ?>" itemprop="significantLink">

                <span class="display-block wp-post-image" style="background-image:url(<?php echo $custhumburl ?>);"></span>

                <span class="bg-gray-solid border-radius-bottom display-block lato all-padding">

                    <h3 class="center-text gray-text lato letter-spacing-heading sub-heading-font text-padding uppercase" itemprop="title"><?php the_subtitle(); ?></h3>

                    <h2 class="black-text capitalize center-text font-light heading-font roboto" itemprop="title"><?php the_title(); ?></h2>

                </span><!-- End post meta -->
            </a><!-- End post anchor tag -->
        </div><!-- End grid-box - post thumbnail -->

When I open Dev Tools, the image url is blank:

<span class="display-block wp-post-image" style="background-image:url();"></span>
Post a comment

comment list (0)

  1. No comments so far