wordpress页脚在功能后没有加载

时间:2017-02-12 19:07:05

标签: php wordpress

我使用的是php代码,我发现它可以计算出wordpress中的所有图片 但是这个代码页脚和侧边栏都没有加载。我无法修复它。这是我的页面的完整代码。 "计数器代码"在div" photo_gallery_counter" 。之后什么都没有加载

  <?php 
    /*
    Template Name: Страница фотогалереи
    */ ?>
    <?php get_header();?>



    <div class="center-part" style="max-width: 73%;">
      <div class="padding-side" style="margin: 0 40px;">

        <section class="article">
          <div class="h2" style="margin-top: -14px">
          <h2>Фотоальбомы</h2></div>

          <div class="photo_gallery">

            <div class="photo_gallery_grid">
              <?php if (have_posts()) :
              $args = array(
              'post_type' => 'fotoalbum',
              'publish' => true,

              'paged' => get_query_var('paged'),
              );
              query_posts($args);
              while (have_posts()) : the_post(); ?>
              <div class="photo_gallery_album">
                <a href="<?php the_permalink(); ?>" class="photo_gallery_link">
                  <?php
                  $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
                  ?>
                  <div class="photo_gallery_item" style="background-image: url(<?php echo $thumbnail[0]; ?>);">
                    <div class="photo_gallery_item_info">
                      <div class="photo_gallery_title">
                        <?php the_title(); ?>
                      </div>
                      <div class="photo_gallery_counter">
                        <?php

                        // Get all the attachments
                        // Get all the galleries in the current post
                        $galleries = get_post_galleries( get_the_ID(), false );
                        // Count all the galleries
                        $total_gal = count( $galleries );
                        /**
                        * count all the images
                        * @param array $array The array needed
                        * @return int returns the number of images in the post
                        */
                        function _get_total_images( $array ){
                        $key = 0;
                        $src = 0;
                        while ( $key < count( $array ) ){
                        $src += count( $array[$key]['src'] );
                        $key++;
                        }
                        return intval( $src );
                        }
                        echo _get_total_images( $galleries );
                        ?>
                      </div>
                    </div>
                  </div>
                </a>
              </div>
              <?php endwhile;?>
              <?php endif;?>
            </div>
          </div>
        </section>
      </div>

      </div><!-- end of gallery-->

      <?php get_sidebar('single'); ?>
      <?php get_footer(); ?>

1 个答案:

答案 0 :(得分:0)

这是一个php错误导致页面的其余部分无法加载。我注意到你的代码中有一个错误,这可能是罪魁祸首,但也可能有其他错误。变化

$galleries = get_post_galleries( get_the_ID(), false );

$galleries = get_post_gallery( get_the_ID(), false );

有关此功能的更多信息:https://codex.wordpress.org/Function_Reference/get_post_gallery
如果这解决了它,请告诉我:))