<h3>Похожие статьи:</h3> <div class="sample-posts"> <ul> <?php //for use in the loop, list 5 post titles related to first tag on current post $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'post__not_in' => array($post->ID), 'showposts'=>5, 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> <?php endwhile; } wp_reset_query(); } ?> </ul> </div>
Понравилась статья? - Подпишись. Или поделись полезным с миром
.sample-posts ul li{
background-image:url("img/list-main.gif");
background-position:left center;
background-repeat:no-repeat;
list-style-type:none;
margin-bottom:5px;
padding-left:18px;
}
<div class="sample-posts">
<h3>Похожие статьи:</h3>
<?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'=>5, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
// Rest is the same as the previous code
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '<ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
}
echo '</ul>';
}
wp_reset_query();
}
?></div>
В ответе на один из предыдущих комментов ты пишешь
И второй вопрос, в какую директорию надо заливать изображение list-main.gif?
Или ответ был об этой записи?
Спасибо за разъяснение того, куда вставлять эту строчку