0

How can i show the content in next previous post of wordpress. For example. For the next post link with title is to be there, Is it possible to show the content of that post (100 Words).

       <div class="alignleftfp">
        <?php next_post_link('%link', '%title'); ?>
<?php get_next_post();?>
        </div>
        <div class="alignrightfp">
        <?php previous_post_link('%link', '%title'); ?>
<?php get_previous_post();?>
        </div>

Much appreciated if any response. . .

4

5 回答 5

2

get_next_post and get_previous_post should help you out.

于 2013-07-18T09:05:52.190 回答
1

如果它在 The Loop 内,您可以使用the_excerpt()get_the_excerpt()根据您的要求使用。

如果它在循环之外,您可以使用这样的函数通过帖子 ID 获取帖子摘录:

function get_excerpt_by_id($post_id){
    $the_post = get_post($post_id); //Gets post ID
    $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
    $excerpt_length = 35; //Sets excerpt length by word count
    $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
    $words = explode(' ', $the_excerpt, $excerpt_length + 1);

    if(count($words) > $excerpt_length) :
        array_pop($words);
        array_push($words, '…');
        $the_excerpt = implode(' ', $words);
    endif;

    $the_excerpt = '<p>' . $the_excerpt . '</p>';

    return $the_excerpt;
}

希望这可以帮助!

于 2013-07-18T09:06:37.200 回答
0

您可以使用以下功能

对于下一篇文章链接

<?php next_post_link('format', 'link', 'in_same_cat', 'excluded_categories'); ?>

对于以前的帖子链接

<?php previous_post_link($format, $link, $in_same_cat = false, $excluded_categories = ''); ?> 
于 2013-07-18T12:29:43.577 回答
0
function content($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}   
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $content;
}

在帖子页面中,输入这样的字数限制->回显内容(100)。希望这会帮助你。

于 2013-07-18T10:07:36.570 回答
0
<div class="post-navigation">
        <div class="prev-post">
            <?php $greenres_prev_post = get_previous_post();
            if($greenres_prev_post):
                ?>
                <h3 class="post-title"><a href="<?php echo get_the_permalink($greenres_prev_post);
                    ?>"><?php echo get_the_title($greenres_prev_post); ?></a></h3>
            <?php endif; ?>
        </div>
        <div class="next-post">
            <?php $greenres_next_post = get_next_post();
            if($greenres_next_post):
            ?>
            <h3 class="post-title"><a href="<?php echo get_the_permalink($greenres_next_post);
                ?>"><?php echo get_the_title($greenres_next_post); ?></a></h3>

            <?php endif; ?>
        </div>
    </div> 
于 2019-05-31T09:50:46.187 回答