I'm currently using this loop:
if (is_single() || is_page() ) :
if (have_posts() ) :
while (have_posts() ) :
the_post();
How can I exclude multiple pages within the loop?
For an example, I want to exclude pages example.com/music
and example.com/contact
.
EDIT:
I've done the way G.M provide, but my music and contact pages keeps loading after apply.
<?php if (is_single() || is_page() ) : if (have_posts() ) : $exclude_pages = array('music', 'contact'); while (have_posts() ) : if ( is_page() && ! empty($exclude_pages) && (
in_array($post->post_name, (array)$exclude_pages) ||
in_array($post->post_name, (array)$exclude_pages)
) ) continue; the_post(); ?>
<meta name="description" content="<?php the_content_limit(150)?>" />
// loop continues
<?php endwhile; endif;
elseif (is_home() ): ?>
// loop continues
<?php endif; ?>
<?php if( is_page( 'music' )) { ?>
<meta property="og:image" content="" />
//loop continues
<?php } ?>
So to clarify: I'd like to exclude some meta tags that i'm generating via a loop in the header.php Now with my loop, all pages and post get affected by the loop. So I don't want the pages music and contact to have the same header tags from the loop in header.php.
page.php
or somewhere else? If this loop the main or are you usingquery_posts
to generate a custom loop? The loop in the header, how is generated? withWP_Query
,query_posts
orget_posts
? – gmazzap♦ Aug 31 '13 at 15:45