Comment Meta
Hi Ammaletu,
erst einmal danke für die Antwort!! Inzwischen bin ich auch über Comment-Meta gestoßen, nur hab ich leider nicht viele Beispiele gefunden, von den man abschauen könnte (kann leider mehr oder weniger kein PHP und mache dann eher trial & error).
Den einzigen Bericht gibt's bei soabboxdave.com
ich hab jetzt erst einmal in meiner Comment.php ein zusätzliches Feld eingefügt:
<div><input type="text" size="25" name="headline" value="<?php echo $myid; ?>" />
<label for="headline"><?php _e('Headline', 'cp'); ?></label></div>
Die Value-Angabe ist natürlich unsinn, da recherchiere ich noch, was da reingehört.
Der Rest steht in der Theme-Functions.php. Soapboxdave folgend hab ich da jetzt erst einmal die add action eingebaut:
add_action ('comment_post', 'add_meta_settings', 1);
function add_meta_settings($post_id) {
add_comment_meta($post_id, 'headline', $_POST['headline'], true);
}
Bin mir nicht so sicher, ob das so richtig ist.
Dann kommt der ganze Comment-Absatz in der Theme-Function (ich poste jetzt einfach mal den ganzen code und hoffe, euer Speicherplatz macht da mit ;-):
// new comment function
function cp_comment_author_link()
{
$comment_author_link = get_comment_author_link();
if ( ereg(']* class=[^>]+>', $comment_author_link) )
{
$comment_author_link = ereg_replace('(]* class=[\'"]?)', '\\1url ' , $comment_author_link );
}
else
{
$comment_author_link = ereg_replace('(<a )/', '\\1class="url "' , $comment_author_link );
}
echo $comment_author_link;
}
function cp_comment_author_avatar()
{
$email = get_comment_author_email();
$avatar = str_replace("class='avatar", "class='photo avatar", get_avatar("$email", "42" ) );
echo $avatar;
}
function cp_comments( $comment, $args, $depth )
{
$GLOBALS['comment'] = $comment;
$headline_array = get_comment_meta(get_comment_ID(),"headline");
$headline = $headline_array[0]; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<a name="comment-<?php comment_ID() ?>"></a>
<div class="comment-meta">
<span class="name"><?php cp_comment_author_avatar(); ?></span>
<?php if ( (get_comment_type() == "comment") ) { cp_comment_author_link(); } ?>
<?php if ( (get_comment_type() == "pingback") or (get_comment_type() == "trackback") ) { ?><?php cp_comment_author_link(); ?><br /><?php } ?>
<?php if ( (get_comment_type() == "comment") or (get_comment_type() == "pingback") or (get_comment_type() == "trackback") ) { ?>
<span class="comment-date"> <?php _e('on', 'cp'); ?> <?php echo get_comment_date( __('F jS, Y', 'cp') ); ?> <?php _e('at', 'cp'); ?> <?php echo get_comment_time(); ?></span>
<span class="edit"><?php edit_comment_link( __('Edit', 'cp'), '', '' ); ?></span>
<span class="permalink"><a class="comment-permalink" href="<?php echo get_comment_link(); ?>" title="<?php _e('Direct link to this comment', 'cp'); ?>">#</a></span>
<?php } ?>
</div>
<div class="comment-entry" id="comment-<?php comment_ID(); ?>">
<div class="comment-headline">
<?php echo $headline; ?>
</div>
<?php comment_text() ?>
<?php if ( $comment->comment_approved == '0') { ?> <p class='comment-unapproved'><?php _e('Your comment is awaiting moderation.', 'cp'); ?></p> <?php } ?>
<div class="comment-reply">
<?php comment_reply_link( array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']) ) ) ?>
</div>
</div>
<div class="clear"></div>
<?php
}
Alles anzeigen
Was ich da geändert habe ist das copy&paste der variablen von soapbox:
$GLOBALS['comment'] = $comment;
$headline_array = get_comment_meta(get_comment_ID(),"headline");
$headline = $headline_array[0]; ?>
... und dann habe ich über den Comment-Text die headline reingeknallt:
<div class="comment-entry" id="comment-<?php comment_ID(); ?>">
<div class="comment-headline">
<?php echo $headline; ?>
</div>
<?php comment_text() ?>
Müsste man wohl noch als h ausgeben, etwa so?
<?php echo '<h4>'.$headline.'</h4>'; ?>
Ist wahrscheinlich noch ziemlicher Unsinn, aber so ganz grob müsste es doch gehen.
Zum Hintergrund, weshalb ich Headlines im Comment haben möchte (gibt's bei twoday übrigens standardmäßig): Ich versuche, mit dem Wordpress-Plugin WP-Answers eine Art getsatisfaction mit Wordpress zu machen, also Feedbacks über Kommentare einzuholen. Headlines in Kommentaren geben dem Leser einen schnelleren Überblick und motivieren möglicherweise, einzelne Kommentare zu raten ...