简体   繁体   中英

How to remove a sidebar for certain URLs?

I have a site that displays training courses - each training course uses the same page template which has a sidebar advertising the dates the training is running. I wish to remove this sidebar from 2 of my courses, but not from any of the others.

Each course has an ID which appears in the URL, so I have been attempting to filter via this.

if(window.location.indexOf("2"))
{
  $('#course-sidebar').hide();

}

This does not cause any errors, but also does not hide the sidebar for course 2.

I hope it is better to be done in the php.

In the page where you have the side bar add a if condition to check if the urlsegment=2.

First get the desired url segment to be checked

<?php $uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

if($uriSegments[3] !=2 && $uriSegments[3] !=x) { ?>
<sidebar>
--Html code for sidebar--

</sidebar>
<?php } ?>

so the sidebar html code will be visible only when the id is not equals to your desired course id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM