Zunächst einmal muss die Kommentarfunktion in der functions.php registriert werden.
<!-- Kommentare -->
<?php
function ms_comments( $comment, $args, $depth ) {$GLOBALS['comment'] = $comment; ?><!-- Name der Funktion kann frei gewählt werden-->
<li class="single-comment"><!-- Listenelement wird von WordPress geschlossen -->
<?php echo get_avatar($comment, $size='90');?><!-- Holt Avatar -->
<p><?php echo get_comment_author_link();?></p><!-- Lädt Author -->
<p><?php echo get_comment_date("d.m.Y");?>, <?php echo get_comment_time();?> Uhr</p><!-- Gibt Datum und Zeit des Kommentars aus -->
<p><?php comment_text();?></p><!-- Der Kommentar ansich -->
<!--Antwort Button-->
<div class="reply">
<?php comment_reply_link(array_merge( $args, array(
'depth' => $depth,
'max_depth' => $args['max_depth']
))) ?>
</div>
<?php }
Anschließend wird in der comments.php der Aufbau des Formulars und die Ausgabe der Kommentare erzeugt.
<div class="comment-form"><!-- Start Formular -->
<?php $fields = array(
'author' => '<p><label for="author">' . __('Name <em>(Pflichtangabe)</em>') . '</label><br /><input id="author" name="author" type="text" value="' . esc_attr($commenter['comment_author']) . '"size="30" aria-required="true"/></p>',
'email' => '<p><label for="email">' . __('E-Mail <em>(Pflichtangabe, wird nicht veröffentlicht)</em>') . '</label><br /><input id="email" name="email" type="text" value="' . esc_attr($commenter['comment_author_email']) . '"size="30" aria-required="true"/></p>',
'url' => '<p><label for="url">' . __('Homepage') . '</label><br /><input id="url" name="url" type="text" value="' . esc_attr($commenter['comment_author_url']) . '"size="30"/></p>',
);
comment_form( array(
'fields' => apply_filters('comment_form_default_fields', $fields ),
'comment_notes_before' => '<p>Dein Kommentar</p>',
'comment_notes_after' => '<p>Dein Kommentar muss nach der Erstellung freigeschaltet werden.</p>',
'title_reply' => __('<h3>Beitrag kommentieren</h3>')
));
?>
</div><!-- Ende Formular -->
<div class="comment-list">
<?php if (have_comments()) : ?><!-- Prüft ob Kommentare vorhanden sind -->
<?php if (get_comment_pages_count() > 1 && get_option('page_comments')) : ?><!-- Prüft ob im Backend "Breche Kommentare in Seiten um" aktiviert ist -->
<!-- Navigation für Kommentare falls aktiviert -->
<div class="navigation">
<div class="nav-previous"><?php previous_comments_link('Vorherige Kommentare');?></div>
<div class="nav-next"><?php next_comments_link('Nächste Kommentare');?></div>
</div>
<?php endif; ?>
<!-- Liste der Kommentare -->
<ul>
<?php wp_list_comments('type=all&callback=ms_comments');?><!-- Lädt Darstellung einzelner Kommentare aus der functions.php - Name muss dort registriert sein -->
</ul>
<!-- Prüft ob Kommentare geschlossen sind-->
<?php if ( ! comments_open()) : ?>
<p>Dieser Beitrag erlaubt keine Kommentare.</p>
<?php endif; ?>
<?php endif; ?>
</div>
Zu guter letzt müssen die Kommentare noch via Template tag "comments_template" in den entsprechenden Template Dateien integriert werden. Standard dafür wäre die single.php üblicherweise unterhalb des content.
<?php comments_template(); ?>
Antwort Funktion für Kommentare
Damit auf die Kommentare auch geantwortet werden kann, muss das ganze noch etwas ergänzt werden.
Dazu benötigen wir folgendes Script, welches Teil von WordPress ist.
<?php wp_enqueue_script('comment-reply');?>
Den Antwort Button haben wir bereits oben in der functions.php eingefügt.