ThemeShaper Forums » Thematic

[closed]

Adding subpages after the post content

(12 posts)
  • Started 4 years ago by talino
  • Latest reply from lqunta
  • This topic is resolved
  1. Hi all. Newbie here, learning child theming, loving it, totally confused.

    I would like to do the following: whenever a page is selected in the main menu, I would like to list its subpages, if there are any, right below the main page content, before anything else.

    Here's what I added to my child theme's function.php which, obviously, didn't work:

    function metra_subpages($content) {
    	global $post;
    	$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    	if ($children) { ?>
    
    <ul>
    	<?php echo $children; ?>
    	</ul>
        <?php }
    	print $content;
    }
    add_filter('the_content', 'metra_subpages');

    I've looked through the framework looking for the right filter to add but couldn't find it. I'm new to filtering and such but I've read most of the tutorials on the Thematic site. I've even managed to add a couple of working filters to my functions.php. But for the life of me I can't figure out how to do the above.

    Thanks for any help.

    Posted 4 years ago #
  2. Hi,

    to filter something means to change the content of a variable. If you stay with your filter you add your content ($children) to $content.

    Easier:

    function single_subpages() {
      $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
      if ($children) { ?>
    
        <ul>
    	<?php echo $children; ?>
        </ul>
      <?php }
    }
    add_action('thematic_singlepost', 'single_subpages');

    Cheers,

    Chris

    Posted 4 years ago #
  3. Thanks for your reply. This doesn't seems to work, however, when using pages (not posts). I tried something simpler:


    function single_subpages() {
    echo 'test';
    }
    add_action('thematic_singlepost', 'single_subpages');

    And I didn't get anything. I've looked all over the framework for a function that displays pages, not posts, but couldn't find anything. It seems everything is handled by thematic_singlepost. I don't know what could be the problem.

    Thanks, though, for clearing up for me the differences between actions and filters. I'm just beginning to grasp the power behind all this and I'm never going back to modifying core files again :)

    Posted 4 years ago #
  4. Apparently there is no Thematic hook in the page.php template. What I did was this, and it works like I want it to. Since I'm a total newbie with this kind of stuff, I'd appreciate it if someone told me there was a simpler way to do it.

    The following goes into my child theme's function.php :

    function my_subpages($content) {
    	global $post;
    	$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
      	if ($children) {
        	$content .= '<ul class="sub_pages">' . $children . '</ul>';
    	}
    	return $content;
    }
    add_filter('the_content', 'my_subpages');

    (There doesn't seem to be an action hook for the_content).

    Posted 4 years ago #
  5. Sorry .. my fault .. mixed up pages and posts.

    Need to integrate the action hook into pages.php .. will be available in the next days via SVN.

    .. and .. currently there's no other way to solve this.

    Cheers,

    Chris

    Posted 4 years ago #
  6. No sweat. I'm just discovering the child-theming concepts and it's already pretty powerful as it is...

    I started another hook-related question/suggestion thread, concerning the_excerpt.

    Thanks a lot for your help.

    Posted 4 years ago #
  7. Hello,

    This is exactly what I need. I am totally new to php. I added this

    function my_subpages($content) {
    global $post;
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) {
    $content .= '<ul class="sub_pages">' . $children . '';
    }
    return $content;
    }
    add_filter('the_content', 'my_subpages');

    to my functions.php. Now what do I need to add to my page template for it to show? I tried <?php my_subpages($content) ?>, but it doesn't do anything (again, new to php).

    Thanks for any help!

    Posted 4 years ago #
  8. Update: I put <?php my_subpages() ?> into my template page, but I got this error message:

    Warning: Missing argument 1 for my_subpages() in /homepages/33/d278181988/htdocs/www/blog/wp-content/themes/earlymorning/functions.php on line 329

    As I was working on something else, all of a sudden it worked. But then it went back to the error message. I was working on the css only, so I don't understand why the error message came and went, and then came back.

    HELP

    Posted 4 years ago #
  9. Hi,

    you can't put a filter call into your template. Remove it and the error will be gone.

    Chris

    Posted 4 years ago #
  10. Thanks!

    I have a couple more questions, this is still the code in my functions.php:

    function my_subpages($content) {
    global $post;
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) {
    $content .= '<ul id="sub_pages">' . $children . '';
    }
    return $content;
    }
    add_filter('the_content', 'my_subpages');

    1. The list of subpages are displayed in the parent page, but not the child pages themselves. Is there a way to get them to display in both?

    2. How do I get them to appear above the content? (right now they are below)

    Any help is greatly greatly appreciated.

    Posted 4 years ago #
  11. lqunta
    Member

    @all, @Chris

    I'm a newbie, and greatful to have come accross this topic. I'm now one step closer.

    Just to add onto the above questions [guys, great code...it works!], how can one list sub-pages in the following manner:
    -Title of the page : Brief Excerpt [The title, not the excerpt, being clickable].

    Thanks
    LQunta

    Posted 4 years ago #
  12. lqunta
    Member

    Greetings All, @Chris,

    Still having trouble customizing the 'loop' [if I may be allowed to call it so] on the home page. Possibly, to give a much more 'visual' example, have a look at the following page - http://justintadlock.com/tags/wordpress-plugins - the way the 'content' is listed.

    I'm trying to achieve that, but, I'm lost in tons, and turns of code!

    Cheers

    LQunta - trying to make sense of it all....

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.