در این آموزش برای نمایش مطلب قبلی و بعدی در انتهای مطالب و یا در هر صفحه دیگر قطعه کدی را معرفی خواهیم کرد تا به راحتی این امکان را به سایت خود بیفزایید.
نمایش مطلب قبلی و بعدی در وردپرس
برای نمایش مطلب قبلی و بعدی هر پست میتوانید قطعه کد زیر را در مکانی که تمایل دارید نمایش داده شود قرار دهید.
?php $post_id = $post-ID; // آی دی پست جاری $cat = get_the_category(); $current_cat_id = $cat[0]-cat_ID; // آی دی دسته بندی پست جاری $args = array('category'=$current_cat_id,'orderby'='post_date','order'= 'DESC'); $posts = get_posts($args); // get ids of posts retrieved from get_posts $ids = array(); foreach ($posts as $thepost) { $ids[] = $thepost-ID; } // get and echo previous and next post in the same category $thisindex = array_search($post-ID, $ids); $previd = $ids[$thisindex-1]; $nextid = $ids[$thisindex+1]; if (!empty($previd)){ ? a rel="prev" href="?php echo get_permalink($previd) ?"پست قبلی/a ?php } if (!empty($nextid)){ ? a rel="next" href="?php echo get_permalink($nextid) ?"پست بعدی/a ?php } ?
امتیاز شما از ۱ تا ۵
۱ رای
Loading…