我的新网站使用Wordpress。现在我已经为我网站上的每个页面添加了四个特殊的侧边栏。我试着使用每个页面的插件来激活该页面的侧边栏。我知道你也有插件为你做这个。但我希望一切都是自动的。:)
我知道如何将网页命名为slug。您可以使用以下php代码来完成此操作:
<?php the_slug();?>
我知道我可以用下面的代码调用每个页面的侧边栏:
<?php if ( is_active_sidebar( 'SIDEBAR-NAME-FOR-THAT-PAGE ' ) ) {?>
<ul id="sidebar">
<?php get_sidebar(); ?>
</ul>
<?php } else { ?>
//empty
<?php } ?>
但现在的事情。我将侧边栏命名为每个页面的不同部分。我想让SIDEBAR-NAME和弹头一样。所以我需要把它命名为:
<?php the_slug();?>
在上面的例子中,放在sidebar - name - for - page的位置。我已经试过了:
<?php if ( is_active_sidebar( ' 'tag=' the_slug() ' ) ) {?>
<ul id="sidebar">
<?php get_sidebar(); ?>
</ul>
<?php } else { ?>
//empty
<?php } ?>
但似乎什么也没发生。
有人知道吗?太好了!谢谢了。
不太熟悉WP,但我认为你应该这样写。
<?php if ( is_active_sidebar( 'tag=' . the_slug() ) ) { ?>
<ul id="sidebar">
<?php get_sidebar(); ?>
</ul>
<?php } else { ?>
//empty
<?php } ?>
或者这样
<?php if ( is_active_sidebar( the_slug() ) ) { ?>
<ul id="sidebar">
<?php get_sidebar(); ?>
</ul>
<?php } else { ?>
//empty
<?php } ?>