Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Currently I'm having some difficulties with below snippet.

As it currently works it shows the_excerpt_rss on a single post and single page. AND it shows the option on is_home().

But what if a page (instead of the 'blog') is the frontpage? If possible I'd like to include the option as well.

I've tried several versions of including is_front_page() but without any luck thus far.

The snippet I'm currently using:

<?php if (is_single() OR is_page()): if (have_posts()): while (have_posts()): the_post(); ?>
    <meta name="description" content="<?php the_excerpt_rss(); ?>">
<?php endwhile; endif; elseif (is_home()): ?>
    <meta name="description" content="<?php $options = get_option('schema_theme_options'); echo $options['metadescription']; ?>">
<?php endif; ?>
share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

Try if ( 'page' == get_option( 'show_on_front' ) ) {}.

Edit

but I've tried adding and replacing <?php endwhile; endif; elseif (is_home()): ?> with both of your code. Could you perhaps include your snippet with mine?

I'm not sure why you would do that. I was specifically answering this question:

But what if a page (instead of the 'blog') is the frontpage? If possible I'd like to include the option as well.

The answer to that question is what I posted:

`if ( 'page' == get_option( 'show_on_front' )

However, that won't actually solve your problem, if I'm reading your code properly. Reading what you're asking, this should work:

if ( is_single() || is_page() || is_front_page() )

(Note: I used || instead of OR as the Boolean operator.)

To be honest, I'm somewhat surprised that this works on static pages. I didn't know that they generated RSS output.

share|improve this answer
    
if(get_the_ID() == get_option('show_on_front')) {} –  Pippin Jan 18 '12 at 18:22
    
@chip-bennett and @pippin, I'm probably a newb…, but I've tried adding and replacing <?php endwhile; endif; elseif (is_home()): ?> with both of your code. Could you perhaps include your snippet with mine? –  Cor van Noorloos Jan 18 '12 at 18:34
    
@Pippin no; please see my comment to your answer. show_on_front returns either page or posts. You're thinking of page_on_front. –  Chip Bennett Jan 18 '12 at 22:03
    
See updated answer... –  Chip Bennett Jan 18 '12 at 22:17
    
Much appreciated! I've been using the_excerpt_rss for quite some time now for static pages, according to this guide by Nathan Rice. –  Cor van Noorloos Jan 19 '12 at 3:08
add comment
<?php if(get_the_ID() == get_option('show_on_front')) : ?>
     <meta name="description" content="<?php $options = get_option('schema_theme_options'); echo $options['metadescription']; ?>">
<?php elseif(is_single() OR is_page()) : ?>
    <?php if (have_posts()): while (have_posts()): the_post(); ?>
          <meta name="description" content="<?php the_excerpt_rss(); ?>">
    <?php endwhile; endif; ?>
<?php endif; ?>

How's that?

share|improve this answer
    
I think you need get_the_ID() == get_option( 'page_on_front' ). The page_on_front option returns the ID of the static page set to display on the front page. The page_for_posts option returns the ID of the static page set to display the blog posts index. The show_on_front option returns either page or posts, depending on what the front page is set to display. –  Chip Bennett Jan 18 '12 at 22:02
    
Ah, yes, you're right. –  Pippin Jan 19 '12 at 0:53
    
Using page_on_front does indeed do the trick. Thanks a lot! –  Cor van Noorloos Jan 19 '12 at 3:10
add comment

Hopefully I would be within the rules when adding this reply (I've been thinking about editing my original question instead)

First of all, @chip-bennett is right. I haven't been 100% clear when asking my question. I wanted to use the_excerpt_rss for single posts and pages, and if the home page would show a static page or the posts page, I'd like to use the option.

Therefore, for future reference, this is the code I'm currently using:

<?php if (is_home() OR is_front_page()): ?>
    <meta name="description" content="<?php $options = get_option('schema_theme_options'); echo $options['metadescription']; ?>">
<?php elseif (is_single() OR is_page()): if (have_posts()): while (have_posts()): the_post(); ?>
    <meta name="description" content="<?php the_excerpt_rss(); ?>">
<?php endwhile; endif; endif ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.