2016-11-22 8 views
1

Im UnderScoreテーマを使用しています。下はメインのpage.phpテンプレートファイルです。私が目指しているのは、サイドバーのアクティブなウィジェットがサイドバー付きのテンプレートを使用しているが、サイドバーなしのメインコンテンツが960pxのテンプレートをアクティブなウィジェットまたはコンテンツが使用していない場合です。また、ACF(アドバンスカスタムフィールド)を使用しているのでサイドバーもチェックする必要があります。助けを求めるグレートフル。私はおそらく "is_active_sidebar"を使用していると思っていましたが、テンプレートパーツが既にチェックされているので、それを正しく実装する方法が不明です。また、sidebar.phpサイドバーでは、別のページテンプレートを使用してください。

if (! is_active_sidebar('sidebar-1')) { 
    return; 
} 
?> 
<aside id="secondary" class="widget-area" role="complementary"> 
    <?php dynamic_sidebar('sidebar-1'); ?> 
    <?php the_field('sidebar_info'); ?> 
</aside><!-- #secondary --> 

答えて

0

たぶん私は完全にあなたが疑問を理解していないんだけど、あなたはそのためのシンプルなif文を使用することができ、以下の

get_header(); ?> 
<div id="primary" class="content-area"> 
    <main id="main" class="site-main" role="main"> 
     <?php 
     while (have_posts()) : the_post(); 
      get_template_part('template-parts/content', 'page'); 
      // If comments are open or we have at least one comment, load up the comment template. 
      if (comments_open() || get_comments_number()) : 
       comments_template(); 
      endif; 
     endwhile; // End of the loop. 
     ?> 
    </main><!-- #main --> 
</div><!-- #primary --> 
<?php 
get_sidebar(); 
get_footer(); 

。以下の擬似コードを参照してください。

if (active widgets in the sidebar) { 
    // use this formatting 
} else { 
    // use that formatting 
} 
関連する問題