從您的父主題中複製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