1
我正在幫助朋友對wordpress主題進行一些更改。目前顯示子頁面僅適用於一個父母及其子頁面(ID爲31的子頁面),但我們希望它適用於所有頁面(及其子頁面)。我想或多或少地保留代碼,只需進行必要的更改即可應用於所有代碼。WordPress的PHP:顯示頁面的子代(編輯現有代碼)
雖然我對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子句,但沒有線索要替換它。有什麼建議麼?
在此先感謝! Joanna
謝謝您的回答。我試着簡單地使用wp_list_pages,但我認爲我在模板上的代碼已經添加了更多的數據(例如它告訴哪個孩子是最後一個,所以不會包含正確的邊框),我們需要這些數據。 – Joanna