Trouble with if statment in index (3 posts)

  1. thebloke
    Posted 10 years ago #


    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!

  2. Kafkaesqui

    Posted 10 years ago #

    <?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.

  3. thebloke
    Posted 10 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.