【问题标题】:Wordpress the_content() not showing after the portfolio sectionWordpress the_content() 在投资组合部分后未显示
【发布时间】:2020-07-11 01:43:16
【问题描述】:

我为主页创建了一个自定义模板。我想在投资组合之后调用内容,但它不起作用。我找不到我犯错的地方。当我在投资组合上方调用时,它会起作用。有谁知道我怎么能做到这一点?

<section id="portfolio" class="portfolio atop">

  <!-- Portfolio Filter -->
  <div class="portfolio_filter">

    <ul>
      <?php $categories = get_categories("taxonomy=categories");
      foreach ($categories as $category) : echo '<li><a data-filter=".' . $category->slug . '"  href="#">' . $category->name . '</a></li>';
      endforeach; ?>
      <li><a class="select-cat" data-filter="*" href="#">All Works</a></li>
    </ul>

  </div>

  <div class="container">
    <div class="row masonry clearfix">
      <!-- a work -->
      <?php $args = array(
        'post_type' => 'portfolio',
        'orderby'   => 'date',
        'order' => 'ASC',
        'posts_per_page' => 100,
      );

      $wp_query = new WP_Query($args);
      while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
        <?php $portcolor = get_field('text_color_of_featured_image'); ?>
        <?php $taxonomy = 'categories';
        $terms = get_the_terms($post->ID, 'categories'); ?>
        <?php foreach ($terms as $term)  ?>
        <a href="<?php echo esc_html(get_permalink()); ?>" class="col-xl-4 col-md-6 grid-item <?php echo esc_html($term->slug); ?> <?php echo esc_attr($portcolor); ?>" data-type="ajax-load">
          <figure class="portfolio-item <?php $portfolio_type = get_field('portfolio_type');
                                        echo esc_attr($portfolio_type); ?>">
            <div class="image">
              <?php $featured_image = get_field('portfolio_featured_image'); ?>
              <img src="<?php echo esc_url($featured_image['url']); ?>" alt="<?php echo esc_attr($featured_image['alt']); ?>" />
            </div>

            <figcaption>
              <span><?php echo esc_html($term->name); ?></span>
              <h3 class="title"><?php the_title(); ?></h3>
            </figcaption>
          </figure>
        </a>
      <?php endwhile; ?>
    </div>
  </div> <!-- container end -->
</section>

 <?php the_content(); ?>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您需要在自定义WP_Query 之后使用wp_reset_postdata() 重置全局帖子。见下文:

    <section id="portfolio" class="portfolio atop">
    
      <!-- Portfolio Filter -->
      <div class="portfolio_filter">
    
        <ul>
          <?php $categories = get_categories("taxonomy=categories");
          foreach ($categories as $category) : echo '<li><a data-filter=".' . $category->slug . '"  href="#">' . $category->name . '</a></li>';
          endforeach; ?>
          <li><a class="select-cat" data-filter="*" href="#">All Works</a></li>
        </ul>
    
      </div>
    
      <div class="container">
        <div class="row masonry clearfix">
          <!-- a work -->
          <?php $args = array(
            'post_type' => 'portfolio',
            'orderby'   => 'date',
            'order' => 'ASC',
            'posts_per_page' => 100,
          );
    
          $wp_query = new WP_Query($args);
          while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
            <?php $portcolor = get_field('text_color_of_featured_image'); ?>
            <?php $taxonomy = 'categories';
            $terms = get_the_terms($post->ID, 'categories'); ?>
            <?php foreach ($terms as $term)  ?>
            <a href="<?php echo esc_html(get_permalink()); ?>" class="col-xl-4 col-md-6 grid-item <?php echo esc_html($term->slug); ?> <?php echo esc_attr($portcolor); ?>" data-type="ajax-load">
              <figure class="portfolio-item <?php $portfolio_type = get_field('portfolio_type');
                                            echo esc_attr($portfolio_type); ?>">
                <div class="image">
                  <?php $featured_image = get_field('portfolio_featured_image'); ?>
                  <img src="<?php echo esc_url($featured_image['url']); ?>" alt="<?php echo esc_attr($featured_image['alt']); ?>" />
                </div>
    
                <figcaption>
                  <span><?php echo esc_html($term->name); ?></span>
                  <h3 class="title"><?php the_title(); ?></h3>
                </figcaption>
              </figure>
            </a>
          <?php endwhile; 
          // reset global post data
          wp_reset_postdata();?>
        </div>
      </div> <!-- container end -->
    </section>
    
    <?php the_content(); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      相关资源
      最近更新 更多