你的代码问题是你只能得到帖子的第一个类别,因为$cat[0]
是第一个,不是当前的。
回路内部:
<?php
previous_post_link( // prints the formatted link
\'<span>« %link</span>\', // beautifying around
\'Prev in this cat\', // the text (%link) to be used in the span above
true, // confirm that you want only this category
\'\', // no categories to exclude
\'category\' // taxonomy name
);
echo " | "; // just a separator between next and prev
/* The same setup here, not shown to keep the answer clean */
next_post_link();
请参见
previous_post_link() 用于参数。
如果您在循环之外,请告诉我,我将更新答案并提供其他代码和注释。