PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : راهنمایی جهت نمایش مطالب مرتبط



docoder
December 23rd, 2018, 17:32
سلام دوستان
بنده نیاز دارم که مطالب مرتبط در در کنار محتوای سایت نمایش بدم
به طور کلی مطالب مرتبط بر اساس دسته بندی نشون بدم
کد های زیادی در نت هست اما برای من نمایش نمیده بر اساس دسته بندی

من یک پست تایپ جدید تولید کردم و میخوام مطالب بر اساس دسته بندی های اون پست تایپ باشن


<?php$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5, 'post__not_in' => array($post->ID) ) );if( $related ) foreach( $related as $post ) {setup_postdata($post); ?><ul> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php the_content('Read the rest of this entry &raquo;'); ?></li></ul> <?php }wp_reset_postdata(); ?>

این کد همه جا هست اما وقتی میذارمش میره مطالب پست های نوشته هامو نشون میده نه نوشته های پست تایپ جدیدم

چیکار کنم ؟

SIBHost
December 23rd, 2018, 19:38
برای اینکار افزونه های زیادی وجود داره، کلیدواژه زیر رو جستجو کنید:


Wordpress Related Posts Shortcode

اگر هم مایل به نصب افزونه نبودید، تکه کد زیر رو تست کنید:

<?php $orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;

$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=> 2, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo '<div id="related_posts"><h3>Related Posts</h3><ul>';
while( $my_query->have_posts() ) {
$my_query->the_post();?>

<li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a></div>
<div class="relatedcontent">
<h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_time('M j, Y') ?>
</div>
</li>
<?
}
echo '</ul></div>';
}
}
$post = $orig_post;
wp_reset_query(); ?>

docoder
December 23rd, 2018, 21:52
برای اینکار افزونه های زیادی وجود داره، کلیدواژه زیر رو جستجو کنید:


Wordpress Related Posts Shortcode

اگر هم مایل به نصب افزونه نبودید، تکه کد زیر رو تست کنید:


<?php $orig_post = $post;global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=> 2, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo '<div id="related_posts"><h3>Related Posts</h3><ul>';
while( $my_query->have_posts() ) {
$my_query->the_post();?>
<li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a></div>
<div class="relatedcontent">
<h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_time('M j, Y') ?>
</div>
</li>
<?
}
echo '</ul></div>';
}
}
$post = $orig_post;

wp_reset_query(); ?>
سلام ممنون از پاسختون
ببنید بنده یک پست تایپ ایجاد کردم به نام crous میخوام مطالب مرتبط این پست تایپ برای مطالب این پست تایپ نمایش بده
مثلا در یک دسته بندی تا مطلب دارم
میخوام کنار مطالب این دسته بندی فقط و فقط پست های همین دسته بندی رو نشون بده
لطفا راهنمایی کنید ممنون

sazsaz
December 23rd, 2018, 22:08
اینجا پاسختون داده شده
http://wpir.ir/thread348.html

docoder
December 23rd, 2018, 22:16
اینجا پاسختون داده شده
http://wpir.ir/thread348.html
سلام دوست خوبم خیلی ممنونم
والا میذارم چیزی نشون نمیده


<?php $orig_post = $post; global $post; $tags = wp_get_post_tags($post->ID); if ($tags) { $tag_ids = array(); foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id; $args=array( 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page'=>4, // Number of related posts to display. 'post_type' => 'crouse', 'caller_get_posts'=>1 ); $my_query = new wp_query( $args ); while( $my_query->have_posts() ) { $my_query->the_post(); ?><li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a></div><div class="relatedcontent"><h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><?php the_time('M j, Y') ?></div></li><? } } $post = $orig_post; wp_reset_query(); ?>

sazsaz
December 23rd, 2018, 22:30
دوتا کد هست یکی پایینه منظورم اونه

docoder
December 23rd, 2018, 22:44
دوتا کد هست یکی پایینه منظورم اونه

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

SIBHost
December 23rd, 2018, 23:35
تکه کدی که گذاشتم پست های مرتبط رو از یک دسته بندی استخراج خواهد کرد

docoder
December 24th, 2018, 10:36
تکه کدی که گذاشتم پست های مرتبط رو از یک دسته بندی استخراج خواهد کرد
سلام چه تکه کدی ؟؟