• توجه: در صورتی که از کاربران قدیمی ایران انجمن هستید و امکان ورود به سایت را ندارید، میتوانید با آیدی altin_admin@ در تلگرام تماس حاصل نمایید.

سوال: نحوه شخصی سازی لیست نظرات سایت وردپرسی

t92

متخصص بخش
امین الان مسئله اینجاست
اگه توی قالبی این فرمت رو برای کامنت ها ایجاد کنیم یعنی
PHP:
 wp_list_comments(array('callback' => 'twentyten_comment'));
و callback به این صورت:

PHP:
function twentyten_comment( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
        case '' :
    ?>
    <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( $comment, 40 ); ?>
                <?php printf( __( '%s <span class="says"></span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?> | <?php printf(__(' %1$s '), get_comment_date()) ?>




<br />
            </div><!-- .comment-author .vcard -->
            <?php if ( $comment->comment_approved == '0' ) : ?>
                <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
                
            <?php endif; ?>


<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">


<?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );?>


            </div><!-- .comment-meta .commentmetadata -->


            <div class="comment-body"><?php comment_text(); ?></div>


            <div class="reply">
                <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
            </div><!-- .reply -->
        </div><!-- #comment-##  -->


    <?php
            break;
        case 'pingback'  :
        case 'trackback' :
    ?>
    <li class="post pingback">
        <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
    <?php
            break;
    endswitch;
}
میتونی تست کنی ببینی برات جواب میده؟
 

amin khan

مدیر انجمن
خب الان هم از همین روش استفاده شده بود!
یعنی می خوای کدش رو ببری رو یه قالب دیگه پیاده کنی؟
 

t92

متخصص بخش
خب الان هم از همین روش استفاده شده بود!
یعنی می خوای کدش رو ببری رو یه قالب دیگه پیاده کنی؟

آره
یعنی این که تنها کدهایی که روی کامنت و خروجی تاثیر دارند کدهایی که بالا قرار داده شد هستند ؟
به عبارت دیگه اگه توی قالبی که کد های اون کپی نباشه کدوم کدها رو قرار بدیم خروجی مورد نظرمون رو برای کامنت ها نتیجه میده؟
همین دو تکه کد رو تست کردی؟ برای من جواب نداده این دو تا کد ها...
البته روش دیگه ای هست ... (آموزشش رو بعدا میذارم اگه قسمت باشه)
ولی بهتره ببینیم برای تو جواب میده این دو تکه کد به تنهایی یا نه...
میتونی تست کنی؟
:دوست:
:ماچ:
 

amin khan

مدیر انجمن
اره اگه اون تکه کد رو درست برداری 100% جواب میده
فقط مشکلی که تو این جور قالب ها هست و من به همین دلیل از این قالب ها برای ویرایش استفاده نمیکنم اینکه علاوه بر قسمت کامنت سعی کرده تکه کدی از سایر بخش ها هم تو فایل فانکشن قرار بده که با برداشتن سایر کد صفحه بالا نمیاد و فکر میکنی که کد های مربوط به کامنت رو درست کپی نکردی.
البته تو وردپرس یه راهی هم هست که متونی یه قالب تعریف کنی و بگی هر موقع اینجا رسیدی برو از فلان فایل کدارو اجرا کن (همون تابع include در php)

در کل به نظر من اگه میخوای کل قالب رو تغییر بدی از قالب های ساده استفاده کن که باعث سردرگمی و کپی شدن کد های اضافی نشی
 

t92

متخصص بخش
اره اگه اون تکه کد رو درست برداری 100% جواب میده
فقط مشکلی که تو این جور قالب ها هست و من به همین دلیل از این قالب ها برای ویرایش استفاده نمیکنم اینکه علاوه بر قسمت کامنت سعی کرده تکه کدی از سایر بخش ها هم تو فایل فانکشن قرار بده که با برداشتن سایر کد صفحه بالا نمیاد و فکر میکنی که کد های مربوط به کامنت رو درست کپی نکردی.
البته تو وردپرس یه راهی هم هست که متونی یه قالب تعریف کنی و بگی هر موقع اینجا رسیدی برو از فلان فایل کدارو اجرا کن (همون تابع include در php)

در کل به نظر من اگه میخوای کل قالب رو تغییر بدی از قالب های ساده استفاده کن که باعث سردرگمی و کپی شدن کد های اضافی نشی

برای من جواب نداد وقتی از دو تکه کد بالا استفاده کردم...
ولی اصولا باید کار میکرد...
به هر حال فرصت کردی تست کنی نتیجه رو اینجا بنویس...:گل:
یعنی با استفاده از wp_list_comments() و آرگومان Callback .
اما روش دیگه ای که جواب میده استفاده از wp_list_commets() و آرگومان Walker هست !
که در یک تاپیک دیگه فرصت شد آموزشش رو قرار میدم.
اگه تست کردی خبر بده..
دوستان دیگه هم تست کردند خبر بدند....
 

amin khan

مدیر انجمن
اصلا نیازی به این همه کار نیست و تنها با قرار دادن کد در فایل کامنت میشه اون قسمت رو به هر شکل مورد نیاز در اورد
در هر صورت اون کدی که تو اون قالب بود رو تست کردم و انتقال دادم به قالب خام دیگه کار کرد

کد های زیر رو بذارید آخر فانکشن

PHP:
// Backwards compatibility with WordPress 3.0.if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )	add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
if ( ! function_exists( 'twentyten_comment' ) ) :/** * Template for comments and pingbacks. * * To override this walker in a child theme without modifying the comments template * simply create your own twentyten_comment(), and that function will be used instead. * * Used as a callback by wp_list_comments() for displaying the comments. * * @since Twenty Ten 1.0 */function twentyten_comment( $comment, $args, $depth ) {	$GLOBALS['comment'] = $comment;	switch ( $comment->comment_type ) :		case '' :	?>	<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( $comment, 40 ); ?>				<?php printf( __( '%s <span class="says"></span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?> | <?php printf(__(' %1$s '), get_comment_date()) ?>


<br />			</div><!-- .comment-author .vcard -->			<?php if ( $comment->comment_approved == '0' ) : ?>				<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>							<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );?>





			</div><!-- .comment-meta .commentmetadata -->
			<div class="comment-body"><?php comment_text(); ?></div>
			<div class="reply">				<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>			</div><!-- .reply -->		</div><!-- #comment-##  -->
	<?php			break;		case 'pingback'  :		case 'trackback' :	?>	<li class="post pingback">		<p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>	<?php			break;	endswitch;}endif;



کد زیر رو هم بذارید فایل comment.php

PHP:
<?php/** * The template for displaying Comments. * * The area of the page that contains both current comments * and the comment form. The actual display of comments is * handled by a callback to twentyten_comment which is * located in the functions.php file. * * @package WordPress * @subpackage Twenty_Ten * @since Twenty Ten 1.0 */?>
			<div id="comments"><?php if ( post_password_required() ) : ?>				<p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'twentyten' ); ?></p>			</div><!-- #comments --><?php		/* Stop the rest of comments.php from being processed,		 * but don't kill the script entirely -- we still have		 * to fully load the template.		 */		return;	endif;?>
<?php	// You can start editing here -- including this comment!?>
<?php if ( have_comments() ) : ?>			<h3 id="comments-title"><?php			printf( _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'twentyten' ),			number_format_i18n( get_comments_number() ), '<em>' . get_the_title() . '</em>' );			?></h3>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>			<div class="navigation">				<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">←</span> Older Comments', 'twentyten' ) ); ?></div>				<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>			</div> <!-- .navigation --><?php endif; // check for comment navigation ?>
			<ol class="commentlist">				<?php					/* Loop through and list the comments. Tell wp_list_comments()					 * to use twentyten_comment() to format the comments.					 * If you want to overload this in a child theme then you can					 * define twentyten_comment() and that will be used instead.					 * See twentyten_comment() in twentyten/functions.php for more.					 */					wp_list_comments( array( 'callback' => 'twentyten_comment' ) );				?>			</ol>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>			<div class="navigation">				<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">←</span> Older Comments', 'twentyten' ) ); ?></div>				<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>			</div><!-- .navigation --><?php endif; // check for comment navigation ?>
	<?php	/* If there are no comments and comments are closed, let's leave a little note, shall we?	 * But we only want the note on posts and pages that had comments in the first place.	 */	if ( ! comments_open() && get_comments_number() ) : ?>		<p class="nocomments"><?php _e( 'Comments are closed.' , 'twentyten' ); ?></p>	<?php endif;  ?>
<?php endif; // end have_comments() ?>
<?php comment_form(); ?>
</div><!-- #comments -->
 
بالا