开发者

How can I echo previous and next page link names in WordPress?

I am using this wonderful bit of code created by jackreichert.

This in the functions.php file.

function siblings($link) {
    global $post;
    $siblings = get_pages('child_of='.$post->post_parent.'&parent='.$post->post_parent);
    foreach ($siblings as $key=>$sib开发者_运维技巧ling){
        if ($post->ID == $sibling->ID){
            $ID = $key;
        }
    }
    $closest = array('before'=>get_permalink($siblings[$ID-1]->ID),'after'=>get_permalink($siblings[$ID+1]->ID));

    if ($link == 'before' || $link == 'after') {
        echo $closest[$link];
    }
    else
    {
        return $closest;
    }
}

and this on the template page

<?php siblings('before'); ?>

and

<?php siblings('after'); ?>

It works wonderfully, but to the echo I would like to be able to add the name of the link as well. How could this be done?


Change this line:

$closest = array('before'=>get_permalink($siblings[$ID-1]->ID),'after'=>get_permalink($siblings[$ID+1]->ID));

To:

$closest = array('before'=> '<a href="'.get_permalink($siblings[$ID-1]->ID).'">'.get_the_title($siblings[$ID-1]->ID).'</a>','after'=> '<a href="'.get_permalink($siblings[$ID+1]->ID).'">'.get_the_title($siblings[$ID+1]->ID).'</a>');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜