Title: [Plugin: PHP Code Widget] Listing subpages not working
Last modified: August 19, 2016

---

# [Plugin: PHP Code Widget] Listing subpages not working

 *  Resolved [mike62](https://wordpress.org/support/users/mike62/)
 * (@mike62)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-listing-subpages-not-working/)
 * The following code, when pasted into the template sidebar, works perfectly, but
   doesn’t work when using this plugin.
 *     ```
       <?php
       //show parent page
       $parent_title = get_the_title($post->post_parent);?>
       <a href="<?php echo get_permalink($post->post_parent) ?>" class="parent"><?php echo $parent_title;?></a>
   
       <?php
       //show child pages
         if($post->post_parent)
         $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
         else
         $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
         if ($children) { ?>
         <ul id="subnav">
         <?php echo $children; ?>
         </ul>
         <br clear="all" />
       <?php } ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Author [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-listing-subpages-not-working/#post-1695050)
 * You don’t have $post defined.
 * The contents of the widget do not run in the global context like templates do.
   If you want access to global variables, you have to declare them.
 * In your case, adding `global $post;` to the beginning of your code would probably
   work.

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: PHP Code Widget] Listing subpages not working’ is closed to 
new replies.

 * ![](https://ps.w.org/php-code-widget/assets/icon.svg?rev=992095)
 * [PHP Code Widget](https://wordpress.org/plugins/php-code-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/php-code-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/php-code-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/php-code-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/php-code-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/php-code-widget/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-listing-subpages-not-working/#post-1695050)
 * Status: resolved