Reputation: 91
I've downloaded a couple of plugins already, but none satisfy what I need: I need a widget to display the child pages of a specific parent page (and to customize it via CSS to include an icon on each 'li' and a certain background-color, borders.). I've also downloaded a plugin which enabled me to add categories to each page, thinking that then I could use a widget that displays specific pages titles from a determined category (and in that way solve the issue), but I haven't found one to do so.
Should I edit the default pages widget (which actually lets me sort via page ID, Page Title and Page order), to enable it to also sort by pages from a speficic category? I don't know much PHP to do so.
I though of using the default page widget and exclude every page ID but the ones I need to appear, but then when some other person makes a new page, it will be displayed by the widget, and that should not happen as only the child themes of a specific parent page should be displayed.
Upvotes: 0
Views: 1606
Reputation: 91
This is the way to do it....taken from Wordpress Codex...
<?php
$ancestor_id=12;
$descendants = get_pages(array('child_of' => $ancestor_id));
$incl = "";
foreach ($descendants as $page) {
if (($page->post_parent == $ancestor_id) ||
($page->post_parent == $post->post_parent) ||
($page->post_parent == $post->ID))
{
$incl .= $page->ID . ",";
}
}?>
<ul>
<?php wp_list_pages(array("child_of" => $ancestor_id, "include" => $incl, "link_before" => "", "title_li" => "", "sort_column" => "menu_order"));?>
</ul>
Upvotes: 1