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

时间:2017-05-16 10:32:18

标签: wordpress

所以我目前正在开发个人网站,并开始使用时间表。帖子中有下一个/上一个按钮,但我希​​望它们显示帖子标题而不是下一个/上一个。我已经查看了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 ('/<source\s+(.+?)>/i', ' ', $content,1);
                    $content =  preg_replace ('/\<object(.*)\<\/object\>/is', ' ', $content,1);
                    $content =  preg_replace ('#\[video\s*.*?\]#s', ' ', $content,1);
                    $content =  preg_replace ('#\[audio\s*.*?\]#s', ' ', $content,1);
                    $content =  preg_replace ('#\[/audio]#s', ' ', $content,1);
                    preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[: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>

2 个答案:

答案 0 :(得分:0)

只需删除括号内的代码

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

在enif和end之间打开你的single.php就像二十五个主题,同时写下代码

// 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.

答案 1 :(得分:0)

您可以使用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>

希望这对你有用。

感谢。