我使用分页下面的代码,它工作正常,但抛出一个PHP的警告:非法抵消未设置类型(unset($allcategories[$parentc]);)
WordPress的PHP的警告:非法偏移类型在未设置
不要有很多PHP的经验,但你们可以指导我的问题在哪里?提前致谢。
<nav class="navigation post-navigation" role="navigation">
<h1 class="screen-reader-text"><?php _e('Post navigation', 'ci'); ?></h1>
<?php
$allcategories = get_terms(
array('category'), // Taxonomies
array('fields' => 'ids') // Fields
);
$post_categories = wp_get_post_categories($post->ID);
foreach ($post_categories as $pc) {
if(($key = array_search($pc,$allcategories)) !== false) {
unset($allcategories[$key]);
}
$this_category = get_category($pc);
if ($this_category->category_parent != '') {
$parentc = get_category($this_category->category_parent);
unset($allcategories[$parentc]);
}
}
?>
<div class="nav-links">
<div class="nav-next"><?php next_post_link('%link', '%title', FALSE, $allcategories); ?></div>
<div class="nav-previous"><?php previous_post_link('%link', '%title', FALSE, $allcategories); ?></div>
</div>
</nav>
检查你在'$ parentc'中得到了什么? – devpro
WP_Term对象 ( [term_id] => 4 [名称] => DFW地铁 [蛞蝓] =>达拉斯堡垒价值 [term_group] => 0 [term_taxonomy_id] => 4 [分类] = > 类别[描述] => [父] => 0 [数] => 4883 [过滤] =>生 [term_icon] => [CAT_ID] => 4 [category_count] => 4883 [category_description] => [cat_name] => DFW地铁 [category_nicename] =>达拉斯堡值 [category_parent] => 0 ) –
这只是一个对象记录 –