获取下一个帖子链接自定义html锚标记

时间:2018-01-29 13:19:24

标签: wordpress

我想使用next_posts_link () Wordpress函数来获取下一页,它给了我一个锚标记,我只想在这个锚标记中添加一个类。 我想在课程page-next和上一页old-page上添加下一页锚标记。

2 个答案:

答案 0 :(得分:0)

您可以对next/previous_post_link();

使用以下功能
<?php
# get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true )
$next_post_obj  = get_adjacent_post( '', '', false );
$next_post_ID   = isset( $next_post_obj->ID ) ? $next_post_obj->ID : '';
$next_post_link     = get_permalink( $next_post_ID );
$next_post_title    = '&raquo;'; // equals "»"
?>
<a href="<?php echo $next_post_link; ?>" rel="next" class="pagination pagination-link pagination-next">
    <?php echo $next_post_title; ?>
</a>

我希望这会奏效。

答案 1 :(得分:0)

这是一个非常简单的解决方案。只需使用此代码在标签中显示您的链接即可。

<?php
global $paged;

    if ( get_previous_posts_link() ) { ?>
        <a href="<?php echo get_pagenum_link( $paged - 1 ); ?>">Prev</a><?php
    }    
    if ( get_next_posts_link() ) { ?>
        <a href="<?php echo get_pagenum_link( $paged +1 ); ?>">Next</a><?php
    }    
?>
相关问题