我正在帮助一个朋友对 wordpress 主题进行一些更改。目前显示子页面仅适用于一个父页面及其子页面(id 为 31 的那个),但我们希望它适用于所有页面(及其子页面)。我想或多或少地保持代码不变,只需进行必要的更改以应用于所有人。
虽然我很擅长 css 和 html,但 php 并不是我真正的强项,所以如果你能帮助我解决这个问题,我将不胜感激。这是现有的代码:
$currentPageId = get_the_ID();
$pages = get_pages('child_of=31');
$i=0;
foreach($pages as $child) {
$childrenPageID[$i] = $child->ID;
$i++;
}
if ( (get_the_ID() == 31) || ( in_array($currentPageId, $childrenPageID)) ) {
$taxonomy = 'portfoliocat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$child_of = 5;
$show_count = 1;
$title_li = null;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'child_of' => $child_of,
'show_count' => $show_count,
'title_li' => $title_li
);
?>
<div style="overflow:auto; margin-bottom:20px;">
<ul style="list-style-type:none; margin-left: 0px;">
<?php
$cat = get_query_var('cat');
// count all categories
$totalCount = count(get_categories($args));
$currentCount = 0;
foreach(get_categories($args) as $category) {
// get current number of stack
$currentCount = $currentCount + 1;
global $wpdb;
$lookForValue = $category->slug;
$querystr = "SELECT post_id
FROM $wpdb->postmeta
WHERE meta_key = 'category-include' AND meta_value = '".$lookForValue."';
";
$postid = $wpdb->get_var($wpdb->prepare($querystr));
// logic to remove last trunk
if ($totalCount != $currentCount ) {
echo '<li class="cat-item"><a class="name" style="font-weight:bold" href="/?page_id='.$postid.'">' . $category->name.'</a> <span style="color: #999;">|</span> </li>';
}
else {
echo '<li class="cat-item"><a class="name" style="font-weight:bold" href="/?page_id='.$postid.'">' . $category->name.'</a></li>';
}
}?>
</ul>
</div>
}
我猜我需要更改 if 子句,但不知道用什么替换它。有什么建议么?
提前致谢!乔安娜