问:看起来我已经能够将sidebar.php移植到我的页面(archive.php)中,但是当我在Wordpress管理区域中启用小部件时,它们中没有一个显示在我的小部件化区域中。(如果我将其他东西(例如标题或div)放到sidebar.php中,它将进入页面的最终呈现,但是所有小部件都不会通过。有什么想法吗?
Sidebar.php
<?php dynamic_sidebar ('sidebar_widgets' ); ?>
Functions.php
函数wp_ua_create_widget($ name,$ id,$ description){
register_sidebar(array(
'name'=> __($ name),
'id'=> $ id,
'description'=> __($ description),
'before_widget' =>'<div class =“ widget”>',
'after_widget'=>'</ div>',
'before_title'=>'<h2 class =“ module-heading”>',
'after_title'=>'< / h2>'
));
}
wp_ua_create_widget('Sidebar Widgets','sidebar_widgets','显示在侧栏中');
存档.php
<?php get_sidebar (); ?>
答:您的代码似乎很好。请问您的archive.php看起来如何?或者您只是其中有get_sidebar()?
答:这是archive.php文件-(请原谅丑陋,尚未设置任何样式-只是试图将骨骼放置到位。)
<?php
/ *
模板名称:右侧边栏
* /
?>
<?php get_header (); ?>
<! -将代码创建主要内容列在这里- >
<DIV CLASS = “领头羊”> <H1> <PHP?wp_title ('' ); ?> Blog Posts </ h1> </ div <!-启动WP循环(容器元素应位于循环外部,重复元素应位于循环内部)-> <?php if (have_posts ()):while (have_posts ()):the_post (); ?>
<h1> <a href =' <?php the_permalink (); ?> '> <?php the_title (); ?> </a> </ h1>
<ul class =“ post-meta no-bullet”>
<li class =“ author”>通过<?php the_author_posts_link (); ?> </ li>
<li class =“ cat”> <?php the_category (',' ); ?> </ li>
<li class =“ date”>在<?php the_time ('F j,Y' ); ?> </ li>
</ ul>
< ?>
<div class =“ img-container”>
<?php the_post_thumbnail ('small' ); ?>
</ div>
<?php endif ; ?>
<p> <?php echo strip_tags (get_the_excerpt () ); ?> </ p>
<!-结束WP循环-> <?php endwhile ; 其他:?>
<p> <?php _e ( “抱歉,找不到该页面。” ); ?> </ p>
<?php endif ; ?>
<!-在此处放置创建侧边栏列的代码->
<?php get_sidebar (); ?>
<?php get_footer (); ?>