Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Forum: Plugins
    In reply to: Get Parent Pages
    Thread Starter spiralstarez

    (@spiralstarez)

    I’ve been looking into the code in the breadcrumb plugin to examine how this would be possible. This code obviously is able to retrieve the parent pages, and I imagine it’s just a matter of retrieving all the pages that don’t have children in the site and stuffing them into an array called $parents. I’m not sure how to translate what is here into what I am after yet though, but for anyone else wanting similar functionality I think this would be a good starting point.

    function get_breadcrumb_page($breadcrumb, $params)
    {
      global $wp_query;
    
      if ($wp_query->is_page)
      {
        $object = $wp_query->get_queried_object();
    
        // Parents.
        $parent_id  = $object->post_parent;
        $parents    = array();
        while ($parent_id)
        {
          $page       = get_page($parent_id);
    
          if ($params["link_none"])
            $parents[]  = get_the_title($page->ID);
          else
            $parents[]  = '<a href="'.get_permalink($page->ID).'" title="'.get_the_title($page->ID).'">'.get_the_title($page->ID).'</a>';
    
          $parent_id  = $page->post_parent;
        }
    
        // Parents are in reverse order.
        $parents    = array_reverse($parents);
        $breadcrumb = array_merge($breadcrumb, $parents);
    
        // Current page.
        if ((breadcrumb_is_paged() || $params["link_all"]) && !$params["link_none"])
          $breadcrumb[] = '<a href="'.get_permalink($object->ID).'" title="'.get_the_title($object->ID).'">'.get_the_title($object->ID).'</a>';
        else
          $breadcrumb[] = get_the_title($object->ID);
      }
    
      return $breadcrumb;
    }
    Forum: Plugins
    In reply to: Get Parent Pages
    Thread Starter spiralstarez

    (@spiralstarez)

    thanks, that sounds like it works on a per page basis, however I’m looking to have something like this:

    home
    about
    – about1
    — about1.1
    — about1.2
    — about 1.2.1
    — about 1.2.2
    contact

    so on the about page, If I’m in 1.2.1 or 1.1 or any of the pages under the parent ‘about’ page, I want to show one header image for the parent and all its children.

    I’ve seen in some code that uses a while loop to check each $page if it has_parent or something like that, and get it into an array. That seems like a good option to achieve this, however my PHP and wordpress knowledge aren’t good enough yet to achieve it.

    Ultimately I think I’m just going to choose 7 images or so and use PHP random to switch them as it’s not imperative that they are specific to a page though it would be nice for future projects to know how to do it.

Viewing 2 replies - 1 through 2 (of 2 total)