• Resolved kerdezo

    (@kerdezo)


    Shame to ask but I’m a beginner.
    -I know how to copy a php file, say comment.php, from the original to a child theme through my Cpanel, but how can I do that in my wp theme by the editor.
    – Where shoul I insert the data bellow, /into My child theme comment.php/
    ‘<p class=”comment-notes”>’ . __( ‘Your email will not display.’ ) . ( $req ? $required_text : ” ) . ‘</p>’
    I want this text to display on contact form.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi kerdezo. Here is an article on how to create a new file using the default editor:
    https://www.webmechanix.com/how-to-create-a-new-theme-file-in-wordpress-without-ftp-access/

    The theme comments.php file is a wrapper for the default WP comment form. It adds things like comment and ping counts, and navigation as required. To add custom code to the actual comment form you’d need to modify the default WP comment file. There are several articles online that discuss ways to do this.

    Thread Starter kerdezo

    (@kerdezo)

    Hi bdbrown, firs issue with copy file is ok, but still challenging the second.
    I read codex/function reference/contact form and figured out that I should copy the the comment.php content to the child theme and then copy/paste the

    ‘<p class=”comment-notes”>’ . __( ‘Your email will not display.’ ) . ( $req ? $required_text : ” ) . ‘</p>’

    to it./This is the optional data in codex for inserting this text/ But to which part of the child theme comment.php should I add the additional info data? I enclose my comment.php in the child theme.

    Thread Starter kerdezo

    (@kerdezo)

    Here it is…

    <?php if ( post_password_required() ) { return; } ?>
    
    <section id="comments" class="themeform">
    
    	<?php if ( have_comments() ) : global $wp_query; ?>
    
    		<h3 class="heading"><?php comments_number( __( 'No Responses', 'hueman' ), __( '1 Response', 'hueman' ), __( '% Responses', 'hueman' ) ); ?></h3>
    
    		<ul class="comment-tabs group">
    			<li class="active"><a href="#commentlist-container"><i class="fa fa-comments-o"></i><?php _e( 'Comments', 'hueman' ); ?><span><?php echo count($wp_query->comments_by_type['comment']); ?></span></a></li>
    			<li><a href="#pinglist-container"><i class="fa fa-share"></i><?php _e( 'Pingbacks', 'hueman' ); ?><span><?php echo count($wp_query->comments_by_type['pings']); ?></span></a></li>
    		</ul>
    
    		<?php if ( ! empty( $comments_by_type['comment'] ) ) { ?>
    		<div id="commentlist-container" class="comment-tab">
    
    			<ol class="commentlist">
    				<?php wp_list_comments( 'avatar_size=96&type=comment' ); ?>
    			</ol><!--/.commentlist-->
    
    			<?php if ( get_comment_pages_count() > 1 && get_option('page_comments') ) : ?>
    			<nav class="comments-nav group">
    				<div class="nav-previous"><?php previous_comments_link(); ?></div>
    				<div class="nav-next"><?php next_comments_link(); ?></div>
    			</nav><!--/.comments-nav-->
    			<?php endif; ?>
    
    		</div>
    		<?php } ?>
    
    		<?php if ( ! empty( $comments_by_type['pings'] ) ) { ?>
    		<div id="pinglist-container" class="comment-tab">
    
    			<ol class="pinglist">
    				<?php // not calling wp_list_comments twice, as it breaks pagination
    				$pings = $comments_by_type['pings'];
    				foreach ($pings as $comment) { ?>
    					<li class="ping">
    						<div class="ping-link"><?php comment_author_link($comment); ?></div>
    						<div class="ping-meta"><?php comment_date( get_option( 'date_format' ), $comment ); ?></div>
    						<div class="ping-content"><?php comment_text($comment); ?></div>
    					</li>
    				<?php } ?>
    			</ol><!--/.pinglist-->
    
    		</div>
    		<?php } ?>
    
    	<?php else: // if there are no comments yet ?>
    
    		<?php if (comments_open()) : ?>
    			<!-- comments open, no comments -->
    		<?php else : ?>
    			<!-- comments closed, no comments -->
    		<?php endif; ?>
    
    	<?php endif; ?>
    
    	<?php if ( comments_open() ) { comment_form(); } ?>
    
    </section><!--/#comments-->

    OK, I see what you’re trying to do now. The WP comment form can accept several arguments, one of which is what you’re trying to add. The theme code to call to the WP comment form doesn’t supply any arguments so only the defaults are used. In comments.php, at the bottom of the code, you need to change this line:

    <?php if ( comments_open() ) { comment_form(); } ?>

    to this to define the arguments and then pass them to the comment form:

    <?php if ( comments_open() ) { 
    
        $comments_args = array(
            // add a note before the comment
            'comment_notes_before' => '<p class="comment-notes">' .
                __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) .
            '</p>',
        );
    
        comment_form($comments_args);
    
    } ?>

    Also, the comment-notes may be hidden by the theme css so you may need to add this to your child theme css to display it:

    #comments .comment-notes {
        display: block;
    }
    Thread Starter kerdezo

    (@kerdezo)

    Thank bdbrown!
    Great,works!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Just to learn’ is closed to new replies.