Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Dec 2011
    Location
    UK
    Posts
    6
    Member #
    30316
    So i recently dived into the wonderful world of WordPress design. And me being me always want to know how to code a theme from scratch etc... and i get to 'comments.php' and im stuck to the high heavens.

    I have got this code (from watching tutorials) and i type it word for word and i just seem to get an error where the article and comment box just repeats like a million times all down the page!
    PHP Code:
    <?php
    if(!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])){
        die(
    'Please do not load this page directly!');
    }
    if(
    post_password_required()){
    ?>
        <p>This post is password protected.</p>
    <?php return; } ?>

    <?php
    //Display the comment loop
    if(have_posts()) :
    ?>
        <h2><?php comments_number('Be the first to comment!''One Comment''% Comments'); ?></h2>
        <ol id='comments_section'>
            <?php wp_list_comments(array('avatar_size'=>80'reply_text'=>'Reply to this comment.')); ?>
        </ol>
        <div><?php paginate_comments_links(); ?></div>
        <?php
        
    else ://If no comments so far
        
    ?>

        <?php if('open' == $post->comment_status) : ?>
        <p>Have your say!</p>
        <?php else :?>
        <p>Comments currently closed!</p>
            <?php endif;?>
        <?php endif; ?>
    <?php 
    if('open' == $post->comment_status) : ?>

    <div id='respond'>
        <h2><?php comment_form_title(); ?></h2>

        <div id='cancel-comment-reply'>
            <small><?php cancel_comment_reply_link(); ?></small>
        </div>

        <?php if(get_option('comment_registration') && !$user_ID): ?>
            <p>You must be logged in to comment</p>
        <?php else : ?>
        <form action="<?php echo get_option('site_url'); ?>/wp-comments-post.php" method="post" id="commentform">

        <?php if($user_ID) :?>
        <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity?></a></p>

        <?php else : ?>
            <p><input type='text' name='author' id='author' value="<?php echo $comment_author;?>" />
            <label for='author'>Name</label></p>
            <p><input type='text' name='email' id='email' value="<?php echo $comment_author_email;?>" />
            <label for='email'>Mail <?php if($req) echo '(Required field)';?></label>
            </p>
            <p>
            <input type='text' name='url' id='url' value="<?php echo $comment_author_url?>" />
            <label for='url'>Website</label>
            </p>
        <?php endif; ?>
        <div><?php comment_id_fields(); ?>
        <input type="hidden" name="redirect_to" value="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'])?>" />
        </div>

        <p><textarea id='comment' name='comment' cols='50' rows='10'></textarea></p>

        <?php if(get_option('comment_moderation') == '1'){ ?>
            <p>Comment moderation is enabled, no need to resubmit any comments posted.</p>
        <?php ?>

        <p><input type='text' name='submit' id='submit' value='Submit' /></p>
        <?php do_action('comment_form'$post->ID); ?>
        </form>
        <?php endif; ?>
    </div>
    <?php endif; ?>
    Now i dunno if its just my system or for everyone else... but its doing my head in that it wont display anything other than the article and and comment box.

    Thanks for any reply given. I appreciate it all as it will help me learn understand it more

    -Jordie

  2.  

  3. #2
    Member Eric Mintz's Avatar
    Join Date
    Mar 2012
    Location
    Atlanta, GA
    Posts
    48
    Member #
    31243
    Liked
    7 times
    Your comments.php looks OK. This is just a guess since it's hard to tell from just this one file, but here are two things to check:

    1) Do you really have tons of comments that might have accumulated unexpectedly while testing some other code? Check directly in the database to eliminate this possibility

    2) Are you including comments.php inside of a loop in some outer file like your index.php file? The line in comments.php:

    <?php wp_list_comments(array('avatar_size'=>80, 'reply_text'=>'Reply to this comment.')); ?>

    Will already spit out all of your comments so you don't need any kind of loop of your own.

  4. #3
    Member jwind's Avatar
    Join Date
    Nov 2010
    Location
    On a mac
    Posts
    76
    Member #
    24894
    Liked
    4 times
    Quote Originally Posted by Eric Mintz, post: 232745

    2) Are you including comments.php inside of a loop in some outer file like your index.php file? The line in comments.php:
    That's almost certainly what is happening. Is it happening on both pages and posts? Post the code from whichever it's happening.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:28 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com