dpfwhb7470 2019-08-05 08:58
浏览 58

如何使用get_template_part()修复错误

i'm trying to solve a problem with get_template_part() and some code that i need to include

I create a first file with some code and include this with the function get_template_part() and this work correctly, but when a try with a second part of code in another file, this generate an error.

THE CODE INSIDE FILE:

<div class="container padding-100-top-bottom main-padding-mobile">

  <div class="row padding-50-bottom">
    <div class="col-sm-12">
      <h1 class="animated fadeInUp">Los mejores tours de Roma</h1>
      <h5 class="animated fadeInUp" style="font-weight: 400;">Ver todos los tours <i class="gdlr-core-pos-right fa fa-long-arrow-right" style="font-size: 17px ;     margin-left: 10px;"></i></h5>
    </div>
  </div>

  <div class="row">
    <?php
        // Setup your custom query
        $args = array(
          'post_type' => 'product',
          'posts_per_page' => 6,
        );
        $loop = new WP_Query($args);

        while ($loop->have_posts()) : $loop->the_post(); ?>
    <div class="col-sm-6 col-md-6 col-lg-4 animated fadeInUp">
      <div class="card" style="margin-bottom: 30px;">
        <div class="sezione_home_tours_img" style="background-image: url('<?php echo get_the_post_thumbnail_url(); ?>');">
        </div>
        <div class="card-body">
          <h5 class="card-title"><?php the_title(); ?></h5>
          <div class="contenitore_info_card">
            <ul>
              <li><i class="fas fa-map-signs"></i> <?php the_field('start_from'); ?></li>
              <li><i class="far fa-clock"></i> <?php the_field('duration'); ?></li>
            </ul>
            <div class="sezione_home_tours_card_prezzo">
              <h6>A partir de</h6>
              <h3><?php echo $product->get_price_html(); ?></h3>
            </div>
          </div>
        </div>
      </div>
    </div>
    <?php endwhile; wp_reset_query(); // Remember to reset?>
  </div>
</div>

THE ERROR GENERATED:

error: Uncaught Error: Call to a member function get_price_html() on null in /app/public/wp-content/themes/transportes-child/template-parts/home-sezione-roma.php:33 Stack trace: #0 /app/public/wp-includes/template.php(724): require()

1 /app/public/wp-includes/template.php(671): load_template('/app/public/wp-...', false) #2

/app/public/wp-includes/general-template.php(168): locate_template(Array, true, false) #3 /app/public/wp-content/themes/transportes-child/page-template/home.php(19): get_template_part('template-parts/...', 'sezione-roma') #4 /app/public/wp-includes/template-loader.php(78): include('/app/public/wp-...') #5 /app/public/wp-blog-header.php(19): require_once('/app/public/wp-...') #6 /app/public/index.php(17): require('/app/public/wp-...') #7 {main} thrown in /app/public/wp-content/themes/transportes-child/template-parts/home-sezione-roma.php on line 33

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据