• Hi all

    I try to develop a new theme from scratch – to make sure I understand every single bit of WordPress. ??

    I proceeded quite well so far; the only thing I have REALLY troubles with is the comment system: for some reason, the line containing the “Edit” and “x comments” underneath each article does not appear….

    I only have an index.php, header.php, sidebar.php footer.php, and functions.php in my theme (beside the css and the searchbar.php include); I created a comments.php, but this did not work. Here’s part of header.php:

    ...
    
        <?php //comments_popup_script(); // off by default ?>
        <?php wp_head(); ?>
      </head>
    
      <body>
        <div id="header">
          <h1><?php bloginfo('title') ?></h1>
          <ul>
            <?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); /* list pages by menu-order but only first hierarchy */ ?>
            <li><?php include (TEMPLATEPATH . '/searchform.php'); ?></li>

    Here’s my index.php:

    <?php get_header(); ?>
    
    <?php get_sidebar(); ?>  
    
      <div id="content">
        <?php if (have_posts()) : ?>
    
          <?php while (have_posts()) : the_post(); ?>
    
            <div>
              <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
              <small>In <?php the_category(","); ?> on <?php the_date(); ?> </small>
              <?php the_content("More"); ?>
              <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
            </div> <!-- end of post-container -->
    
          <?php endwhile; ?>
    
        <?php else : /*no posts? */ ?>
    
          <h2>Not Found</h2>
          <p>Sorry, but you are looking for something that isn't here.</p>
          <!-- <?php include (TEMPLATEPATH . "/searchform.php"); ?> -->
    
        <?php endif; /* if post available */ ?>
      </div> <!-- end of "content" container -->
    
    <?php get_footer(); ?>

    When I look at the page containing an individual post, I see the header, the sidebar, the post itself – and directly underneath the footer; there is NO comment line…
    When I switch to another theme, everything works as designed…

    Sorry if this is a long post – but I really, really don’t know what I am doing wrong……. ??

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter tkhobbes

    (@tkhobbes)

    OK, found out something else. After adding the line

    <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>

    the “comment” link suddenly appeared. But – clicking on it (on the link pointing to #respond, basically), lead me back to where I began – to a nice website containing the post, but without possibility to add a comment…

    I think you’ll need a comments.php, with the bits in it that are produced when you call

    <?php comments_template(); ?>

    From your single entry page. (just before the end of the while have posts loop)

    Thread Starter tkhobbes

    (@tkhobbes)

    I DO have a comments.php – it’s quite sophisticated (and frankly copied from the Sandbox theme with some little adjustments). But I don’t have a single.php file (as if not available, WordPress should just use index.php)

    Here is comments.php:

    <?php if ($comments) { ?>
    
      <ol id="commentlist">
        <?php foreach ($comments as $comment) { ?>
    
          <li id="comment-<?php comment_ID() ?>"><?php comment_text() ?>
            <cite><?php comment_type(__('Comment'), __('Trackback'), __('Pingback')); ?> by
            <?php comment_author_link() ?> —
            <?php comment_date() ?> @
            <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite>
            <?php edit_comment_link(__("Edit This"), ' |'); ?>
    
          </li>
    
        <?php } ?>
      </ol>
    
    <?php } else { // If no comment is available ?>
    
      No comments.
    
    <?php } ?>
    
    <?php if (comments_open()) { ?>
    
      <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
        <?php if ($user_ID) { ?>
          Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>.
          <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Logout &raquo;</a>
    
        <?php } else { ?>
          <input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
          <label for="author"><small>Name <?php if ($req) _e('(required)'); ?></small></label>
    
          <input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
          <label for="email"><small>Mail (will not be published) <?php if ($req) _e('(required)'); ?></small></label>
    
          <input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
          <label for="url"><small>Website</small></label>
    
        <?php } ?>
    
        <textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea>
    
        <input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
        <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
    
        <?php do_action('comment_form', $post->ID); ?>
      </form>
    
    <?php } ?>

    You will only see the “Edit” link if you are logged in as the Admin. It disappears automatically when you’re logged out, or logged in with a login that doesn’t have high enough permissions to Edit posts.

    Not sure if this is your issue, but I wanted to mention it

    Thread Starter tkhobbes

    (@tkhobbes)

    I don’t see neither the “comments” link nor the “edit” link – regardless as whom I am logged in. Besides, the issue is about the “comments” link, not about the “edit” link ??

    But I assume that they are connected – as I can’t see any of them and am supposed to see both of them…

    scale back to what MrM. said

    try just
    <?php comments_template(); ?>
    in your template, not the comments_popup_thingy

    Thread Starter tkhobbes

    (@tkhobbes)

    using the suggested comments_template() function (just underneath the the_content(“More”); function) gives a (very ugly) comment text-field underneath each post – but ONLY when I am in the “single-view” mode of the post (not in a category view); furthermore, in the category views, the text “x comments” is still missing, as is the “edit” link (even though I am logged in)…

    The “edit” you want is the “Edit Post” button for the admin to see, right?

    Here’s some code from my index.php
    I have similar code in my category.php

    This is inside The Loop (hopefully you have the idea of what that means, if not then read about The Loop in the Codex)

    <?php edit_post_link('EDIT ','','<strong>|</strong>'); ?> <?php comments_popup_link('Comments/Requests?', 'Comments? (1 so far)', 'Feedback! % Comments. Post yours', '', ''); ?>

    I am providing this so you can make sure that your comments_popup_link code, and your edit_post_link code, are typed properly. I think you have way too many parentheses in your comments_popup_link code, but it’s hard for me to be sure because I don’t speak PHP, I just copy-paste it and modify where I can hang with it. Maybe just try my code and see if that works better.

    Thread Starter tkhobbes

    (@tkhobbes)

    It does not change the basic situation – the comment link is displayed, but as soon as I click on it, I end up on a screen with JUST the post and NO comment form…
    Also, I think by default WordPress should show the comment link by itself – i. e. you don’t have to put the <?php comments_popup_link ?> command?

    tk, wordpress shows the comment link by itself if you just use the Default theme.

    If you make or use another theme, well, it’s up to you what is in the theme, what theme you choose, or how you tweak it. Almost every theme I have seen shows the comment link. Some people don’t want the comment link, or want it to act various ways, that is why there are choices.

    Just glancing at the Codex, trying to find a solution for you, I think you might need to look into this javascript part of it, for when you want the popup you might need to put something in your header:
    https://codex.www.ads-software.com/Template_Tags/comments_popup_script

    ok I just looked at your header code again and you probably simply need to remove the // and // from this line of the code in your header:

    <?php //comments_popup_script(); // off by default ?>

    change it to
    <?php comments_popup_script(); ?>

    In the end it will just come down to adding the comment text in to all the template types that you’d want them on. If you’re developing your own theme from scratch then nothing will show up “by default” unless you specifically put it there. That means if you want it on your category pages it’ll have to go into that template too.

    I guess the popup script is commented because it’s the old way of doing things. No doubt these days you should try for the single entry + comments approach, or use some fancy AJAX stuff to make the comments appear and disappear as you like.

    I agree with mrmist as far as the popup method being not so modern. But that is what tk wanted ??

    Thread Starter tkhobbes

    (@tkhobbes)

    Ah – funny, I read on some website (can’t remember, one that taught “building a theme from scratch) that within the loop, not only the post(s), but also the comment links will show up by default…

    However, I don’t want the popup stuff – what I want is a link that says “comments” and when you click on it (and end up on the #respond thingy), you get a nicely designed comment form (which comes from comments.php, already designed, see above).

    What happens though is when I insert the link manually (as said above), and click it, I end up in exactly the same page as before – but without comment link and without comment form….. ??
    And this is exactly the part I do not understand.

    No. Nor do I understand..:)

    Thread Starter tkhobbes

    (@tkhobbes)

    BTW – you can have a look at this at https://www.hobbes.ch/test … just click a category and then on an article…

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘I don’t understand the comment system’ is closed to new replies.