Thursday, August 4, 2022
HomeWordPress Developmentclasses - Picture loading operate not engaged on archive.php template

classes – Picture loading operate not engaged on archive.php template


I’m utilizing the next operate to show a submit thumbnail or ACF customized area picture relying on the web page sort being seen. This operate is loaded from the inc/template-tags.php file within the energetic theme listing.

if ( ! function_exists( 'flagstaffcounty_post_thumbnail' ) ) :
  /**
   * Shows an optionally available submit thumbnail.
   *
   * Wraps the submit thumbnail in an anchor factor on index views, or a div
   * factor when on single views.
   */
  operate flagstaffcounty_post_thumbnail() {
    if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
        return;
    }
    $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );

    if ( is_singular( 'submit' ) || is_search() ) : ?>
      <determine class="" itemprop="picture" itemscope="" itemtype="http://schema.org/ImageObject">
          <div class="post-thumbnail">
              <?php the_post_thumbnail(); ?>
          </div>
      </determine><!-- .post-thumbnail -->
    <?php elseif ( is_page() ) : ?>
      <determine class="page-thumbnail" model="background-image: url(<?php echo $url; ?>);" itemprop="picture" itemscope="" itemtype="http://schema.org/ImageObject">
        <header class="entry-header">
          <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
        </header><!-- .entry-header -->
      </determine>
    <?php elseif ( is_category( 'information' ) ) : ?>
    <?php $picture = get_field( 'taxonomy_image' ); ?>
      <determine class="tax-thumbnail" <?php if( !empty( $picture ) ) : ?>model="background-image: url(<?php echo esc_url($picture['url']); ?>);"<?php endif; ?> itemprop="picture" itemscope="" itemtype="http://schema.org/ImageObject">
        <header class="entry-header">
          <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
        </header><!-- .entry-header -->
      </determine><!-- .post-thumbnail -->
    <?php else : ?>
        <a category="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
            <?php
                the_post_thumbnail(
                    'post-thumbnail',
                    array(
                        'alt' => the_title_attribute(
                            array(
                                'echo' => false,
                            )
                        ),
                    )
                );
            ?>
        </a>
        <?php
    endif;
   }
endif;

The operate works correctly on is_singular( 'submit' ) and is_page() web page varieties, nevertheless it doesn’t work on is_category(), both with empty parentheses or the information class slug supplied.

The operate is loaded into every web page sort utilizing <?php flagstaffcounty_post_thumbnail(); ?>. This code is positioned simply after the get_header(); embody in every file. Archives are utilizing the default archive.php file, pages are utilizing the default web page.php file, and posts are utilizing the default single.php file. There aren’t any class particular template information that may very well be overriding the default archive.php, although I did take a look at category-news.php and class.php, however each didn’t work.

There’s nothing in my features.php file that may very well be affecting the loading of the thumbnail operate on the archive pages.

Perhaps I’m lacking one thing easy…

Any assistance is vastly appreciated.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments