1

ショートコードを作成して使用してサイドバーを追加しようとしています。サイドバーを表示することはできますが、その後、ページの下部にボタンを作成するカスタム メタで問題が発生しますthe_content();。これはショートコードを作成するコードです[sidebar]:

function sidebar_sc( $atts ) {
ob_start();
dynamic_sidebar('Sidebar');
$html = ob_get_contents();
ob_end_clean();
return '
<aside id="sidebar">'.$html.'</aside>';
}
add_shortcode('sidebar', 'sidebar_sc');

私のページテンプレートにはこれがあります:

<?php echo the_content(); ?>
<?php if($meta_button_t_1 || $meta_button_t_2 || $meta_button_t_3) { ?>
<?php get_template_part('section', 'pageButtons'); ?>
<?php } ?>

そして、テンプレート パーツ「pageButtons」には次のものがあります。

<div id="page_buttons" class="<?php echo $class; ?>">
<?php if($meta_button_t_1) { ?>
<a href="<?php echo $meta_button_h_1; ?>" class="cr_btn_large" title="The Revolving Stage Co: <?php echo $meta_button_t_1; ?>" id="page_button_1"><?php echo $meta_button_t_1; ?></a>
<?php } if($meta_button_t_2) { ?>
<a href="<?php echo $meta_button_h_2; ?>" class="cr_btn_large" title="The Revolving Stage Co: <?php echo $meta_button_t_2; ?>" id="page_button_2"><?php echo $meta_button_t_2; ?></a>
<?php } if($meta_button_t_3) { ?>
<a href="<?php echo $meta_button_h_3; ?>" class="cr_btn_large" title="The Revolving Stage Co: <?php echo $meta_button_t_3; ?>" id="page_button_3"><?php echo $meta_button_t_3; ?></a>
<?php } ?>
</div>

ショートコードを使用しない場合[sidebar]、ボタンは正常に表示されます。ショートコードを含めると、divが得られますが、空です。の前にテンプレート部分を含めると、the_content();明らかに間違った場所にあることを除いて、すべてが機能します。

4

0 に答える 0