WP: previous post excerpt

medea
На сайте с 19.09.2007
Offline
307
616

Как на single страничке после текущего поста вывести previous post excerpt?

Нашел только функцию previous_post_link(), но с её помощью, как я понимаю, можно вывести только ссылку с анкором-заголовком?

medea добавил 03.05.2009 в 20:53

Нашел решение в одной из тем, мало ли кому пригодится:

в папке с темой в файле functions.php создаем такие функции:


function tl_excerpt($text, $excerpt_length = 55) {
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}

return apply_filters('the_excerpt', $text);
}

function tl_post_excerpt($post) {
$excerpt = ($post->post_excerpt == '') ? (tl_excerpt($post->post_content))
: (apply_filters('the_excerpt', $post->post_excerpt));
return $excerpt;
}

function previous_post_excerpt($in_same_cat = false, $excluded_categories = '') {
if ( is_attachment() )
$post = &get_post($GLOBALS['post']->post_parent);
else
$post = get_previous_post($in_same_cat, $excluded_categories);

if ( !$post )
return;
$post = &get_post($post->ID);
echo tl_post_excerpt($post);
}

function next_post_excerpt($in_same_cat = false, $excluded_categories = '') {
$post = get_next_post($in_same_cat, $excluded_categories);

if ( !$post )
return;
$post = &get_post($post->ID);
echo tl_post_excerpt($post);
}

а, соответственно, в том месте, где нам нужно вывести post_excerpt, пишем


<?php
$previouspost = get_previous_post($in_same_cat, $excluded_categories);
if ($previouspost != null) {

previous_post_excerpt();

} ?>
Продвижение сайтов (http://www.iqpromo.ru/) под моим присмотром :)

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