• Resolved nthnlsmmrs

    (@nthnlsmmrs)


    Simple question. I’ve got a blog up that allows comments on some pages. In order to get them to show I have to add <?php comments_template(); ?> in the loop. That works just fine but I don’t want to show anything at all when comments are disabled for that page. How would I go about doing that? I’m sure it’s a simple coding change.. and extra if statement somewhere… I just have no earthly idea where to look.

    Any help would be greatly appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • wpitn2shape

    (@wpitn2shape)

    I think you’ll find your answer in a line of code that should come in your template, like this here: (alone this would break things, totally “quote” and broken piece of code)

    <?php else : // comments are closed ?>
    		<!-- If comments are closed. -->
    		<p class="nocomments">Comments are closed.</p>

    You could try this:

    <?php else : // comments are closed ?>
    		<!-- If comments are closed. -->

    And then it moves on to the next part, which closes that original if. Now you might need to do more, let me see…

    <?php if ('open' == $post-> comment_status) : ?>
    		<!-- If comments are open, but there are no comments. -->

    And move that to ABOVE where comments would DISPLAY. Helpful if you want your old comments (if they were once allowed) to not show (without deleting them).

    Hope that answers everything! I’ll probably be around for a little more tonight, I’ll check back on ya.

    wpitn2shape

    (@wpitn2shape)

    I might be a little confused about this, and you MAY need two separate instances of either the whole comments code OR the page template – one for open comment pages and one for closed.

    Anyone else know?

    Thread Starter nthnlsmmrs

    (@nthnlsmmrs)

    I think the problem is that my comments template for this theme lays down all the design features (neat little boxes with curved edges and all that jazz) then executes the code as to whether or not comments are shown and puts it inside the neat little box.

    I want to show nothing. Which tells me that I need to add an If statement into my page template so that the comments template isn’t even called if comments are not allowed.

    So… let’s re-frame the question: How would I be able to tell (in PHP) whether comments are allowed or not, on a page. That way I can simply put an If statement in that reads mostly like this:

    if comments are allowed {
    Load comments template
    } else {
    do nothing
    }

    The fun part is that I have no idea how to tell if comments are allowed or not.

    moshu

    (@moshu)

    You guys are overcomplicating it… especially WPITn2shape!
    No need for all that craziness.

    Have two (or a zillion) Page Templates: one with comments, the other without the call for the comments template or showing the comments link. That’s it.
    When writing Pages you can always select which template to use.

    Thread Starter nthnlsmmrs

    (@nthnlsmmrs)

    er… I don’t see the template dropdown anywhere. I see: Discussion
    Page Status
    Page Password
    Page Parent
    Page Slug
    Page Author
    Page Order
    Upload
    And Custom Field

    No evidence of the page template. Sounds awesome, but I’ve never seen it. Any reason that might not be showing?

    moshu

    (@moshu)

    Any reason that might not be showing?
    Yes. You need the default (page.php) template AND another one for the dropdown to show up.

    Thread Starter nthnlsmmrs

    (@nthnlsmmrs)

    Cool, that fixed it. I didn’t realize I had to add that funny piece of code:

    <?php
    /*
    Template Name: Template_Name
    */
    ?>

    After that, it was easy as pie. Thanks guys. That was super simple.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Page comments’ is closed to new replies.