2
我是一個新手,並有一塊Wordpress代碼,它有一個小故障。Array Splice不保留「trail_end」
對不起,如果我的問題很愚蠢,雖然從我購買主題的支持似乎迴應了很大的延遲。
我會粘貼它,也許有人可以幫忙。如果沒有人能夠找出問題,我會刪除這個問題。
該代碼在我的site上添加了對麪包屑導航的一些更改。
我覺得這個問題是這樣的:
// Add the trail back on to the end.
$links[] = $trail['trail_end'];
// Add the new links, and the original trail's end, back into the trail.
array_splice($trail, 1, count($trail) - 1, $links);
這兩行代碼應該添加一個<span class="trail-end"></span>
圍繞詞「XPAND的Xtreme泵」(麪包屑結束我的鏈接例如)
下面是代碼:
function woo_custom_breadcrumbs_trail_add_product_categories ($trail) {
if ((get_post_type() == 'product') && is_singular()) {
global $post;
$taxonomy = 'product_cat';
$terms = get_the_terms($post->ID, $taxonomy);
$links = array();
if ($terms && ! is_wp_error($terms)) {
foreach ($terms as $c) {
$parents = woo_get_term_parents($c->term_id, $taxonomy, true, ', ', $c->name, array());
if ($parents != '' && ! is_wp_error($parents)) {
$parents_arr = explode(', ', $parents);
foreach ($parents_arr as $p) {
if ($p != '') { $links[] = $p; }
}
}
}
// Add the trail back on to the end.
$links[] = $trail['trail_end'];
// Add the new links, and the original trail's end, back into the trail.
array_splice($trail, 1, count($trail) - 1, $links);
}
}
return $trail;
} // End woo_custom_breadcrumbs_trail_add_product_categories()
您可以在'$ links [] ='命令之前執行'var_dump($ trail)'嗎? – 2012-01-31 18:16:37
這是var_dup:array(3){[0] => string(150)「Home」[1] => string(72)「Products」[「trail_end」] => string(17)「的輸出Elite Mass Gainer「} – webmasters 2012-01-31 18:31:13
您可以在'$ links []'之前執行'var_dump($ links)'嗎? – 2012-01-31 18:50:54