Support » Fixing WordPress » Trouble with if statment in index

  • thebloke



    I am trying to put the following code:

    <center> <?php previous_post(‘« « %’, ”, ‘yes’); ?>
    | “>Main Page
    | <?php next_post(‘% » » ‘, ”, ‘yes’); ?>

    in my index.php.

    But I want it only on individual post pages rather than on the main page. I have tried putting in an if… else statement, but I keep on getting error messages whenever I do so.

    Can someone please give me a clue on:

    (1) the syntax of the if…else statement,
    (2) what condition to check for in order for have the code be activated only for individual post pages?

    Thanks for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Kafkaesqui


    <?php if(is_single()) : ?>
    <center> <?php previous_post('&laquo; &laquo; %', '', 'yes'); ?>
    | <a href="<?php bloginfo('siteurl'); ?>">Main Page</a>
    | <?php next_post('% &raquo; &raquo;', '', 'yes'); ?>
    <?php endif; ?>

    Note that if you set up a single.php in your theme, you would not need a conditional statement.



    Thanks Kafkaesqui! That did it! I failed to put in the <?php endif; ?> and when I did I did not put in the “;” when I tried. Also I was doing it wrong by checking for if (is_home) and putting the code in the else section. That doesn’t quite work of course.

    I did see other themes have a single.php, but did not know that just by having a single.php it will take care of itself (I thought I needed to call the file or something).

    Now that you have enlightened me, I will go ahead and try to add a single.php to my theme.

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trouble with if statment in index’ is closed to new replies.