0

我正在开发一个 wordpress 主题,但坚持对我的 wp 主题进行小部件化,我遵循了几个教程但仍然无法工作。我的小部件菜单未出现在仪表板上的外观下。这是我的函数和侧边栏:function.php: http: //pastebin.com/X679LmVM

<?php

function custom_enqueue_scripts() {

        wp_deregister_script( 'jquery' );

        wp_register_script( 'jquery', get_template_directory_uri() . '/bin/js/jquery-1.10.1.min.js', 'jquery', '1.10.1',TRUE);
        wp_register_script( 'fittext', get_template_directory_uri() . '/bin/js/jquery.fittext.js', 'jquery', '1.0',TRUE );

        wp_enqueue_script( 'jquery' );
        wp_enqueue_script( 'fittext' );

}
add_action( 'wp_enqueue_scripts', 'custom_enqueue_scripts' );

if (function_exists('register_sidebar')) {

        register_sidebar(array(
                'name' => 'Widgetized Area',
                'id'   => 'katuhu',
                'description'   => 'This is a widgetized area.',
                'before_widget' => '<div id="%1$s" class="widget %2$s">',
                'after_widget'  => '</div>',
                'before_title'  => '<h4>',
                'after_title'   => '</h4>'
        ));

}

?>

sidebar.php: http: //pastebin.com/0TvAKBZy

<div id="katuhu">

        <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Widgetized Area')) : else : ?>

        <div class="pre-widget">
                <p><strong>Widgetized Area</strong></p>
                <p>This panel is active and ready for you to add some widgets via the WP Admin</p>
        </div>

        <?php endif; ?>

</div>

你能帮帮我吗,我沮丧了好几天:(。谢谢你提前的帮助。

4

2 回答 2

2

将这行代码放在function.php中

if (function_exists("register_sidebar")) {
register_sidebar();
}

把它放到 sidebar.php

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php $image = new WP_query ('showposts=1');
if(have_posts()) : while($image->have_posts()) : $image->the_post; ?>

  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to 
 <?php  the_title_attribute(); ?>"><?php postimage(); ?></a>

 <?php endwhile; endif; rewind_posts; ?>
于 2014-02-10T12:20:42.723 回答
1

前几天我用这个很棒的教程来制作一个小部件,它工作正常,如果你按照所有步骤操作,你会看到小部件选项出现在你的管理端:http ://wp.tutsplus.com/tutorials/创意编码/构建自定义wordpress-widgets/

于 2013-07-17T09:14:36.370 回答