2017-04-18 148 views
1

這裏是我的寄存器窗口小部件側邊欄的衝突的Widget功能

// 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文件中的代碼。我已經要求

if(file_exists(dirname(__FILE__). '/gallery.php')) { 
    require_once(dirname(__FILE__). '/gallery.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(); 

} 

當我需要這個文件。我的小工具設置無法正常工作。如果我刪除這個需求文件。它的工作完美。 謝謝

+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");