مطالب مرتبط در وردپرس بدون افزونه

ساخت وبلاگ

<?php

//شناسایی نوشته های مرتبط با تگ اول نوشته حاضر

$tags = wp_get_post_tags($post->ID);

if ($tags) {

// خواندن تگ اول نوشته

$first_tag = $tags[0]->term_id;

$args=array(

// اگر میخواهید تمام تگها بررسی شوند، در سطر بعدی به جای

// $first_tag

// بنویسید:

// $tags

'tag__in' => array($first_tag),

'post__not_in' => array($post->ID),

'posts_per_page'=>4,

'caller_get_posts'=>1

);

// http://codex.wordpress.org/Class_Reference/WP_Query

$my_query = new WP_Query($args);

if( $my_query->have_posts() ) {

?>  <aside class="widget widget_related_posts"> <?php

echo '<h4 class="widget-title">دسخط های مرتبط</h4>';

while ($my_query->have_posts()) : $my_query->the_post(); ?>

<article class="post">

    <div class="post-media">

<!-- چاپ تصویر نوشته مرتبط

http://codex.wordpress.org/Function_Reference/the_post_thumbnail

-->

                            <a href="<?php the_permalink() ?>" class="thumbnail"><?php the_post_thumbnail('thumb-160'); ?></a>

                        </div>

<!-- چاپ لینک و عنوان نوشته مرتبط -->

<h5><a href="<?php the_permalink() ?>" title="لینک یکتا به <?php the_title_attribute(); ?>" ><?php the_title(); ?></a></h5>

                    <footer class="post-meta">

<!-- چاپ تعداد دیدگاه نوشته مرتبط -->

                          <?php the_time('j F, Y'); ?> <a href="<?php echo the_permalink().'/#Idea' ?>" class="Idea-count"><?php Idea_number('0', '1', '%'); ?></a>

                     </footer>

</article>

<?php

endwhile;

?>

</aside>

<?php

}

// بازگرداندن کوئری وردپرس به حالت عادی

// http://codex.wordpress.org/Function_Reference/wp_reset_query

wp_reset_query();

}

?>

- - , .

آموزش دستک...
ما را در سایت آموزش دستک دنبال می کنید

برچسب : نویسنده : استخدام کار dastak بازدید : 175 تاريخ : دوشنبه 28 دی 1394 ساعت: 23:34