با سلام خدمت مدیران و دوستان عزیز.
کد زیر کد مطالب مشابه یا مرتبط هستند.
ولی من می خوام مطالب مشابه رو به صورت تصادفی نشون بده.
این کار شدنی هست؟!
کد زیر کد مطالب مشابه یا مرتبط هستند.
ولی من می خوام مطالب مشابه رو به صورت تصادفی نشون بده.
این کار شدنی هست؟!
کد:
<?php
$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),
'showposts'=>1, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<a href="<?php the_permalink()?>" title="<?php the_title(); ?>">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/no-thumbnail.png" width="150" height="100" alt="thumbnail" />';
}
?>
</a> <h2><a href="<?php the_permalink()?>"><?php the_title(); ?></a></h2>
<p> <?php the_content_rss('', TRUE, '', 40); ?>…</p>
<span class="info">(<time><?php the_time('j M Y') ?></time>)</span>
<?php
}
echo '';
}
}
?><?php wp_reset_query(); ?>
آخرین ویرایش توسط مدیر: