WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP Help Needed Please (6 posts)

  1. andymike
    Member
    Posted 8 years ago #

    Ok I think I need an "if" PHP statement. I am a real beginner with PHP. I want this chunk of code from my comments.php to parse only if there is at least one comment:

    <h3 class="commentstop"><?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments')); ?>
    <?php if ( comments_open() ) : ?>
    <a id="leavecomment" href="#postcomment" title="<?php _e("Leave a comment"); ?>">Leave A Comment</a>
    <?php endif; ?></h3>

    So the PHP I need in English:

    [ IF THERE ARE NO COMMENTS SKIP THIS CODE] [ IF THERE IS AT LEAST 1 COMMENT PARSE IT NORMALLY]

    It should be relatively simple I just don't know any PHP.

    Thanks for any help you can give :)

  2. Michael_
    Member
    Posted 8 years ago #

    Try this one:

    if ( $comments ) {
    echo 'There is at least one comment';
    } else {
    echo 'No comment here';
    }

  3. andymike
    Member
    Posted 8 years ago #

    Thanks!

    I actually found some similar PHP later in the comments code that worked perfectly. I just used:

    <?php if ( $comments ) : ?>

    CODE HERE

    <?php else : // If there are no comments yet ?>
    <?php endif; ?>

    Worked like a charm!

  4. resiny
    Member
    Posted 8 years ago #

    I suck at php. I can hack my way around, but I really need to learn to do custom variables for myself...I need stuff like this all the time

  5. Kafkaesqui

    Posted 8 years ago #

  6. resiny
    Member
    Posted 8 years ago #

    yeah, yeah, I know. I just need the motivation. There are tons of sites out there with great tutorials...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags