【问题标题】:Widget not displayed in Wordpress小部件未显示在 Wordpress 中
【发布时间】:2018-03-14 12:41:05
【问题描述】:

我的 Wordpress 小部件中有一个探针。我在 HTML 中创建了一个 Wordpress 模板。我想在我的关于我们页面上添加这个小部件,但是没有显示这个小部件。

这是我在function.php中的代码

function wpb_widgets_init() {

    register_sidebar( array(
        'name'          => 'Custom Header Widget Area',
        'id'            => 'custom-header-widget',
        'before_widget' => '<div class="chw-widget">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="chw-title">',
        'after_title'   => '</h2>',
    ) );
}
add_action( 'widgets_init', 'wpb_widgets_init' );

这段代码是我的主题page-about.php:

<?php
    if ( is_active_sidebar( 'custom-header-widget' ) ) : ?>
        <div id="header-widget-area" class="chw-widget-area widget-area" role="complementary">
        <?php dynamic_sidebar( 'custom-header-widget' ); ?>
        </div>

    <?php endif; ?>

我该如何解决这个问题?

【问题讨论】:

    标签: php html wordpress plugins widget


    【解决方案1】:

    function.php

    中添加如下代码
    function wpb_widgets_init() {
    
    register_sidebar( array(
        'name'          => 'Custom Header Widget Area',
        'id'            => 'custom-header-widget',
        'before_widget' => '<div class="chw-widget">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="chw-title">',
        'after_title'   => '</h2>',
       ) );
    }
    
    add_action( 'widgets_init', 'wpb_widgets_init' );
    

    并将此代码添加到您的 page-about.php

    <?php
     if ( is_active_sidebar( 'custom-header-widget' ) ) : ?>
        <div id="header-widget-area" class="chw-widget-area widget-area" role="complementary">
        <?php dynamic_sidebar( 'custom-header-widget' ); ?>
        </div>
    
    <?php endif; ?>
    

    【讨论】:

    • 我试过了,但是一样。 widged 没有显示。嗯..发生了什么?
    • @MuhammadAntok Antok 在你最后一行的代码中 ` 符号来了
    • 那么可能你的php标签打开和关闭不匹配
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多