我正在开发一个wordpress主题,但坚持widgetizing我的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>
你能帮助我吗,好几天我很沮丧:(。 感谢您在Advance中提供的帮助。
答案 0 :(得分:3)
将这行代码放在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; ?>
答案 1 :(得分:1)
我前几天使用这个很棒的教程来制作小部件,它运行正常,如果您按照所有步骤操作,您会看到管理员端显示小部件选项:http://wp.tutsplus.com/tutorials/creative-coding/building-custom-wordpress-widgets/