更改下一个/上一个链接以显示帖子标题



所以我目前正在我的个人网站上工作,并开始使用时间线。帖子中有下一个/上一个按钮,但我希望它们显示帖子标题而不是下一个/上一个。我已经查看了wordpress代码,但是开发人员正在使用非标准代码来实现它。

有人可以看看代码并告诉我我需要更改什么。

谢谢!

 <div class="clearfix"></div>
            </div>
            <div class="timeline-info">
                <div class="timeline-content">
                    <?php 
                    $content =  preg_replace ('#<embed(.*?)>(.*)#is', ' ', get_the_content(),1);
                    $content =  preg_replace ('@<iframe[^>]*?>.*?</iframe>@siu', ' ', $content,1);
                    $content =  preg_replace ('/<sources+(.+?)>/i', ' ', $content,1);
                    $content =  preg_replace ('/<object(.*)</object>/is', ' ', $content,1);
                    $content =  preg_replace ('#[videos*.*?]#s', ' ', $content,1);
                    $content =  preg_replace ('#[audios*.*?]#s', ' ', $content,1);
                    $content =  preg_replace ('#[/audio]#s', ' ', $content,1);
                    preg_match_all('#bhttps?://[^s()<>]+(?:([wd]+)|([^[:punct:]s]|/))#', $content, $match);
                    foreach ($match[0] as $amatch) {
                        if(strpos($amatch,'soundcloud.com') !== false){
                            $content = str_replace($amatch, '', $content);
                        }elseif(strpos($amatch,'youtube.com') !== false){
                            $content = str_replace($amatch, '', $content);
                        }
                    }
                    $content = preg_replace('%<object.+?</object>%is', '', $content,1);
                    echo apply_filters('the_content',$content);?>
                </div>
            </div>
            <?php 
            $we_sevent_navi = get_option('wpex_navi');
            if($we_sevent_navi!='no'){
                $wpex_navi_order = get_option('wpex_navi_order');
                $preevtrsl = get_option('wpex_text_prev')!='' ? get_option('wpex_text_prev') : esc_html__('Previous article','wp-timeline');
                $nextevtrsl = get_option('wpex_text_next')!='' ? get_option('wpex_text_next') : esc_html__('Next article','wp-timeline');
                if($wpex_navi_order!='ct_order'){ ?>
                    <div class="timeline-navigation defa">
                        <div class="next-timeline">
                            <?php next_post_link('%link', $nextevtrsl) ?>
                        </div>
                        <div class="previous-timeline">
                            <?php previous_post_link('%link', $preevtrsl) ?>
                        </div>
                    </div>
                    <?php 
                }else{
                    wpex_next_previous_timeline($preevtrsl,$nextevtrsl);
                }
            }?>
            <div class="clearfix"></div>
        </div>
    </div>

您可以使用WordPress默认函数来获取下一个和上一个带有永久链接的帖子标题,如下所示:

    <?php  // FOR PREVIOUS POST
        $prev_post = get_previous_post(); 
        $id = $prev_post->ID ;
        $permalink = get_permalink( $id );
    ?>
    <?php // FOR NEXT POST
        $next_post = get_next_post();
        $nid = $next_post->ID ;
        $permalink = get_permalink($nid);
    ?>

然后只需在 HTML 结构中使用此变量,如下所示:

<div class="next-timeline">
     <?php next_post_link( '%link', __( 'Next <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
     <h2><a href="<?php echo $permalink; ?>"><?php echo $next_post->post_title; ?></a></h2>
</div>
<div class="previous-timeline">
     <?php previous_post_link( '%link', __( '<span class="meta-nav">&larr;</span> Previous', 'twentyeleven' ) ); ?> 
     <h2><a href="<?php echo $permalink; ?>"><?php echo $prev_post->post_title; ?></a></h2>                           
</div>

希望这对你有用。

谢谢。

只需删除括号内的代码

<div class="timeline-navigation defa">
                        <div class="next-timeline">
                            <?php next_post_link(); ?>
                        </div>
                        <div class="previous-timeline">
                            <?php previous_post_link(); ?>
                        </div>
</div>

下面是示例:https://wordpress.stackexchange.com/questions/77166/switch-form-next-previous-to-post-title

<nav id="nav-single">
    <h3 class="assistive-text"><?php _e( 'Post navigation', 'admired' ); ?></h3>
    <span class="nav-previous"><?php previous_post_link(); ?></span>
    <span class="nav-next"><?php next_post_link(); ?></span>
</nav><!-- #nav-single -->

打开你的单曲.php比如 ENIF 和 end 之间的二十个十五主题,同时编写下面的代码

// Previous/next post navigation.
            the_post_navigation( array(
                'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( '', 'twentyfifteen' ) . '</span> ' .
                    '<span class="screen-reader-text">' . __( 'Next post:', 'twentyfifteen' ) . '</span> ' .
                    '<span class="post-title">%title</span>',
                'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( '', 'twentyfifteen' ) . '</span> ' .
                    '<span class="screen-reader-text">' . __( 'Previous post:', 'twentyfifteen' ) . '</span> ' .
                    '<span class="post-title">%title</span>',
            ) );
        // End the loop.

最新更新