2016-07-26 14 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

を私はこれが表示されませんあなたのコードですが、どのようにfunctions.phpをindex.phpに含めますか? 'require'または 'require_once'を使用していますか? functions.phpはfunction.phpから任意の関数を呼び出す前にindex.phpに含める必要があります – CharlesEF

+0

@CharlesEF ahhh確認してみましょう – MikeL5799

+0

この問題を解決しましたか? – CharlesEF

答えて

0

[OK]を、ので、私はこれらの行を追加の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

を書いてみます

次に、目的の機能を呼び出す前と後でエコーからメッセージを見ることができるかどうかを確認します。

+0

ありがとうフォンオーク。この2つのメッセージはうまく印刷されますが、ギャラリーは表示されません。 – MikeL5799

+0

index.phpは実際にうまくいきます。ギャラリー機能の呼び出しが機能していないだけです。 – MikeL5799

+0

エラー報告を有効にしましたか? 'error_reporting(E_ALL);ini_set( "display_errors"、1); 'テストの目的で、これらの行をスクリプトの先頭に追加します。 index.phpファイルの –

関連する問題