Create parent and children page in Wordpress with BreadCrumb

 First go to dashboard create to pages Our History and Our Goal with dummy content and also from sidebar menu select Page attribute parent About us for these pages and publish.

Now we make breadcrumb box dynamic so follow along

I want display current page title in page.php metabox so add below code ->

 <p>
      <a class="metabox__blog-home-link" href="#"><i class="fa fa-home" aria-hidden="true"></i> Back to About Us</a>
      <span class="metabox__main"><?php the_title()  ?></span>
    </p>

and save.

Now we want to display breadcrumb in only child pages so follow below code ->

for this we use in get_the_ID() function which return the post page Id and wp_get_post_parent_id() which will check get_the_ID() function return id have parent or not if parent have return Parent ID  if not return 0

Now to test lest create another child page in Privacy Policy -> Cookie Policy

and check page you will see static title for that parent page so follow below code change metabox code like below ->

 <?php
   $theParent = wp_get_post_parent_id(get_the_ID());
  if($theParent) { ?>
  <div class="metabox metabox--position-up metabox--with-home-link">
    <p>
      <a class="metabox__blog-home-link" href="<?php echo get_the_permalink($theParent) ?>"><i class="fa fa-home"
          aria-hidden="true"></i> Back to
        <?php echo get_the_title($theParent);  ?></a>
      <span class="metabox__main"><?php the_title()  ?></span>
    </p>
  </div>

  <?php  }  ?>

and save..

Comments

Popular posts from this blog

Basics Of PHP

Creating App.js for Node Application

WordPress Full Guide For Developer