WordPress.org

Ready to get started?Download WordPress

Forums

template: just show child uri's (3 posts)

  1. tdskate
    Member
    Posted 6 years ago #

    <?php
    /*
    Template Name: Just Show Child URL's
    */
    
    $page_children = get_page_children($post->ID, '');
    
    if (!empty($page_children)) {
    	foreach ($page_children as $child) {
    		echo $child->guid . "\n";
    	}
    }
    ?>

    Why won't this work ??
    If i put in a wp_list_pages, it works ...

    <?php
    /*
    Template Name: Just Show Child URL's
    */
    
    wp_list_pages();
    
    $page_children = get_page_children($post->ID, '');
    
    if (!empty($page_children)) {
    	foreach ($page_children as $child) {
    		echo $child->guid . "\n";
    	}
    }
    ?>

    Help :-(

  2. MichaelH
    Member
    Posted 6 years ago #

    Didn't test to see what your code actually outputs, but wouldn't you have to echo the $child->guid wrapped in an <a href= type tag?

  3. tdskate
    Member
    Posted 6 years ago #

    Well no,
    Here's what i really wanted to achieve:

    <?php
    /*
    Template Name: Redirect to Random Sub
    */
    
    get_pages();
    $page_children = get_page_children($post->ID, '');
    $children_count = count($page_children)-1;
    $random_child = rand(0, $children_count);
    $randum_url = ($page_children[$random_child]->guid);
    
    echo header("Location: $randum_url");
    
    ?>

    This is a template that randomly redirects the user to one of the child pages of a parent page. I needed the child url's in an array and it worked by triggering get_pages();

Topic Closed

This topic has been closed to new replies.

About this Topic