Guest User

Untitled

a guest
Jan 26th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?
  2. function getBreadcrumbs( $post, $arr ) {
  3.  
  4.     array_push( $arr, ['title' => $post->post_title, 'id' => $post->ID] );
  5.  
  6.     if ( $post->post_parent !== 0 ) {
  7.         $child_post = $post->post_parent;
  8.  
  9.         return getBreadcrumbs( get_post( $child_post ), $arr );
  10.     }
  11.  
  12.     return array_reverse( $arr );
  13. }
  14.  
  15. ?>
  16.  
  17. <? $breadcrumbs = getBreadcrumbs( $post, [] ); ?>
  18.  
  19. <? foreach ( $breadcrumbs as $index => $breadcrumb ) : ?>
  20.  
  21.     <a href="<?= get_permalink( $breadcrumb['id'] ); ?>">
  22.     <?= $breadcrumb['title']; ?>
  23.         <? if ( $index < count( $breadcrumbs ) - 1 ): ?>
  24.             <span class="o-breadcrumbs__arrow">&raquo;</span>
  25.         <? endif; ?>
  26.     </a>
  27. <? endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment