2016-07-26 7 views
0

특정 페이지에 갤러리를 표시하려면 function.php 페이지에 쓴 함수가 있습니다. 그것은 사용자 정의 템플릿을 표시하지만 지금은 index.php를 여기에 표시 내 functions.php 파일의 코드가 필요합니다PHP 함수 호출이 index.php에서 작동하지 않습니다.

function min_get_page_gallery($echo = true) { 
global $post; 



$show_gallery = get_post_meta($post->ID, 'min_gallery-show', true); 

if (empty($show_gallery)) { 
    return; 
} 

$gallery  = get_post_meta($post->ID, 'min_image_advanced', false); 

ob_start(); 
?> 
<div class="gallery" id="gallery-<?php echo $post->ID; ?>"> 
    <button class="gallery-move-left"><i class="fa fa-arrow-circle-left"  aria-hidden="true"></i></button> 
    <div class="image_container clearfix"> 

     <?php 
      $count = count($gallery); 
      $num = ceil($count/3); 
      //$width_container = $num * 100; 
      //$width_row = 100/$num; 
      //echo '<div class="gallery_inner" style="width:' . $width_container . '%;">'; 
      echo '<div class="gallery_inner">'; 
      for ($i = 0; $i < $count; $i++) { 
       if ($i % 3 == 0) { 
        //echo '<div class="row" style="width: ' . $width_row . '%;">'; 
        echo '<div class="row'. (0 == $i ? ' active': ' inactive') .'">'; 
       } 
       echo '<div class="col-sm-4 img_container' . (0 == $i ? ' active': ' inactive') . '">'; 
       echo wp_get_attachment_image($gallery[$i], 'thumb-gallery'); 
       echo '</div>'; 
       if ($i % 3 == 2 || ($i+1) == $count) { 
        echo '</div>'; 
       } 

      } 
      echo '</div>'; 
     ?> 
    </div> 
    <button class="gallery-move-right"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i></button> 
</div> 
<?php 
$return = ob_get_contents(); 
ob_end_clean(); 

if ($echo) { 
    echo $return; 
    } else { 
     return $return; 
    } 

} 

그 코드가 마법처럼 작동이. 여기를 min_get_page_gallery()라고 부릅니다. awards.php에서 완벽하게 작동 여기서

<?php 
/* Template Name: Awards Page Template */ 

get_header(); ?> 

<div class="container" id="block-no-sidebar"> 
    <h1><?php the_title(); ?></h1> 
<div id="award-list"> 
    <?php echo min_get_awards(); ?> 
</div> 
<div class="row"> 
    <?php min_get_page_gallery(); ?> 
</div> 
    <?php min_get_page_tabs(); ?> 
</div> 
<?php get_footer(); ?> 

이제 마지막으로, 나는 min_get_page_gallery 같은 함수 호출()를 추가하려고; 이처럼 내 index.php 파일에서 :

<?php 
    // Silence is golden. 
     if (! defined ('ABSPATH')) { 
     exit; 
     } 
    ?> 

    <?php get_header(); ?> 

     <style class="take-to-head"> 
      #block-main-content-with-sidebar { background: #ffffff; } 
     </style> 

     <div class="container" id="block-main-content-with-sidebar"> 
     <div class="row"> 

     <div class="col-sm-8"> 
      <?php 
      if (have_posts()) : while (have_posts()) : the_post(); 
       l('block-' . get_post_type()); 
      endwhile; else: 
       l('block-none'); 
      endif; 

      ?> 

     </div> 
     <div class="col-sm-4"> 
      <?php l('block-sidebar'); ?> 
     </div> 
     </div> 
     <div class="row"> 
      <?php min_get_page_gallery(); ?> 
     </div> 
    </div> 

는 내가 부족 뭔가가 있나요?

+0

내가이 표시되지 않습니다를 귀하의 코드하지만 어떻게 index.php에 functions.php를 포함합니까? 'require'또는 'require_once'를 사용합니까? functions.php는 functions.php에서 어떤 함수를 호출하기 전에 index.php에 포함되어야합니다. – CharlesEF

+0

@CharlesEF 확인해 보겠습니다. – MikeL5799

+0

이 문제를 해결 한 적이 있습니까? – CharlesEF

답변

0

좋아, 그래서 메타 내가이 라인을 추가 functions.php에 표시 할 얻기 위해 일부 조정을했다 : 다음 $pagemain = is_page();

과 :

if ($pagemain == is_page(35393) ) { 
    $meta[] = array(
     'id'   => 'imageupload', 
     'post_types' => array('page'), 
     'context' => 'normal', 
     'priority' => 'high', 
     'title' => __('Image Gallery', 'min'), 
     'fields' => array(
      array(
       'name' => __('Show', 'min'), 
       'id' => "{$prefix}_gallery-show", 
       'desc' => __('', 'meta-box'), 
       'type' => 'checkbox', 
       'clone' => false, 
      ), 
      array(
       'id'    => "{$prefix}_image_advanced", 
       'name'    => __('Image Advanced', 'min'), 
       'type'    => 'image_advanced', 
       // Delete image from Media Library when remove it from post meta? 
       // Note: it might affect other posts if you use same image for multiple posts 
       'force_delete'  => false, 
       // Maximum image uploads 
       //'max_file_uploads' => 2, 
      ), 
     ), 
    ); 
} 
0

index.php의 문제점을 자세히 설명해주십시오. 일부 출력은 input.php이거나 빈 페이지입니까?

올바르게 정의 되었습니까? ABSPATH? 그렇지 않으면 스크립트가 처음에 종료됩니다.

스크립트를 통해 흐름의보다 구체적인 인식에 대한

, 일부 echo

이 일예를 작성하려고

<div class="row"> 
    <?php echo "Before calling min_get_page_gallery()" ?> 
    <?php min_get_page_gallery(); ?> 
    <?php echo "After calling min_get_page_gallery()" ?> 
</div> 

그런 다음 원하는 기능을 호출하기 전과 후에 에코의 메시지를 볼 수 있다면보십시오.

+0

고마워요 폰 오크. 이 두 메시지는 잘 인쇄되지만 갤러리는 인쇄되지 않습니다. – MikeL5799

+0

index.php는 실제로 잘 작동합니다. 갤러리 함수에 대한 호출이 작동하지 않습니다. – MikeL5799

+0

오류보고를 활성화 했습니까? 'error_reporting (E_ALL);ini_set ("display_errors", 1);'테스트 목적으로 스크립트 시작 부분에 다음 행을 추가하십시오. index.php 파일의 –

관련 문제