Forums

[resolved] Want to change my single.php for sticky posts (5 posts)

  1. rekkette
    Member
    Posted 1 year ago #

    Hello, I want to change my single.php file (I've got a twentyten child theme) to react differently for sticky posts.

    I found this code to block events on the posts page, but it doesn't work in the single.php file.

    <?php if( !is_sticky() || !is_home() ) :?>
    <div id="nav-above" class="navigation">
    ...
    </div><!-- #nav-above -->
    <?php endif;?>

    If I understand correctly, <?php if( !is_sticky() || !is_home() ) :?> is a negative statement.

    I need to not only block out the 'navigation div', but posit something in its place. So, I need to learn how to negate something if it's sticky, and replace it with something else.

    I'll take any suggestions including sites on .PHP that aren't too wordy.
    Cheers!

  2. zoonini
    help me help you
    Posted 1 year ago #

    <?php if (is_sticky()): ?>
    do the sticky thing
    <?php else: ?>
    do the non-sticky thing
    <?php endif; ?>

    Would this work?

    And yes, adding an exclamation mark before the conditional checks that it is NOT that thing. So if (!is_sticky()) means "if NOT sticky."

  3. rekkette
    Member
    Posted 1 year ago #

    That is HOT! Thank you SOOO much. It worked beautifully. Seriously, though, I really have to learn some .PHP syntax. Do you know of a good site/tutorial you can recommend?

  4. zoonini
    help me help you
    Posted 1 year ago #

    Excellent, glad it worked!

    I don't know any good PHP tutorials off-hand but if you Google I'm sure there are some out there. There is the official PHP Manual but it's not the most beginner-friendly thing. On the WordPress side, the Conditional Tags page is invaluable, and it comes with examples which may be enough to get you started.

    If you would please mark this thread as "resolved" (drop-down menu in the right column) it would be appreciated. Helps everyone keep better track of whose issues are still outstanding. Thanks!

  5. rekkette
    Member
    Posted 1 year ago #

    Already done! Have googled it before, can get pretty intimidating. But I'll check out the link on conditional tags. The WordPress tutorials I find are really simple to follow and the explanations are good. Thank you again!

Topic Closed

This topic has been closed to new replies.

About this Topic