【问题标题】:Next Previous Post in wordpress下一篇 上一篇在 wordpress 中
【发布时间】:2013-07-18 09:04:26
【问题描述】:

如何在 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>

如果有任何回应,不胜感激。 . .

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    get_next_postget_previous_post 应该可以帮助您。

    【讨论】:

    • 我没有在特定帖子中获得任何内容,原因
    • OK 试试例如:` post_title; ?> `
    【解决方案2】:

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

    希望这会有所帮助!

    【讨论】:

    • 感谢您的回复。使用 get_previous_post 时我没有收到任何内容
    【解决方案3】:
    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;
    }
    

    在post page中,输入这样的字数限制--> echo content(100)。 希望这会对你有所帮助。

    【讨论】:

      【解决方案4】:

      您可以使用以下功能

      下一篇文章链接

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

      上一篇文章的链接

      <?php previous_post_link($format, $link, $in_same_cat = false, $excluded_categories = ''); ?> 
      

      【讨论】:

        【解决方案5】:
        <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> 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-11-14
          • 1970-01-01
          • 2013-03-04
          • 1970-01-01
          • 2018-07-22
          相关资源
          最近更新 更多