WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] php syntax help (5 posts)

  1. heidipj
    Member
    Posted 5 years ago #

    Hi there,

    I am trying to do an if else in php but it's not working... Can someone take a quick look and tell me what I am doing wrong? What I'm trying to do: if post ID is not equal to 27 (id of homepage) then show post title.

    <?php if ( the_ID()!=27 ) { ?>
    <h2><?php the_title(); ?></h2>
    <?php } ?>

    any help would be much appreciated.

  2. leadandfollow
    Member
    Posted 5 years ago #

    Probably you need to echo the title so that it actually prints:

    <?php echo the_title(); ?>

  3. heidipj
    Member
    Posted 5 years ago #

    yeh i tried that. Funnily enough with my code there it prints out the post id first and then the post title regardless of the if else statement.

  4. leadandfollow
    Member
    Posted 5 years ago #

    Actually, sorry, these are template tags and do not need to be echoed. Probably you should use functions that are not template tags if you do not want it to be printed.

    http://codex.wordpress.org/Function_Reference/get_post_meta

  5. heidipj
    Member
    Posted 5 years ago #

    Thanks leadandfollow - not exactly what I was looking for but I hunted around a bit more and found this page which was helpful http://codex.wordpress.org/Conditional_Tags#The_Front_Page

    The code which worked for me eventually was:

    <?php if( !is_front_page() ){  ?>
    <h2><?php the_title(); ?></h2>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic