Wordpress:previous_post_link()位于div之后,在div“entry-content”之后,无论我放在哪里

时间:2013-12-23 06:45:56

标签: wordpress-theming wordpress

我安装了一个自定义帖子类型的插件,我正在尝试使用previous_post_link()next_post_link()来获取上一篇和下一篇文章。

它工作正常,但唯一的问题是我将它放在我的第4个div容器中,因为它始终位于div "entry-content"之后的页面顶部。

这是一个已知问题吗?

这是一段代码:

function some_function () {

global $post;

    if ('team' == get_post_type() && is_single() && in_the_loop()) {
        $fields = WPMTPv2_OPTIONS()->fields;
        $meta = WPMTPv2_FIELDS($post->ID);

        $tmp = '<div id="wpmtp-single-wrap">';
        $tmp .= '<div class="wpmtp-vcard">';
        $tmp .= '<div class="wpmtp-vcard-left">';

        $tmp .= wpmtpv2_featured_img($post->ID);

        $previous   = previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');
        $next       = next_post_link('%link', '<div class="wpmtp-goback">go back</div>');
//        $tmp .= '<a href=""><div class="wpmtp-goback">go back</div></a>';
//        $tmp .= '<a href=""><div class="wpmtp-gonext">view next</div></a>';

        $tmp .= $previous;
        $tmp .= $next;

        $tmp .= '</div>';

...........
..........
..........
........

return $tmp;

}

如果我放置注释的html代码或上一个和下一个函数,它可以正常工作。这意味着html和css是正确的,问题在于我猜的功能。

这是我在用firebug检查后​​得到的结果:

<article .....>
<h2 .....></h2>
<div class="meta"></div>
    <div class="entry-content">

        <a href="link to next" rel="prev">
                    <div class="wpmtp-gonext">view next</div>
                </a>
    <a href="link to previous" rel="next">
        <div class="wpmtp-goback">go back</div>
    </a>
    <div id="wpmtp-single-wrap">
        <div class="wpmtp-vcard">
            <div class="wpmtp-vcard-left">
.....
....
....
....

1 个答案:

答案 0 :(得分:3)

试试这段代码:

    <?php
    function some_function () {

    global $post;

        if ('team' == get_post_type() && is_single() && in_the_loop()) {
            $fields = WPMTPv2_OPTIONS()->fields;
            $meta = WPMTPv2_FIELDS($post->ID);
    ?>
            <div id="wpmtp-single-wrap">
               <div class="wpmtp-vcard">
                  <div class="wpmtp-vcard-left">
                     <?php echo wpmtpv2_featured_img($post->ID); ?>
                     <div class="wpmtp-goback"><?php previous_post_link( '%link', __( ' go back', 'twentyeleven' ),TRUE ); ?></div>
                     <div class="wpmtp-gonext"><?php next_post_link( '%link', __( 'view next', 'twentyeleven' ),TRUE ); ?></div>
                         <?php      
                         // replace **twentyeleven** with your theme name
                         //or try with this line
                         //previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');   
                         //next_post_link('%link', '<div class="wpmtp-goback">go back</div>');                       
                        ?>               
            </div>
    <?php        
    .........
    .........
    ........

    return $tmp;

    }

或最好试试这个插件:wp-pagenavi

此插件提供了wp_pagenavi()模板标记,可生成精美的分页链接。

感谢