47 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
virgild says

Hello people! I’ve been playing with Wordpress for 2 weeks now and today I tried to make my very own div id that I can use in page templates. I obviously stumbled into some issues. Here’s what I did.

First I added this code for a new “div id” in the index. It’s to list childpages in the parent page:

<div id="childpages"> &lt;?php if ($post?&gt;post_parent == 0) { $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); $parentpage = $wpdb->get_row("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE ID = '".$post->ID."'"); } if ($post->post_parent != 0) { $next_post_parent = $post->post_parent; while ($next_post_parent != 0) { $children = wp_list_pages("title_li=&child_of=".$next_post_parent."&echo=0"); $parentpage = $wpdb->get_row("SELECT ID, post_title, post_parent, post_name FROM $wpdb->posts WHERE ID = '".$next_post_parent."'"); $next_post_parent = $parentpage->post_parent; } } ?&gt; &lt;?php if ($children) { ?&gt; <ul> <li><h2><a href="&lt;?php echo get_permalink($parentpage->ID); ?&gt;">&lt;?php echo $parentpage?&gt;post_title; ?&gt;</a></h2> <ul> &lt;?php echo $children; ?&gt; </ul> </li> </ul> &lt;?php } ?&gt; </div>

Next I headed to the css and added this in the layout section:

#childpages { float:left; width:270px;

And finally I duplicated the page.php, gave it a page template name added to the bottom, <?php get_childpages(); ?> And chose the template for my “about” page.

And the result is this http://www.graphictask.com/?page_id=2

Fatal error: Call to undefined function get_childpages() in /home/requestg/public_html/graphictask/wp-content/themes/bigfeature/childpage Template.php on line 53

The child pages were supposed to appear in the right there..

Am I doing something TERRIBLY wrong? I really want to learn WP!

707 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says

You are trying to hook into a function that does not exist, You could just use this.

<?php if ($post?>post_parent)
    $children = wp_list_pages("sort_column=menu_order&title_li=&child_of=".$post->post_parent."&echo=0");
    else
    $children = wp_list_pages("sort_column=menu_order&title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?>
    <ul>
        <?php echo $children; ?>
    </ul>
<?php } ?>
47 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
virgild says
You are trying to hook into a function that does not exist, You could just use this.
<?php if ($post?>post_parent)
    $children = wp_list_pages("sort_column=menu_order&title_li=&child_of=".$post->post_parent."&echo=0");
    else
    $children = wp_list_pages("sort_column=menu_order&title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?>
    
    <?php echo $children; ?>
<?php } ?>

Thanks for replying! I’m using that now in a new page layout template.

by
by
by
by
by
by