Посоветуйте плагин для Wordpress

ivmas
На сайте с 12.01.2010
Offline
121
746

Нужен плагин, который выводит под статьей похожие записи как "Yet Another Related Posts", только еще превью картинки нужно, не просто текст! Спасибо

stundr
На сайте с 19.06.2008
Offline
201
#1

можно без плагина.

вставьте в файл functions.php код:


function ordered_thumbnails( $display = 'true', $class='' ) {

global $post;

// get all image attachments for this post
$images = get_children( array( 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', order=>"asc" ) );

// if the post has image attachments
if( $images !== false ) {

// find the image in position 1
foreach($images as $i) {
if ( $i->menu_order == 1 ) {
$img_id = $i->ID;
}
}

// if the images were unordered
if ( $img_id == '' ) {
$i = array_slice( $images, 0, 1 );
$img_id = $i[0]->ID;
}

// get image data
$image = wp_get_attachment_image_src( $img_id, 'thumbnail' );

$result = array(
'url' => $image[0],
'width' => $image[1],
'height' => $image[2]
);

// should the image be displayed or should data be returned as an array?
if ( $display == 'true' ) {
return _e( '<img src="'.$result['url'].'" width="'.$result['width'].'" height="'.$result['height'].'" class="'.$class.'" />' );
} else {
return $result;
}

} else {

// post does not have any image attachments
return (bool) false;

}
}

function ordered_thumbnails_medium( $display = 'true', $class='' ) {

global $post;

// get all image attachments for this post
$images = get_children( array( 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', order=>"asc" ) );

// if the post has image attachments
if( $images !== false ) {

// find the image in position 1
foreach($images as $i) {
if ( $i->menu_order == 1 ) {
$img_id = $i->ID;
}
}

// if the images were unordered
if ( $img_id == '' ) {
$i = array_slice( $images, 0, 1 );
$img_id = $i[0]->ID;
}

// get image data
$image = wp_get_attachment_image_src( $img_id, 'medium' );

$result = array(
'url' => $image[0],
'width' => $image[1],
'height' => $image[2]
);

// should the image be displayed or should data be returned as an array?
if ( $display == 'true' ) {
return _e( '<img src="'.$result['url'].'" width="'.$result['width'].'" height="'.$result['height'].'" class="'.$class.'" />' );
} else {
return $result;
}

} else {

// post does not have any image attachments
return (bool) false;

}
}

// create template tag "ordered_thumbnails"
add_action( 'ordered_thumbnails', 'ordered_thumbnails', 2 );


// Add Post Thumbnail Theme Support
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
add_image_size( 'featured', 200, 150, true );
}

//get thumbnail
function postimage($size=medium) {
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'order' => 'ASC',
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo $attachmentimage.apply_filters('the_title', $parent->post_title);
}
}
}

//check any attachment
function checkimage($size=medium) {
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
return $attachmentimage;
}
}
}

и в файл single.php в нужное место код:


<div>
<?php
$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),
'showposts'=> 5, // Number of related posts that will be shown.
'caller_get_posts'=> 1
);
$rp_query = new wp_query($args);
endif;
if($rp_query):
if($rp_query->have_posts()) ?>
<?php while ($rp_query->have_posts()): $rp_query->the_post(); ?>

<div style="width:210px;padding:10px;text-align:center;display:inline-block;position:relative;vertical-align:top;float:left;" >
<div style="text-align:center;"><a href="<?php the_permalink() ?>" title="<?php the_title('', ''); ?>"><?php ordered_thumbnails(); ?></div>
<div style="text-align:center;"><?php the_title(); ?></a></div>
</div>
</div>

<?php endwhile; ?>
<?php else: ?>
<div><?php _e("Матрица свободна, Нео...",""); ?></div>
<?php endif; wp_reset_query(); ?>
</div>
=^_^=
facegrodno
На сайте с 02.05.2009
Offline
45
#2

что-то у вас с div напутано

Партнерка кино и развлекательное (http://u.to/BrgYAQ) Новая Кинопартнерка (http://goo.gl/tXuaC) NEW Май 2012
stundr
На сайте с 19.06.2008
Offline
201
#3

если поправите, то это будет только приветствоваться.

InoHacker
На сайте с 18.10.2009
Offline
75
#4

Я пользуюсь вот таким. Если чуть-чуть подогнать под дизайн, получается очень даже ничего.

Магазин аккаунтов с балансом Litres,DNS,Ozon,Rotapost и еще 50+ других сервисов тут - vk.cc/7QK0Sk
ivmas
На сайте с 12.01.2010
Offline
121
#5

А какие еще плагины есть?

Оринаих
На сайте с 13.04.2008
Offline
147
#6

Contextual Related Posts. Можно настроить — показывать только текстом или с миниатюрами.

© TextBroker.ru - копирайтинг на заказ (http://textbroker.ru/?source=search) © TextReporter.ru - наполнение сайтов и соцгрупп (http://textreporter.ru/?source=search) © TextDreamer.ru - слоганы, нейминг (http://textdreamer.ru/?source=search)
hexacell
На сайте с 10.12.2010
Offline
65
#7

Есть вот такой - RELATED POST with THUMBNAIL. А тут описание. Но он с 2008 не обновлялся, кто его знает работает ли.

Есть еще Contextual Related Posts. Тут описание и руссификатор. Этот по-новее будет.

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий