Support » Themes and Templates » Help with If/else code

  • I have a movie website and im starting to use the tags-description to show som info about actors. I would like the tags-description and title only to show on the page if there is a tag-description written.

    I suppose i should do some if/else code but I dont know anything about that. The code I got now in my tag.php is

    <div id="tag-title"><?php single_tag_title(); ?></div>
    		<div id="tag-description"><?php echo tag_description(); ?></div>
    		<?php if ( is_tag() && tag_description() ) : ?>
    	<meta name="description" content="<?php echo wp_specialchars( strip_tags( tag_description() ), 1 ); ?>" />
    <?php endif; ?>

    Please help

    /Christian

    http://www.onyanserat.se

Viewing 15 replies - 1 through 15 (of 30 total)
  • You can’t use a meta line in the body of a web page.

    Thread Starter lillprinsen

    (@lillprinsen)

    Is there any way to achive what I want?

    Try:

    <div id="tag-title"><?php single_tag_title(); ?></div>
    		<div id="tag-description"><?php echo tag_description(); ?></div>
    		<?php if ( is_tag() && tag_description() ) : ?>
    	<div class="tag=description"><?php echo esc_html( strip_tags( tag_description() ), 1 ); ?>" /></div>
    <?php endif; ?
    Thread Starter lillprinsen

    (@lillprinsen)

    I get this error: Parse error: syntax error, unexpected ‘?’ in /home/web80729/domains/onyanserat.se/public_html/wp-content/themes/Onyanserat 5/tag.php on line 9

    Missing >:

    <div id="tag-title"><?php single_tag_title(); ?></div>
    		<div id="tag-description"><?php echo tag_description(); ?></div>
    		<?php if ( is_tag() && tag_description() ) : ?>
    	<div class="tag=description"><?php echo esc_html( strip_tags( tag_description() ), 1 ); ?>" /></div>
    <?php endif; ?>
    Thread Starter lillprinsen

    (@lillprinsen)

    new error

    Parse error: syntax error, unexpected T_ELSE in /home/web80729/domains/onyanserat.se/public_html/wp-content/themes/Onyanserat 5/tag.php on line 28

    I should give you the whole code. Sorry.

    Thread Starter lillprinsen

    (@lillprinsen)

    <div id="tag-title"><?php single_tag_title(); ?></div>
    <?php if ( is_tag() && tag_description() ) :?> <div  id="tag-description"><?php echo esc_html( strip_tags( tag_description() ), 1 ); ?></div><?php endif;?>

    Tested & working on my install.

    Thread Starter lillprinsen

    (@lillprinsen)

    Get this now:
    Parse error: syntax error, unexpected T_ELSE in /home/web80729/domains/onyanserat.se/public_html/wp-content/themes/Onyanserat 5/tag.php on line 25

    There must be something else wrong in my tag.php then. Could you please help me with that? Got the whole code above in the pastebin link.

    thanx.

    Can you paste the new template code into the pastebin?

    Thread Starter lillprinsen

    (@lillprinsen)

    You’re missing the if(have_posts():

    http://wordpress.pastebin.com/8RsWh0DX

    Thread Starter lillprinsen

    (@lillprinsen)

    Thank you. Now it works except two things.

    1. The image I have in the description doesn’t show (I use html with a plugin)

    2. I dont want the title to show on the pages without description either.

    I´m very thankful that you are helping me with this.

    1. How is the plugin returning the image? I did wonder at the <?php echo esc_html( strip_tags( tag_description() ), 1 ); ?> line since you can just use <?php tag_description(); ?>.

    2. See http://wordpress.pastebin.com/FzT1uM2Y

    Thread Starter lillprinsen

    (@lillprinsen)

    Hmmm. I´m mot very good at this. I use theme test drive when im working with my new theme so you can´t look at it. But I can change for the theme i´m working on fo a moment if you have time now to check it out?

Viewing 15 replies - 1 through 15 (of 30 total)
  • The topic ‘Help with If/else code’ is closed to new replies.