Пробуйте
| Код |
|---|
<div class="related_posts">
<p>Похожие материалы</p>
<?php
$tags = wp_get_post_tags($post->ID);
$categories = get_the_category($post->ID);
if (!empty($tags)) {
$tag_ids = array();
foreach ($tags as $individual_tag)
$tag_ids[] = $individual_tag->term_id;
$args = array(
'tag__in' => $tag_ids,
'orderby' => rand,
'post__not_in' => array(
$post->ID
),
'showposts' => 4
);
$my_query = new wp_query($args);
echo '<ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
$title = the_title();
$link = the_permalink();
$thumbnail = the_post_thumbnail();
$trim_title = trim_title_words(7, '...');
echo '<li><a href="' . $link . '" rel="bookmark" title="' . $title . '">' . $thumbnail . '<br />' . $trim_title . '</a></li>';
}
echo '</ul>';
} else {
$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' => 4,
'orderby' => rand,
'caller_get_posts' => 1
);
$my_query = new wp_query($args);
echo '<ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
$title = the_title();
$link = the_permalink();
$thumbnail = the_post_thumbnail();
$trim_title = trim_title_words(7, '...');
echo '<li><a href="' . $link . '" rel="bookmark" title="' . $title . '">' . $thumbnail . '<br />' . $trim_title . '</a></li>';
}
echo '</ul>';
}
wp_reset_query();
?>
</div>
|
