Hallo WP-Freunde,
ich schreibe an meinem eigenen Theme und bin gerade dabei die Kommentarfunktion einzubauen.
Ich möchte verschachtelte Kommentare auf meiner Seite einbinden. Soweit funktioniert auch alles, nur habe ich ein Problem: Die Antwort-Kommentare (also die Kind-Elemente) werden nicht unterhalb des beantworteten Kommentars (Eltern-Element) angezeigt, sondern am Ende der Kommentarliste. Ich hätte aber natürlich gerne, dass die Kind-Elemente unter den Eltern-Elementen angeordnet werden.
Ich habe einiges ausprobiert, finde aber keine Lösung. Vielleicht habt ihr einen Ansatz für mich.
Ich poste euch mal meine comments.php und die functions.php, damit ihr sehen könnt, was ich bisher erreicht habe.
COMMENTS.PHP
<div id="respond">
<h4 id="kommentar-titel">Und jetzt du! Schreib uns deine Geschichte.</h4>
<p id="kommentar-untertitel">
<small>Um uns vor Spam zu schützen, bitten wir dich die markierten Felder auszufüllen. Deine E-Mail-Adresse wird nicht veröffentlicht.</small>
</p>
<div id="cancel-comment-reply"> <!-- Kommentarformular wieder schließen (beim Antworten auf Kommentare)-->
<small><?php cancel_comment_reply_link(); ?></small>
</div>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<p class="eingabe-name">
<label for="author">Name* </label>
<input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="50" />
</p>
<p class="eingabe-mail">
<label for="email">E-Mail* </label>
<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="50" tabindex="2" />
</p>
<p class="eingabe-url">
<label for="url">Webseite </label>
<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="50" tabindex="3" />
</p>
<div>
<?php comment_id_fields(); ?> <!-- von JS benötigt im verschachtelte Kommentare auszugeben -->
<input type="hidden" name="redirect_to" value="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]); ?>" />
</div>
<p class="eingabe-kommentar">
<label>Kommentare, Anmerkungen und Anekdoten</label>
<textarea name="comment" id="comment" style="width: 76%;" rows="10" tabindex="4"></textarea>
</p>
<div class="clear"></div>
<p>
<input name="submit" type="submit" id="submit" tabindex="5" value="SENDEN" />
<?php comment_id_fields(); ?>
</p>
<?php do_action('comment_form', $post->ID); ?>
<div class="clear"></div>
</form>
</div>
<!-- KOMMENTARFORMULAR -->
<!-- ES FOLGT DER KOMMENTAR-LOOP (NOTWENDIG UM KOMMENTARE ANZUZEIGEN) -->
<div id="kommentare">
<div class="kommentar-text">
<?php wp_list_comments('type=comment&callback=kb_comment_template'); /* Dieses Template wird später in der functions.php definiert */ ?>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<strong>Achtung: Dein Kommentar muss moderiert werden.</strong><br />
<?php endif; /* end for each comment */ ?>
<div class="clear"></div>
</div><!-- kommentare -->
Alles anzeigen
FUNCTIONS.PHP
/* template for comments */
function kb_comment_template($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar('info@nuestra-america.de', $comment->comment_author_email, 30 ); ?>
<div id="name">
<?php printf(__('<cite class="fn">%s</cite>'), get_comment_author_link()) ?>
</div>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<?php _e('Dein Kommentar muss erst moderiert werden.') ?>
<br />
<?php endif; ?>
<div class="kommentar-meta">
<div class="ausgabedatum">
<?php printf(__('%1$s'), get_comment_date()) ?>
</div>
<div class="kommentar-edit">
<?php edit_comment_link(__('(Kommentar bearbeiten)'),' ','') ?>
</div>
</div>
<div class="clear"></div>
<div class="kommentar-beitrag">
<?php comment_text() ?>
</div>
<div class="clear"></div>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
<hr/>
<div class="clear"></div>
</div>
<?php
}
Alles anzeigen
Vorab schon einmal besten Dank für die Hilfe