Pages

Wednesday, September 12, 2012

Redirect partent page to the first child page in wordpress.

if you want to redirect a Parent page to his first child page then follow the post.
01. take a php file "redirect.php" in this path folder : "wp-content/themes/[your theme folder].
02. put the code below:
<?php
/* Template Name: Redirect To First Child */
  if (have_posts()) {
    while (have_posts()) {
       the_post();
       $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
       $firstchild = $pagekids[0];
       wp_redirect(get_permalink($firstchild->ID));
    }
  } 
?>
03. go to you dashboard and Pages >> Add New you can see the option in template of Page Attributes section. Select the template to Redirect the page.