merhann 0 ارسال شده در مرداد 93 گزارش بازنشر ارسال شده در مرداد 93 با سلام و عرض خسته نباشد . من افزونه ی Post Views رو نصب کردم .. در جایگزاری کد دچار مشکل هستم . چون اینجا دیگه بحث single.php نیست که کد رو جاسازی کنم . من احیتاج دارم تعداد آمار بازدید من دقیقا در یک <div> با تولبار متام (که نام نویسنده و تاریخ و دسته بندی) در اون وجود داره باشه ..زبان پی اچ پی من قد نداد که این کد رو در فانکشن درست کنم .. لطفا راهنمایی کنید . "ابتدا این کد post views : <?php echo_post_views(get_the_ID()); ?> اما نکته ی اصلی کد نیست .. بلکه فانکشن من هست .. چون توابطع رو غیر مستقیم داره میخونه نه مستیقیم . دقت برمایید : $output = '<div class="mom-post-meta '.$class.'">';$author = mom_option('post_meta-author') == 1 ? '<span class="author vcard">'.__('Posted By:', 'theme').' <span class="fn"><a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'.get_the_author_meta( 'display_name' ).'</a></span></span>': '';$date = mom_option('post_meta-date') == 1 ? '<span>'.__('Posted date:', 'theme').' <time datetime="'.get_the_time('c').'" itemprop="datePublished" class="updated">'.get_mom_date_format().'</time></span>': '';$cat = mom_option('post_meta-cat') == 1 ? '<span>'.__('in:', 'theme').' '.trim($cats, $separator).'</span>': '';$comments = mom_option('post_meta-comments') == 1 ? '<span>'.$write_comments.'</span>': '';if ($display == 'date_comments') {$output .= $date.$comments;} else {$output .= $author.$date.$cat.$comments;}$output .= get_mom_show_review_score();$output .= '</div>';echo $output;}خوب حالا سوال من اینجاست کد post views رو به چه شکل میتونم بنویسیم که در قسمتی که Output در واقع echo شده .. یک سری آرایه رو فراخوانی و به نمایش میزاره .. حالا به نظر شما به چه شکل میتونم کدم رو مثل این کد ها در داخل این کد جا بدم و ازش نمایش بگیرم ؟ نقل قول لینک به ارسال
imanfakhar 26231 ارسال شده در مرداد 93 گزارش بازنشر ارسال شده در مرداد 93 $output = '<div class="mom-post-meta '.$class.'">';$author = mom_option('post_meta-author') == 1 ? '<span class="author vcard">'.__('Posted By:', 'theme').' <span class="fn"><a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'.get_the_author_meta( 'display_name' ).'</a></span></span>': '';$date = mom_option('post_meta-date') == 1 ? '<span>'.__('Posted date:', 'theme').' <time datetime="'.get_the_time('c').'" itemprop="datePublished" class="updated">'.get_mom_date_format().'</time></span>': '';$cat = mom_option('post_meta-cat') == 1 ? '<span>'.__('in:', 'theme').' '.trim($cats, $separator).'</span>': '';$comments = mom_option('post_meta-comments') == 1 ? '<span>'.$write_comments.'</span>': '';if ($display == 'date_comments') {$output .= $date.$comments;} else {$output .= $author.$date.$cat.$comments;}$output .= get_post_views();$output .= get_mom_show_review_score();$output .= '</div>';echo $output;}تست کنید مشکل داشت پیوند افزونه تون رو در وردپرس بگذارید افزونه های هم نام و مشابه زیادند 1 نقل قول لینک به ارسال
merhann 0 ارسال شده در مرداد 93 مالک گزارش بازنشر ارسال شده در مرداد 93 (ویرایش شده) با سلام و تشکری ویژه خدمت استاد ..لینک افزونه https://wordpress.org/plugins/wp-postviews/راستش رو بخواید این کارو کرده بودم ولی اعداد رو بالا یا پایین متا مینداخت .. ولی با این کد کلا دیگه لود نشد .. من به حالت قبل برگردوندم .. براتون یه عکسی میگیرم امیدوارم کمک کنه .این متای من هست .. که داره این کد $output .= $author.$date.$cat.$comments; رو فراخوانی می کنه .. و فقط $date و $cat ... حالا به این کاری نداریممن کد کامل فانکشن این قسمت رو قرار میدم خدمتتون ... من دقیقا میخوام بازدید تو لیست اینا بیوفته ..قبل از هرجیزی چه بشه چه نشه از شما استاد بزرگوار تشکر میکنم .function mom_posts_meta ($class = '', $display = null) {$num_comments = get_comments_number(); // get_comments_number returns only a numeric valueif ( comments_open() ) {if ( $num_comments == 0 ) {$comments = __('No Comments', 'theme');} elseif ( $num_comments > 1 ) {$comments = $num_comments .' '. __(' Comments', 'theme');} else {$comments = __('1 Comment', 'theme');}$write_comments = '<a href="' . get_comments_link() .'">'. $comments.'</a>';} else {//$write_comments = __('Comments off', 'theme');$write_comments = '';}$categories = get_the_category();$separator = ', ';$cats = '';if($categories){foreach($categories as $category) {$cats.= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s", 'theme' ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;}}$output = '<div class="mom-post-meta '.$class.'">';$author = mom_option('post_meta-author') == 1 ? '<span class="author vcard">'.__('Posted By:', 'theme').' <span class="fn"><a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'.get_the_author_meta( 'display_name' ).'</a></span></span>': '';$date = mom_option('post_meta-date') == 1 ? '<span>'.__('Posted date:', 'theme').' <time datetime="'.get_the_time('c').'" itemprop="datePublished" class="updated">'.get_mom_date_format().'</time></span>': '';$cat = mom_option('post_meta-cat') == 1 ? '<span>'.__('in:', 'theme').' '.trim($cats, $separator).'</span>': '';$comments = mom_option('post_meta-comments') == 1 ? '<span>'.$write_comments.'</span>': '';if ($display == 'date_comments') {$output .= $date.$comments;} else {$output .= $author.$date.$cat.$comments;}$output .= get_mom_show_review_score();$output .= '</div>';echo $output;} ویرایش شده مرداد 93 توسط merhann نقل قول لینک به ارسال
imanfakhar 26231 ارسال شده در مرداد 93 گزارش بازنشر ارسال شده در مرداد 93 تست کنید $output = '<div class="mom-post-meta '.$class.'">';$author = mom_option('post_meta-author') == 1 ? '<span class="author vcard">'.__('Posted By:', 'theme').' <span class="fn"><a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'.get_the_author_meta( 'display_name' ).'</a></span></span>': '';$date = mom_option('post_meta-date') == 1 ? '<span>'.__('Posted date:', 'theme').' <time datetime="'.get_the_time('c').'" itemprop="datePublished" class="updated">'.get_mom_date_format().'</time></span>': '';$cat = mom_option('post_meta-cat') == 1 ? '<span>'.__('in:', 'theme').' '.trim($cats, $separator).'</span>': '';$comments = mom_option('post_meta-comments') == 1 ? '<span>'.$write_comments.'</span>': '';$views = get_post_meta($post->ID, 'views', true);if ($display == 'date_comments') {$output .= $date.$comments.' '.$views;} else {$output .= $author.$date.$cat.$comments.' '.$views;}$output .= get_mom_show_review_score();$output .= '</div>';echo $output;} 1 نقل قول لینک به ارسال
macro 52 ارسال شده در مرداد 93 گزارش بازنشر ارسال شده در مرداد 93 (ویرایش شده) استاد بزرگوار من مرهان هستم .. و خواستم بگم کمک بسیار بسیار بزرگی انجام دادید . کدی که دادید کاملا درست بود ولی متوجه نشدم چرا $views = get_post_meta($post->ID, 'views', true); قسمت get_post_meta رو نمایش نداد .. کد شما از لحاظ ساختاری کاملا درست بود و باید اینجا میگرفت در قسمت output نمایش می داد .. به هر ترتیب من داشتم تو خوده افزونه گشت و گذار میکردم دیدم میشه با یه the_views() به نمایش درورد .. مشکل بعدی من این بود که 2 بار روی متا post views رو نشون میداد یکی نمایش تعداد پست های واقعی بود و یکی هم 1 رو نشون می داد . برای کامل شدن پست باز جسارت کردم و تغییراتی دادم باز و کد شما تبدیل شد به $views = the_views($post->ID, true) ; و به جاش از توی خود افزونه سیستم label رو نوشتم .. واقعا سپاس گذارم استاد فوق العاده بود کمکتون این هم نتیجه ی آخری برای کسانی که اگه روزی با این افزونه کار کردن و به این مشکل برخوردند . ویرایش (به دلیل اینکه تو کد هست بولد نشده بقل لای های مهم وجود داره )$output = '<div class="mom-post-meta '.$class.'">';$author = mom_option('post_meta-author') == 1 ? '<span class="author vcard">'.__('Posted By:', 'theme').' <span class="fn"><a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'.get_the_author_meta( 'display_name' ).'</a></span></span>': '';$date = mom_option('post_meta-date') == 1 ? '<span>'.__('Posted date:', 'theme').' <time datetime="'.get_the_time('c').'" itemprop="datePublished" class="updated">'.get_mom_date_format().'</time></span>': '';$cat = mom_option('post_meta-cat') == 1 ? '<span>'.__('in:', 'theme').' '.trim($cats, $separator).'</span>': '';$comments = mom_option('post_meta-comments') == 1 ? '<span>'.$write_comments.'</span>': '';[b]$views = the_views($post->ID, true) ; [/b]if ($display == 'date_comments') {[b]$output .= $date.$comments.' '.$views;[/b]} else {[b]$output .= $author.$date.$cat.$comments.' '.$views;[/b]}$output .= get_mom_show_review_score();$output .= '</div>';echo $output;} ویرایش شده مرداد 93 توسط macro 1 نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .