競合

2017-04-18 7 views
1

ここでは、レジスタウィジェットサイドバーのための私のコードは// Sidear登録競合

add_action('widgets_init', 'comet_sidebar'); 

function comet_sidebar() { 
    register_sidebar(array(
     'name'   => __('Right Sidebar', 'comet'), 
     'description' => __('Put Right Sidebar here', 'comet'), 
     'id'   => 'right-sidebar', 
     'before_widget' => '<div class="widget">', 
     'after_widget' => '</div>', 
     'before_title' => '<h6 class="upper">', 
     'after_title' => '</h6>', 
    )); 

    register_sidebar(array(
     'name'   => __('Footer Left', 'comet'), 
     'description' => __('Put Footer Sidebar here', 'comet'), 
     'id'   => 'footer-left', 
     'before_widget' => '<div class="col-sm-4"><div class="widget">', 
     'after_widget' => '</div></div>', 
     'before_title' => '<h6 class="upper">', 
     'after_title' => '</h6>', 
    )); 

    register_sidebar(array(
     'name'   => __('Footer Right', 'comet'), 
     'description' => __('Put Footer Sidebar here', 'comet'), 
     'id'   => 'footer-right', 
     'before_widget' => '<div class="col-sm-4"><div class="widget">', 
     'after_widget' => '</div></div>', 
     'before_title' => '<h6 class="upper">', 
     'after_title' => '</h6>', 
    )); 

} 

そして、ここでは私の別のPHPファイルである

です。私はこのファイルを必要とするとき、私はgallery.php

<?php 


add_shortcode('gallery', 'comet_gallery'); 

function comet_gallery($attr, $content) { 
    $att = shortcode_atts(array(
     'ids' => '', 
    ), $attr);   

    extract($att); 

    $idd = explode(',', $ids); 

    ob_start(); ?> 
    <div data-options="{&quot;animation&quot;: &quot;slide&quot;, &quot;controlNav&quot;: true" class="flexslider nav-outside"> 
     <ul class="slides"> 
      <?php foreach($idd as $id) : ?> 
      <?php $musa = wp_get_attachment_image_src($id, 'full'); ?> 

      <li><img src="<?php echo $musa [0]; ?>"></li> 
      <?php endforeach; ?> 
     </ul> 
    </div> 

    <?php return ob_get_clean(); 

} 

ため

if(file_exists(dirname(__FILE__). '/gallery.php')) { 
    require_once(dirname(__FILE__). '/gallery.php'); 
} 

コードを必要としています。私のウィジェットの設定が正しく動作しません。これを削除すると、ファイルが必要です。それは完璧に働いています。 ありがとう

+0

何をgallery.phpであり、まさに起こってないだけウィジェットの設定が正しく機能していないか、空白を得るのですか/?壊れたページ? – Gazi

+0

私はgallery.phpのコードを追加しました – Musarrof

+0

私はちょうど私の答えを編集しました。 – Gazi

答えて

1

私はreturn ob_get_clean();が正しいとは思わない。

代わりにこれを試してみてください:

<?php 
add_shortcode('gallery', 'comet_gallery'); 

function comet_gallery($attr, $content) { 
    $att = shortcode_atts(array(
     'ids' => '', 
    ), $attr);   

    extract($att); 

    $idd = explode(',', $ids); 
?> 
    <div data-options="{&quot;animation&quot;: &quot;slide&quot;, &quot;controlNav&quot;: true" class="flexslider nav-outside"> 
     <ul class="slides"> 
      <?php foreach($idd as $id) : ?> 
      <?php $musa = wp_get_attachment_image_src($id, 'full'); ?> 

      <li><img src="<?php echo $musa [0]; ?>"></li> 
      <?php endforeach; ?> 
     </ul> 
    </div> 

    <?php return $content; 

} 
function comet_gallery_start() { ob_start("comet_gallery"); } 
function comet_gallery_end() { ob_end_flush(); } 
add_action('wp_head', 'comet_gallery_start'); 
add_action('wp_footer', 'comet_gallery_end'); 

require_once(TEMPLATEPATH."/gallery.php");