Results 1 to 2 of 2

Thread: How to display text only if there are comments?

  1. #1
    jonbey is offline Hello World
    Join Date
    Sep 2010
    Posts
    2

    Default How to display text only if there are comments?

    I am sure this is a simple thing, but my attempts result in a php error and no site!

    I want this code (which is in the loop.php) to only appear if comments are switched on:

    Code:
    <a href="#comment"><b>FREE ADVICE HERE</b></a> (<?php comments_number( 'Ask a question', 'one response', '% responses' ); ?>).
    So, it should not appear on my homepage (no comments on home page) or any other pages where I have disabled comments. You can see it on the top (ish) of the pages between the titles and content (or in the case of the homepage that has no title displayed, below the main horizontal menu).

    Any help would be much appreciated!

    Cheers

    Jon.

  2. #2
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Try wrapping your code in the following conditional, using comments_open() and have_comments():
    PHP Code:
    if ( comments_open() && have_comments ) {
        
    // Comments are open, and there are comments;
        // do something.

    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •