最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sidebar - How do I set is_active_sidebar?

programmeradmin1浏览0评论

I have a Page like:

<?php 
/* 
    Template Name: Agenda
*/
get_header(); ?>
<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            My Hompagetext
        </main><!-- #main -->
    </div><!-- #primary -->
    <?php get_sidebar('test'); ?>
</div><!-- .wrap -->
<?php get_footer();?>

I have a sidebar called: sidebar-test.php

<aside id="secondary" class="widget-area" role="complementary" aria-label="<?php esc_attr_e( 'Test Sidebar', 'rczo2' ); ?>">
    this text is displayed on the bottom but I want it in the sidebar on the right side
</aside><!-- #secondary -->

I tryed reading across the WP-documentation and found how to register a widget, but not how to include a simple script like this.

I have a Page like:

<?php 
/* 
    Template Name: Agenda
*/
get_header(); ?>
<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            My Hompagetext
        </main><!-- #main -->
    </div><!-- #primary -->
    <?php get_sidebar('test'); ?>
</div><!-- .wrap -->
<?php get_footer();?>

I have a sidebar called: sidebar-test.php

<aside id="secondary" class="widget-area" role="complementary" aria-label="<?php esc_attr_e( 'Test Sidebar', 'rczo2' ); ?>">
    this text is displayed on the bottom but I want it in the sidebar on the right side
</aside><!-- #secondary -->

I tryed reading across the WP-documentation and found how to register a widget, but not how to include a simple script like this.

Share Improve this question asked Feb 10, 2020 at 13:19 ratmalwerratmalwer 1011 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 0

I believe, reading your question, you are asking how to call up a widget that you've registered? If so, in the overall sidebar template (likely, sidebar.php), at the point where you want the widget to show, if the sidebar widget is named 'sidebar-test', add:

<?php if ( is_active_sidebar( 'sidebar-test' ) ) dynamic_sidebar( 'sidebar-test' ); ?>

I had to add:

<body <?php body_class('has-sidebar'); ?>>

to the header of my Page

发布评论

评论列表(0)

  1. 暂无评论