Domanda

I would like to use multiple, different orbit sliders which are displayed in header. I tried to build if statement using is_page(ID) but it seem not working, after uploading this in my header.php page went blank, only top navigatioan appeared. Can you help me out and improve this code?

 <?php
     if (is_page(112){
      get_template_part('partials/slider3');
     } 
     elseif (is_page(110)) {
      get_template_part('partials/slider2');
     }

?>

<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Support Center</title>

<?php wp_head(); ?>
</head>
<body <?php body_class( );?>>


<?php get_template_part('partials/topbar'); //Topbar navigation ?>
<!-- OFF CANVAS FOUNDATION NAVIGATION -->  
<div class="off-canvas-wrap"> 
<div class="inner-wrap">
<nav class="tab-bar show-for-small">
<section class="left-small">
<a href="#" class="left-off-canvas-toggle menu-icon"><span></span></a>
</section>
<section class="middle tab-bar-section">
<h1 class="title"><i class="fi-first-aid"></i> 
<a href="<?php bloginfo( 'url' );?>">Support Center</a></h1>
</section>
</nav>
<?php get_sidebar('off-canvas'); ?>
È stato utile?

Soluzione

try this:

$page_id = get_queried_object_id();
if ($page_id == 112) {
   get_template_part('partials/slider3');
} elseif ($page_id == 110) {
   get_template_part('partials/slider2');
}

By the way, your forgot a ) here: if (is_page(112){ must be if (is_page(112)) {

Altri suggerimenti

It depends where exactly in header.php you place this code. Give more information, or post whole code of your header.php. Also keep in mind that is_page() function can accept Page ID, Page Title or Page Slug, not only the ID.

Read here the documentation.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top