从您的父主题中复制single.php页面并将其粘贴到您的Child-theme的目录中。从child-theme目录打开single.php,并在文件末尾添加以下代码[get_footer();之前)。 ]
<?php
$post_id = $post->ID; // Get current post ID
$cat = get_the_category();
$current_cat_id = $cat[0]->cat_ID; // Get current Category ID
$args = array('category'=>$current_cat_id,'orderby'=>'post_date','order'=> 'DESC');
$posts = get_posts($args);
// Get IDs of posts retrieved by get_posts function
$ids = array();
foreach ($posts as $thepost) {
$ids[] = $thepost->ID;
}
// Get and Echo the Previous and Next post link within same Category
$index = array_search($post->ID, $ids);
$prev_post = $ids[$index-1];
$next_post = $ids[$index+1];
?>
<?php if (!empty($prev_post)){ ?> <a class="previous-post" rel="prev" href="<?php echo get_permalink($prev_post) ?>"> <span class="meta-icon"><i class="fa fa-angle-left fa-lg"></i></span> Previous</a> <?php } ?>
<?php if (!empty($next_post)){ ?> <a class="next-post" rel="next" href="<?php echo get_permalink($next_post) ?>">Next <span class="meta-icon"><i class="fa fa-angle-right fa-lg"></i></span> </a> <?php } ?>
添加此代码后,下面的代码粘贴到你的孩子为主题的style.css的样式链接:
a.previous-post, a.next-post {
color: #fff;
background-color: #4498e7;
text-align: center;
height: 34px;
line-height: 34px;
font-size: 14px;
border: 1px solid;
padding: 0 20px;
margin-bottom: 30px;
text-transform: uppercase;
border-radius: 4px;
font-weight: bold;
}
a.previous-post:hover, a.next-post:hover {
color: #4498e7;
background-color: #fff;
}
a.previous-post {
float: left !important;
}
a.next-post {
float: right !important;
}
要看到的这些动作链接,访问我的网站:www.techtutsonline.com
让我知道结果:)
你可能想继续阅读进一步下来,直到你看到这样 <?PHP next_post_link(“%链接”,“下一步POS t','TRUE','13'); ?> – xlordt
嘿@xlordt。我已经尝试了参数TRUE,但它没有帮助。当然,我不确定我是否把它放在正确的地方。 –
你究竟如何尝试这个?你可以用你尝试过的解决方案更新你的文章吗? – xlordt