简体   繁体   English

wordpress中的下一个上一篇文章

[英]Next Previous Post in wordpress

How can i show the content in next previous post of wordpress. 如何在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). 对于下一个标题的帖子链接是否存在,是否可以显示该帖子的内容(100字)。

       <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. 非常感谢,如果有任何回应。 . .

get_next_postget_previous_post可以帮到你。

If it's within The Loop, you can use the_excerpt() or get_the_excerpt() depending on your requirements. 如果它在The Loop中,您可以根据您的要求使用the_excerpt()get_the_excerpt()

If it's outside The Loop, you can use a function like this to get the post excerpt by the post ID: 如果它在The Loop之外,您可以使用这样的函数来获取帖子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;
}

Hope this helps! 希望这可以帮助!

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;
}

In post page , enter the words limit like this--> echo content(100). 在帖子页面中,输入单词limit这样 - > echo content(100)。 Hope this will help you. 希望这会帮助你。

You can use following functions 您可以使用以下功能

For next post link 对于下一个帖子链接

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

For previous post link 对于以前的帖子链接

<?php previous_post_link($format, $link, $in_same_cat = false, $excluded_categories = ''); ?> 
<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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM