Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Michael Wilhelmsen
Michael Wilhelmsen
2,490 Points

Comments in Wordpress strips content on updates

I have a problem with comments in the Wordpress theme I'm building. As of now, I can comment just fine, but whenever I do (press "reply", "edit comment", press the date, really anything that involves updating a comment), my header and site content dissapears and I'm stuck with the comments at the top of the site/content-wrapper and everything below it (sidebar, footer).

Here's my comments.php template (I'm not sure what else can be causing this, but I appreciate any help:

<?php
  /**
   *
   *  Comments themplate - Adapted Version of Kubrick's
   *
   *  There are 2 distinct sections after the protection area ::
   *  Display Comments is a loop surrounding the wp_list_comments() function
   *  The Form/Login section uses comment_form() to do everything
   *  ( Finally the RSS link is at the end of the page )
   *
   *  */

  // ##########  Do not delete these lines
  if (isset($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])){
      die ('Ikke last denne siden direkte. Takk!'); }
  if ( post_password_required() ) { ?>
      <p class="nocomments"><?php _e('Denne posten er passordbeskyttet. Skriv inn passordet for å vise kommentarene.', 'kubrick'); ?></p>
  <?php
      return; }
  // ##########  End do not delete section

  // Display Comments Section
  if ( have_comments() ) : ?>
      <h3 id="comments"><?php comments_number('Ingen kommentarer', 'Én kommentar', '% kommentarer');?> <?php printf('til “%s”', the_title('', '', false)); ?></h3>
          <div class="navigation">
              <div class="alignleft"><?php previous_comments_link() ?></div>
              <div class="alignright"><?php next_comments_link() ?></div>
          </div>
      <ol class="commentlist">
       <?php
       wp_list_comments(array(
        // see http://codex.wordpress.org/Function_Reference/wp_list_comments
        // 'login_text'        => 'Login to reply',
        // 'callback'          => null,
        // 'end-callback'      => null,
        // 'type'              => 'all',
        // 'avatar_size'       => 32,
        // 'reverse_top_level' => null,
        // 'reverse_children'  =>
        ));
        ?>
      </ol>
          <div class="navigation">
              <div class="alignleft"><?php previous_comments_link() ?></div>
              <div class="alignright"><?php next_comments_link() ?></div>
          </div>
      <?php
      if ( ! comments_open() ) : // There are comments but comments are now closed
          echo"<p class='nocomments'>Kommentarer er stengt.</p>";
      endif;

  else : // I.E. There are no Comments
      if ( comments_open() ) : // Comments are open, but there are none yet
          // echo"<p>Be the first to write a comment.</p>";
      else : // comments are closed
          echo"<p class='nocomments'>Kommentarer er stengt.</p>";
      endif;
  endif;

  // Display Form/Login info Section
  // the comment_form() function handles this and can be used without any paramaters simply as "comment_form()"
  comment_form(array(
    // see codex http://codex.wordpress.org/Function_Reference/comment_form for default values
    // tutorial here http://blogaliving.com/wordpress-adding-comment_form-theme/
    'comment_field' => '<p><textarea name="comment" id="comment" cols="58" rows="10" tabindex="4" aria-required="true"></textarea></p>',
    'label_submit' => 'Kommentér',
    'comment_notes_after' => ''
    ));

  ?>

3 Answers

Hi,

If you take the source code before you comment and the source code of the page after you comment. Can you post the differences?

I suspect that you've got a tag not closed or closed too soon that's causing the layout of your page to render unexpectedly.

You could run your page through validator.w3.org before and after and see if it spots any tag mismatches as a first test.

Michael Wilhelmsen
Michael Wilhelmsen
2,490 Points

These are the errors i get, the source code shows everything both before and after I comment (which is weird, considering only the comments and what's below it is visible in the faulty page).

Line 16, Column 19: Stray start tag html. <html lang="en-US">

Line 144, Column 28: Element p not allowed as child of element small in this context. (Suppressing further errors from this subtree.) <small class="edit-link"><p><a class="post-edit-link" href="http://localhost:88…

Line 184, Column 158: Bad value category tag for attribute rel on element a: The string category is not a registered keyword or absolute URL. …itle="View all posts in Uncategorized" rel="category tag">Uncategorized</a></p>

Michael Wilhelmsen
Michael Wilhelmsen
2,490 Points

I've been through this countless times now and I can't find anything wrong with either the comments or single template.. :/ Does anyone know how to fix this? Does anyone have a suggestion or thought to get me in the right direction?