Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author scribu

    (@scribu)

    First of all, WordPress does not have a function for generating breadcrumbs at all. So, whatever breadcrumbs you have now, they are generated by the theme or by some plugin.

    Second of all, in your example:

    Home > Region > Country > Events > Future Events > Event Name

    what are each of those components? Pages? Custom posts? Taxonomy terms?

    Thread Starter Gianfranco

    (@gian-ava)

    I am actually using Breadcrumb NavXT plugin to generate the Breadcrumb.

    Region, Country, Events, Future Events: are Pages.
    Event Name: is Custom Post Type.

    The problem is that when you are on the “Future Events” page and click on an event, you end up having this Breadcrumb:
    Home > Event Name

    So, you loose the hierarchy, because the Custom Post Type is not connected to a given page.

    Plugin Author scribu

    (@scribu)

    Well, yeah, to generate breadcrumbs like that you would need to have the event connected to the page somehow, which you can do easily with P2P.

    But beyond that, it’s up to you to use that connection to fetch the page and then it’s ancestor pages.

    I personally use the Breadcrumb Trail plugin. I’ve found it to be pretty easy to extend, since it provides filters.

    Thread Starter Gianfranco

    (@gian-ava)

    I’ll try the Breadcrumb Trail plugin, but I doubt it will be able to assign a trail automatically, because for WordPress the Custom Types are not a nested element.

    Having a Breadcrumb that “stops” where Custom Types begin, is really killing.

    I wonder how the tons of developers do, or justify the lack of this basic functionality to clients who just want a Breadcrumb all along their website (go tell them “Hmm… WordPress, you know, doesn’t handle this, because a Custom Post Type is not a Page”, and see the reaction…). ??

    Maybe I’ll try to get around it using the P2P plugin for the “Custom Type” Single template, telling the client he needs to create a connection in the backend (select a page). Only thing, I am not a PHP master, so I am wondering if you can easily provide such a code to generate the connection and the Breadcrumb for the “single-event.php” template.

    Thanks anyway, Scribu.

    Plugin Author scribu

    (@scribu)

    Well, you have to ask yourself: how do the events get on the “Future Events” page in the first place? Maybe you could automatically create that P2P connection when the event is created.

    As for the template, it would go something like this:

    $q = new WP_Query( array(
      'connected_type' => 'YOUR_CONNECTION_TYPE',
      'connected_items' => get_queried_object()
    ) );
    
    $child_page_id = $q->posts[0]->ID;
    
    $parent_pages = get_ancestors( $child_page_id, 'page' );

    Note that this has not been tested.

    Now, all you have to do is generate links using those page ids you found and add them to the breadcrumb.

    That’s about as specific as I can get, I’m afraid. Good luck!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Posts 2 Posts] Can P2P be used to create a Breadcrumb?’ is closed to new replies.