مدیریت کل سایت Saberian 1,792 ارسال شده در مهر 2، 1394 مدیریت کل سایت گزارش اشتراک گذاری ارسال شده در مهر 2، 1394 نمایش مطالب مرتبط در صفحه مطلب وردپرس زیر پست مزایای زیادی دارد و باعث میشه که کاربر با دیدن مطالبی که مرتبط با اون پست هست که به اون علاقه داره مدت زمان بیشتری در سایت ما بمونه و این به نفع ماست در این روش مطالب مرتبط با توجه به دسته بندی پست اصلی انجام میشه اول فایل functions.php پوسته رو باز کنید و کد زیر رو در اون قرار بدید : // "More from This Category" list by Barış Ünver @ 20script+function bistscript_more_from_cat( $title = "More From This Category:" ) { global $post; // We should get the first category of the post $categories = get_the_category( $post->ID ); $first_cat = $categories[0]->cat_ID; // Let's start the $output by displaying the title and opening the <ul> $output = '<div id="more-from-cat"><h3>' . $title . '</h3>'; // The arguments of the post list! $args = array( // It should be in the first category of our post: 'category__in' => array( $first_cat ), // Our post should NOT be in the list: 'post__not_in' => array( $post->ID ), // ...And it should fetch 5 posts - you can change this number if you like: 'posts_per_page' => 5 ); // The get_posts() function $posts = get_posts( $args ); if( $posts ) { $output .= '<ul>'; // Let's start the loop! foreach( $posts as $post ) { setup_postdata( $post ); $post_title = get_the_title(); $permalink = get_permalink(); $output .= '<li><a href="https://go.20script.ir/index.php?url=' . $permalink . '" title="' . esc_attr( $post_title ) . '">' . $post_title . '</a></li>'; } $output .= '</ul>'; } else { // If there are no posts, we should return something, too! $output .= '<p>Sorry, this category has just one post and you just read it!</p>'; } // Let's close the <div> and return the $output: $output .= '</div>'; return $output;} بعد برای نمایش مطلب مرتبط کد زیر رو در جای مناسب در پایین پست قرار بدید : <?php echo bistscript_more_from_cat( 'مطالب مرتبط:' ); ?> لینک به دیدگاه به اشتراک گذاری در سایت های دیگر More sharing options...
پست های پیشنهاد شده