Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #190766

    Steve Woody
    Participant

    Hey,

    I want to have comments on a specific page.

    I’m using a blank template so it does not output the comments. Is there a way to add them as an element to a page ?

    #191366

    Rad
    Moderator

    Hi Steve,

    Thanks for writing in.

    What stacks you’re working on? Follow this instruction for integrity.

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    Add this code at your child theme’s functions.php

    add_shortcode('x_comment_embed', 'x_comment_embed');
    
    function x_comment_embed ( $atts ) {
    
    ob_start();
    
    if ( post_password_required() )
      return; // 1
    
    ?>
    
    <div id="comments" class="x-comments-area">
    
      <?php if ( have_comments() ) : ?>
    
        <h2 class="h-comments-title"><span><?php _e( 'Comments' , '__x__' ); ?> <small><?php echo number_format_i18n( get_comments_number() ); ?></small></span></h2>
        <ol class="x-comments-list">
          <?php
          wp_list_comments( array(
            'callback' => 'x_integrity_comment',
            'style'    => 'ol'
          ) );
          ?>
        </ol>
    
        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
        <nav id="comment-nav-below" class="navigation" role="navigation">
          <h1 class="visually-hidden"><?php _e( 'Comment navigation', '__x__' ); ?></h1>
          <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', '__x__' ) ); ?></div>
          <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', '__x__' ) ); ?></div>
        </nav>
        <?php endif; ?>
    
        <?php if ( ! comments_open() && get_comments_number() ) : ?>
        <p class="nocomments"><?php _e( 'Comments are closed.' , '__x__' ); ?></p>
        <?php endif; ?>
    
      <?php endif; ?>
    
      <?php
      comment_form( array(
        'comment_notes_after' => '',
        'id_submit'           => 'entry-comment-submit',
        'label_submit'        => __( 'Submit' , '__x__' )
      ) );
      ?>
    
    </div>
    
    <?php return ob_get_clean(); } 

    Then just add [x_comment_embed] inside your page content that has blank template.

    Hope this helps.

    #192101

    Steve Woody
    Participant

    Perfect as always 🙂

    Thank you

    #192488

    Paul R
    Moderator

    You’re welcome! 🙂

    #240625

    jmgb689
    Participant

    Hello Themeco Staff
    I have the same problem with icon stack, and adding this code at my child theme I can see the comments form but not the list of comments.
    Can you help me, please?

    #240660

    Paul R
    Moderator

    Hi,

    Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

    #267626

    jwhcowan
    Participant

    I’m using Integrity. I set up a child theme and added the code to functions.php, and then [x_comment_embed] to the page. I see the submit form, but not existing comments.

    Please help

    Thanks.

    #267641

    jwhcowan
    Participant
    This reply has been marked as private.
    #267827

    Paul R
    Moderator

    Hi,

    Thank you for providing your url.

    We can try another approach for this.

    Please copy the file template-blank-6.php from wp-content/themes/x/framework/views/integrity
    into your child theme wp-content/themes/x-child/framework/views/integrity

    Then edit the file that is in your child theme and add the code <?php x_get_view( 'global', '_comments-template' ); ?>
    after the line <?php endwhile; ?>

    Code in your template-blank-6.php file will look like this.

    
    <?php
    
    // =============================================================================
    // VIEWS/INTEGRITY/TEMPLATE-BLANK-6.PHP (No Container | No Header, No Footer)
    // -----------------------------------------------------------------------------
    // A blank page for creating unique layouts.
    // =============================================================================
    
    ?>
    
    <?php x_get_view( 'global', '_header' ); ?>
    
      <?php x_get_view( 'global', '_slider-above' ); ?>
      <?php x_get_view( 'global', '_slider-below' ); ?>
    
      <div class="x-main full" role="main">
    
        <?php while ( have_posts() ) : the_post(); ?>
    
          <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <?php x_get_view( 'global', '_content', 'the-content' ); ?>
          </article>
    
        <?php endwhile; ?>
        <?php x_get_view( 'global', '_comments-template' ); ?>
      </div>
    
      <?php x_get_view( 'global', '_footer', 'scroll-top' ); ?>
    
    <?php x_get_view( 'global', '_footer' ); ?>
    

    Please do the same for the other blank templates(template-blank-1.php,template-blank-2.php,template-blank-3.php…..) you want to use.

    Hope that helps.

    #268303

    jwhcowan
    Participant
    This reply has been marked as private.
    #268548

    Rad
    Moderator

    Hi there,

    Could you try adding this at your child theme’s functions.php

    add_post_type_support( 'page', ''comments' );

    Then edit your specific page and go to Screen Options on top and see if Discussion is available. If available, then enable it and scroll down to find Discussion section and turn or off comments.

    Hope this helps.

    #268576

    jwhcowan
    Participant

    Yes, that worked – thank you. You had an extra single quote before ‘comments’ that I needed to remove.

    I can now toggle the comments on and off.

    The comments are STILL outside of the content band / container that I would like them in. They stretch across the entire screen and look weird. Any ideas for correcting that?

    #268711

    Rue Nel
    Moderator

    Hello There,

    Sorry for the typo error.

    Please try to check the code below, the x-main full div doesn’t have a closing. We just made some revision:

    <?php
    
    // =============================================================================
    // VIEWS/INTEGRITY/TEMPLATE-BLANK-6.PHP (No Container | No Header, No Footer)
    // -----------------------------------------------------------------------------
    // A blank page for creating unique layouts.
    // =============================================================================
    
    ?>
    
    <?php x_get_view( 'global', '_header' ); ?>
    
      <?php x_get_view( 'global', '_slider-above' ); ?>
      <?php x_get_view( 'global', '_slider-below' ); ?>
    
      <div class="x-main full" role="main">
    
        <?php while ( have_posts() ) : the_post(); ?>
    
          <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <?php x_get_view( 'global', '_content', 'the-content' ); ?>
          </article>
    
        <?php endwhile; ?>
    
        <div class="x-container max width">
        <?php x_get_view( 'global', '_comments-template' ); ?>
        </div>
    
      </div>
    
      <?php x_get_view( 'global', '_footer', 'scroll-top' ); ?>
    
    <?php x_get_view( 'global', '_footer' ); ?>

    Please let us know how it goes.

    #269115

    jwhcowan
    Participant

    Wooooohooooo! THANK YOU. That worked perfectly.

    #269234

    Zeshan
    Member

    You’re welcome! 🙂