Using is_page() function for Page with custom WP_Query
-
I’m having a few problems with a WordPress page which uses a custom WP_Query. Here’s an example of the page.
Essentially the problem is when I try to detect the page in my code using the is_page it fails. is_page() is used for highlighting the current page in the site’s navigation menu, it appears to fail when I try and test for the page name is_page(‘image-archive’) which is the page the template is attached to. Is this in any way due to the the manner in which I have used WP_Query?
To put into context the image archive page utilises the Yet Another Photoblog plugin and displays a thumbnail for every post created on the blog. Is the page correct or should I be displaying the information in another way.
Any help with this would be greatly appreciated.
Here is the navbar code called,
<!-- Fixed navbar --> <div class="navbar navbar-fixed-top navbar-inverse"> <div class="navbar-inner"> <div class="container"> <a id="navbar-btn" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <?php if(is_home()): ?> <div id="navbar-branding"><a id="logo" class="brand pull-left" href="<?php bloginfo('url' ); ?>"> <?php echo bloginfo('name' ); ?>:</a></div> <?php the_title('<h1 class="pull-left" id="header-title">','</h1>'); ?> <?php elseif(is_single() || is_page('about-me') || is_page('image-archive') || is_page('contact-me')): ?> <div id="navbar-branding"><a id="logo" class="brand pull-left" href="<?php bloginfo('url' ); ?>"><?php echo bloginfo('name' ); ?>:</a></div> <?php the_title('<h1 class="pull-left" id="header-title">','</h1>'); ?> <?php elseif(is_tag()): ?> <div id="navbar-branding"><a id="logo" class="brand pull-left" href="<?php bloginfo('url' ); ?>"><?php echo bloginfo('name' ); ?>:</a></div> <h1 class="pull-left" id="header-title">Tag</h1> <?php elseif(is_category()): ?> <div id="navbar-branding"><a id="logo" class="brand pull-left" href="<?php bloginfo('url' ); ?>"><?php echo bloginfo('name' ); ?>:</a></div> <h1 class="pull-left" id="header-title">Category</h1> <?php elseif(is_search()): ?> <div id="navbar-branding"><a id="logo" class="brand pull-left" href="<?php bloginfo('url' ); ?>"><?php echo bloginfo('name' ); ?>:</a></div> <h1 class="pull-left" id="header-title">Search Results</h1> <?php elseif(is_404()): ?> <div id="navbar-branding"><a id="logo" class="brand pull-left" href="<?php bloginfo('url' ); ?>"><?php echo bloginfo('name' ); ?></a></div> <?php endif; ?> <div class="nav-collapse collapse"> <ul class="nav pull-right"> <li id="mobile-home" <?php if ( is_home()) { echo ' class="active"'; } ?>><a href="<?php bloginfo('url' ); ?>">Home</a></li> <li <?php if ( is_page('about-me')) { echo ' class="active"'; } ?>><a href="<?php echo esc_url( get_permalink( get_page_by_title( 'about me' ) ) ); ?>">About</a></li> <li <?php if ( is_page('image-archive')) { echo ' class="active"'; } ?>><a href="<?php echo esc_url( get_permalink( get_page_by_title( 'image archive' ) ) ); ?>">Archive</a></li> <li <?php if ( is_page('contact-me')) { echo ' class="active"'; } ?>><a href="<?php echo esc_url( get_permalink( get_page_by_title( 'contact me' ) ) ); ?>">Contact</a></li> <li><a href="<?php echo get_a_random_post(); ?>">Random</a></li> <li><?php get_search_form(); ?></li> </ul> </div><!--/.nav-collapse --> </div> </div> </div>and the code for the image-archive template,
<?php /* Template Name: Image-Archive */ $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('showposts=10'.'&paged='.$paged); get_header(); get_template_part('navbar'); ?> <!-- Begin page content --> <div class="container"> <div class="row"> <div class="span8"> <div class="row"> <div id="upper-pagination" class="pagination span7"> <?php paginate(); ?> // Calls custom pagination function to paginate image thumbnails. </div> </div> <div class="row"> <div class="span7"> <ul class="thumbnails"> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <?php // Let's define the needed thumbnail format $thumbConfig = array('w=100','h=100','zc=1'); ?> <?php if (!is_null($image = YapbImage::getInstanceFromDb($post->ID))): ?> <li> <div class="thumbnail"> <a class="thumbnail" title="<?php the_title(); ?>" href="<?php echo get_permalink($post->ID); ?>"> <img src="<?php echo $image->getThumbnailHref($thumbConfig) ?>" width="<?php echo $image->getThumbnailWidth($thumbConfig) ?>" height="<?php echo $image->getThumbnailHeight($thumbConfig) ?>" alt="<?php the_title(); ?>" /> </a> </div> </li> <?php endif ?> <?php endwhile; ?> </ul> </div> </div> <div class="row"> <div class="pagination span7"> <?php paginate(); ?> // Calls custom pagination function to paginate image thumbnails. </div> </div> </div> <div class="span4"> <?php get_template_part('display_archive_sidebar'); ?> </div> </div> </div> <div id="push"></div> </div> <!-- End wrap --> <?php get_template_part('info_page_footer'); ?> <?php $wp_query = null; $wp_query = $temp; get_footer(); ?>
The topic ‘Using is_page() function for Page with custom WP_Query’ is closed to new replies.