Komputeromaniak.net - Forum Komputerowo-Webmasterskie: [Rozwiązany]Zmiana kolejności komentarzy - Komputeromaniak.net - Forum Komputerowo-Webmasterskie

Skocz do zawartości




Strona 1 z 1
  • Nie możesz napisać tematu
  • Temat jest zamknięty

[Rozwiązany]Zmiana kolejności komentarzy

#1
Usunięty/Gość_96th_*


  • Tytuł
  • Grupa Gość
Przeczytałem kodeks WP... Przejrzałem kod komentarzy i nadal nic nie mogę znaleźć. Moje komentarze wyświetlają się odwrotnie niż mają. Najnowszy jest na górze a najstarszy na dole.

functions.php:
CODE

/** Comments */
if (function_exists('wp_list_comments')) {
// comment count
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $commentcount ) {
global $id;
$_commnets = get_comments('post_id=' . $id);
$comments_by_type = &separate_comments($_commnets);
return count($comments_by_type['comment']);
}
}

// custom comments
function custom_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
global $commentcount;
if(!$commentcount) {
$commentcount = 0;
}
?>
<li class="comment <?php if($comment->comment_author_email == get_the_author_email())
{echo 'admincomment';} else {echo 'regularcomment';} ?>" id="comment-<?php comment_ID() ?>">
<div class="author">
<div class="pic">
<?php if (function_exists('get_avatar') && get_option('show_avatars'))
{ echo get_avatar($comment, 32); } ?>
</div>
<div class="name">
<?php if (get_comment_author_url()) : ?>
<a id="commentauthor-<?php comment_ID() ?>
" class="url" href=
"<?php comment_author_url() ?>" rel="external nofollow">
<?php else : ?>
<span id="commentauthor-<?php comment_ID() ?>">
<?php endif; ?>

<?php comment_author(); ?>

<?php if(get_comment_author_url()) : ?>
</a>
<?php else : ?>
</span>
<?php endif; ?>
</div>
</div>

<div class="info">
<div class="date">
<? printf( __('%1$s at %2$s', 'inove'), get_comment_time(__('F jS, Y', 'inove')),
get_comment_time(__('H:i', 'inove')) ); ?>
| <a href="#comment-
<?php comment_ID() ?>"><?php printf('#%1$s', ++$commentcount); ?>
</a>
</div>
<div class="act">
<a href="java script:void(0);" onclick="MGJS_CMT.reply('commentauthor-
<?php comment_ID() ?>', 'comment-<?php comment_ID() ?>', 'comment');"><?php _e('Reply', 'inove'); ?>
</a> |
<a href="java script:void(0);" onclick="MGJS_CMT.quote('commentauthor-
<?php comment_ID() ?>',
'comment-<?php comment_ID() ?>', 'commentbody-<?php comment_ID() ?>', 'comment');">
<?php _e('Quote', 'inove'); ?></a>
<?php
if (function_exists("qc_comment_edit_link")) {
qc_comment_edit_link('', ' | ', '', __('Edit', 'inove'));
}
edit_comment_link(__('Advanced edit', 'inove'), ' | ', '');
?>
</div>
<div class="fixed"></div>
<div class="content">
<?php if ($comment->comment_approved == '0') : ?>
<p><small><?php _e('Your comment is awaiting moderation.', 'inove'); ?>
</small></p>
<?php endif; ?>

<div id="commentbody-<?php comment_ID() ?>">
<?php comment_text(); ?>
</div>
</div>
</div>
<div class="fixed"></div>
</li>
<?php
}
?>


comments.php
CODE

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/comment.js"></script>

<?php if (!empty($post->post_password) &&
$_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
<div class="errorbox">
<?php _e('Enter your password to view comments.', 'inove'); ?>
</div>
<?php return; endif; ?>

<?php
// for WordPress 2.7 or higher
if (function_exists('wp_list_comments')) {
$trackbacks = $comments_by_type['pings'];
// for WordPress 2.6.3 or lower
} else {
$trackbacks = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->
comments WHERE comment_post_ID =
%d AND comment_approved = '1' AND (comment_type = 'pingback'
OR comment_type = 'trackback') ORDER BY
comment_date", $post->ID));
}
?>

<?php if ($comments || comments_open()) : ?>
<div id="comments">

<div id="cmtswitcher">
<?php if(pings_open()) : ?>
<a id="commenttab" class="curtab" href="java script:void(0);" onclick="MGJS.switchTab
('thecomments,commentnavi', 'thetrackbacks', 'commenttab', 'curtab', 'trackbacktab', 'tab');">
<?php _e('Comments', 'inove');
echo (' (' . (count($comments)-count($trackbacks)) . ')'); ?></a>
<a id="trackbacktab" class="tab" href="java script:void(0);"
onclick="MGJS.switchTab('thetrackbacks', 'thecomments,commentnavi', 'trackbacktab',
'curtab', 'commenttab', 'tab');">
<?php _e('Trackbacks', 'inove'); echo (' (' . count($trackbacks) . ')'); ?></a>
<?php else : ?>
<a id="commenttab" class="curtab" href="java script:void(0);">
<?php _e('Comments', 'inove'); echo (' (' . (count($comments)-count($trackbacks)) . ')'); ?>
</a>
<?php endif; ?>
<?php if(comments_open()) : ?>
<span class="addcomment"><a href="#respond">
<?php _e('Leave a comment', 'inove'); ?></a></span>
<?php endif; ?>
<?php if(pings_open()) : ?>
<span class="addtrackback"><a href="<?php trackback_url(); ?>">
<?php _e('Trackback', 'inove'); ?></a>
</span>
<?php endif; ?>
<div class="fixed"></div>
</div>

<div id="commentlist">
<!-- comments START -->
<ol id="thecomments">
<?php
if ($comments && count($comments) - count($trackbacks) > 0) {
// for WordPress 2.7 or higher
if (function_exists('wp_list_comments')) {
wp_list_comments('type=comment&callback=custom_comments');
// for WordPress 2.6.3 or lower
} else {
foreach ($comments as $comment) {
if($comment->comment_type != 'pingback' && $comment->comment_type != 'trackback') {
custom_comments($comment, null, null);
}
}
}
} else {
?>
<li class="messagebox">
<?php _e('No comments yet.', 'inove'); ?>
</li>
<?php
}
?>
</ol>
<!-- comments END -->

<?php
if (get_option('page_comments')) {
$comment_pages = paginate_comments_links('echo=0');
if ($comment_pages) {
?>
<div id="commentnavi">
<span class="pages"><?php _e('Comment pages', 'inove'); ?></span>
<div id="commentpager">
<?php echo $comment_pages; ?>
</div>
<div class="fixed"></div>
</div>
<?php
}
}
?>

<!-- trackbacks START -->
<?php if (pings_open()) : ?>
<ol id="thetrackbacks">
<?php if ($trackbacks) : $trackbackcount = 0; ?>
<?php foreach ($trackbacks as $comment) : ?>
<li class="trackback">
<div class="date">

<? printf( __('%1$s at %2$s', 'inove'), get_comment_time
(__('F jS, Y', 'inove')), get_comment_time(__('H:i', 'inove')) ); ?>
| <a href="#comment-<?php comment_ID() ?>">
<?php printf('#%1$s', ++$trackbackcount); ?></a>
</div>
<div class="act">
<?php edit_comment_link(__('Edit', 'inove'), '', ''); ?>
</div>
<div class="fixed"></div>
<div class="title">
<a href="<?php comment_author_url() ?>">
<?php comment_author(); ?>
</a>
</div>
</li>
<?php endforeach; ?>

<?php else : ?>
<li class="messagebox">
<?php _e('No trackbacks yet.', 'inove'); ?>
</li>

<?php endif; ?>
</ol>
<?php endif; ?>
<div class="fixed"></div>
<!-- trackbacks END -->
</div>

</div>
<?php endif; ?>

<?php if (!comments_open()) : // If comments are closed. ?>
<div class="messagebox">
<?php _e('Comments are closed.', 'inove'); ?>
</div>
<?php elseif ( get_option('comment_registration') && !$user_ID ) :
// If registration required and not logged in. ?>
<div id="comment_login" class="messagebox">
<?php
if (function_exists('wp_login_url'))
{
$login_link = wp_login_url();
}
else {
$login_link = get_option('siteurl') .
'/wp-login.php?redirect_to='
.
urlencode(get_permalink());
}
?>
<?php printf(__('You must be
<a href="%s">logged in
</a> to post a comment.', 'inove'),
$login_link); ?>
</div>

<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>
/wp-comments-post.php" method="post" id="commentform">
<div id="respond">

<?php if ($user_ID) : ?>
<?php
if (function_exists('wp_logout_url')) {
$logout_link = wp_logout_url();
} else {
$logout_link = get_option('siteurl') . '/wp-login.php?action=logout';
}
?>
<div class="row">
<?php _e('Logged in as', 'inove'); ?>
<a href="<?php echo get_option('siteurl'); ?>
/wp-admin/profile.php"><strong><?php echo $user_identity; ?>
</strong></a>.
<a href="<?php echo $logout_link; ?>
" title="<?php _e('Log out of this account', 'inove'); ?>">
<?php _e('Logout &raquo;', 'inove'); ?></a>
</div>

<?php else : ?>
<?php if ( $comment_author != "" ) : ?>
<div class="row">
<?php printf(__('Welcome back <strong>%s</strong>.',
'inove'), $comment_author) ?>
<span id="show_author_info"><a href="java script:void(0);" onclick="MGJS.setStyleDisplay('author_info','');MGJS.setStyleDisplay('show_author_info','none');
MGJS.setStyleDisplay('hide_author_info','');"><?php _e('Change &raquo;'); ?></a></span>

<span id="hide_author_info"><a href="java script:void(0);"
onclick="MGJS.setStyleDisplay('author_info','none');MGJS.setStyleDisplay('show_author_info','');
MGJS.setStyleDisplay('hide_author_info','none');"><?php _e('Close &raquo;'); ?></a></span>
</div>
<?php endif; ?>

<div id="author_info">
<div class="row">
<input type="text" name="author" id="author" class="textfield" value="
<?php echo $comment_author; ?>" size="24" tabindex="1" />
<label for="author" class="small"><?php _e('Name', 'inove'); ?>
<?php if ($req) _e('(required)', 'inove'); ?></label>
</div>
<div class="row">
<input type="text" name="email" id="email" class="textfield" value="<?php echo $comment_author_email; ?>" size="24" tabindex="2" />
<label for="email" class="small">
<?php _e('E-Mail (will not be published)', 'inove');?>
<?php if ($req) _e('(required)', 'inove'); ?></label>
</div>
<div class="row">
<input type="text" name="url" id="url" class="textfield" value=
"<?php echo $comment_author_url; ?>" size="24" tabindex="3" />
<label for="url" class="small">
<?php _e('Website', 'inove'); ?></label>
</div>
</div>

<?php if ( $comment_author != "" ) : ?>
<script type="text/javascript">MGJS.setStyleDisplay('hide_author_info','none');MGJS.setStyleDisplay('author_info','none');</script>
<?php endif; ?>

<?php endif; ?>

<!-- comment input -->
<div class="row">
<textarea name="comment" id="comment" tabindex="4" rows="8" cols="50"></textarea>
</div>

<!-- comment submit and rss -->
<div id="submitbox">
<a class="feed" href="<?php bloginfo('comments_rss2_url'); ?>">
<?php _e('Subscribe to comments feed', 'inove'); ?></a>
<div class="submitbutton">
<input name="submit" type="submit" id="submit" class="button" tabindex="5" value=
"<?php _e('Submit Comment', 'inove'); ?>" />
</div>
<?php if (function_exists('highslide_emoticons')) : ?>
<div id="emoticon"><?php highslide_emoticons(); ?></div>
<?php endif; ?>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
<div class="fixed"></div>
</div>

</div>
<?php do_action('comment_form', $post->ID); ?>
</form>

<?php endif; ?>


comments.js:
CODE

/*
Author: mg12
Update: 2008/11/13
Author URI: http://www.neoease.com/
*/
(function() {

function reply(authorId, commentId, commentBox) {
var author = MGJS.$(authorId).innerHTML;
var insertStr = '<a href="#' + commentId + '">@' + author.replace(/\t|\n|\r\n/g, "") + '</a> \n';

appendReply(insertStr, commentBox);
}

function quote(authorId, commentId, commentBodyId, commentBox) {
var author = MGJS.$(authorId).innerHTML;
var comment = MGJS.$(commentBodyId).innerHTML;

var insertStr = '<blockquote cite="#' + commentBodyId + '">';
insertStr += '\n<strong><a href="#' + commentId + '">'
+ author.replace(/\t|\n|\r\n/g, "") + '</a> :</strong>';
insertStr += comment.replace(/\t/g, "");
insertStr += '</blockquote>\n';

insertQuote(insertStr, commentBox);
}

function appendReply(insertStr, commentBox) {
if(MGJS.$(commentBox) && MGJS.$(commentBox).type == 'textarea') {
field = MGJS.$(commentBox);

} else {
alert("The comment box does not exist!");
return false;
}

if (field.value.indexOf(insertStr) > -1) {
alert("You've already appended this reply!");
return false;
}

if (field.value.replace(/\s|\t|\n/g, "") == '') {
field.value = insertStr;
} else {
field.value = field.value.replace(/[\n]*$/g, "") + '\n\n' + insertStr;
}
field.focus();
}

function insertQuote(insertStr, commentBox) {
if(MGJS.$(commentBox) && MGJS.$(commentBox).type == 'textarea') {
field = MGJS.$(commentBox);

} else {
alert("The comment box does not exist!");
return false;
}

if(document.selection) {
field.focus();
sel = document.selection.createRange();
sel.text = insertStr;
field.focus();

} else if (field.selectionStart || field.selectionStart == '0') {
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
var cursorPos = startPos;
field.value = field.value.substring(0, startPos)
+ insertStr
+ field.value.substring(endPos, field.value.length);
cursorPos += insertStr.length;
field.focus();
field.selectionStart = cursorPos;
field.selectionEnd = cursorPos;

} else {
field.value += insertStr;
field.focus();
}
}

window['MGJS_CMT'] = {};
window['MGJS_CMT']['reply'] = reply;
window['MGJS_CMT']['quote'] = quote;

})();

Użytkownik 96th edytował ten post 06 kwiecień 2009
Powód edycji: Edycja kodu tak by tekst był w miarę czytelny - Warn ;]

0

#2
Bogdan  


  • Tytuł Pegetto
  • Grupa Przyjaciele forum
  • Postów 529
  • Rejestracja 10 luty 2009
  • GG:1557427
  • Płeć:Mężczyzna
  • Skąd:ja mam wiedzieć? ;)
  • OS:Ubuntu Linux
Mam ten styl na swoim blogu i komentarze wyświetlają mi się od najmłoszego do najstarszego. Sprawdzałeś ustawienia? http://adres-bloga/wp-admin/options-discussion.php (Ustawienia --> dyskusja)
0

#3
Usunięty/Gość_96th_*


  • Tytuł
  • Grupa Gość
Dzięki, nawet nie wiedziałem że taka opcja w WordPressie jest wink.gif
0

Udostępnij ten temat:


Strona 1 z 1
  • Nie możesz napisać tematu
  • Temat jest zamknięty

Użytkownicy przeglądający ten temat: 1
0 użytkowników, 1 gości, 0 anonimowych