最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sidebar - display menus on all page except one?

programmeradmin0浏览0评论

I'm not very good at this, so please bear with me. I have a Wordpress site with sections for different cites, and the different cities each have their own nav menu which shows for all of the pages in that city.

if ( is_page( 'phnom-penh' ) || in_array( '11760', $ancestors ) ) :
    get_sidebar( 'city-phnom-penh' );

However, I want to remove the menu/sidebar just from one page in the Phnom Penh section so I can add a widgetized sidebar to that page instead. Is it possible to have this sidebar apply to all pages in that section except for one?

I'm not very good at this, so please bear with me. I have a Wordpress site with sections for different cites, and the different cities each have their own nav menu which shows for all of the pages in that city.

if ( is_page( 'phnom-penh' ) || in_array( '11760', $ancestors ) ) :
    get_sidebar( 'city-phnom-penh' );

However, I want to remove the menu/sidebar just from one page in the Phnom Penh section so I can add a widgetized sidebar to that page instead. Is it possible to have this sidebar apply to all pages in that section except for one?

Share Improve this question asked Jan 29, 2021 at 12:07 LinaLina 112 bronze badges 2
  • Yes - it's possible - does your code not work, if not, what errors do you get? - perhaps try ! is_page( 'phnom-penh' ) – Q Studio Commented Jan 29, 2021 at 12:22
  • Sorry, I don't understand what you mean. The code above puts the sidebar on all pages within the phnom-penh section, but I want to specifically exclude one page within that secion. How do I do that? – Lina Commented Jan 29, 2021 at 13:30
Add a comment  | 

1 Answer 1

Reset to default 0

As I noted in my comment, you can use the negation operator, like so:

if ( ! is_page( 'phnom-penh' ) ) {
    get_sidebar( 'not-phnom-penh' );
} else {
    get_sidebar( 'phnom-penh' );
}

Note the ! before the is_page - that means NOT.

Also note that if you use more than once condition via || or OR and either of the conditions returns true - the sidebar will be returned.

发布评论

评论列表(0)

  1. 暂无评论