簡體   English   中英

wordpress中的下一個上一篇文章

[英]Next Previous Post in wordpress

如何在wordpress的下一篇文章中顯示內容。 例如。 對於下一個標題的帖子鏈接是否存在,是否可以顯示該帖子的內容(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>

非常感謝,如果有任何回應。

get_next_postget_previous_post可以幫到你。

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

如果它在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;
}

希望這可以幫助!

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

在帖子頁面中,輸入單詞limit這樣 - > echo content(100)。 希望這會幫助你。

您可以使用以下功能

對於下一個帖子鏈接

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

對於以前的帖子鏈接

<?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