• Hi, I have WP 3.5 installation with the Genesis framework and WP Types and WP Views installed (to manage CPT as my coding skills are quite basic). I also have the YOAST SEO plugin installed. ALl on a linux vps.

    Now, here is what I want to do.

    I have 3 custom post types:
    – Cities
    – Districts
    – Attractions

    I would like the breadcrumb navigation to display something like:

    HOME > Cities > London (Overview of the city)
    HOME > Cities > London > District1 (one of the districts)
    HOME > Cities > London > Big Ben (one of the attractions)

    I have tried Breadcrumb NavXT and various other plugins (i.e. CPT-onomies: Using Custom Post Types as Taxonomies), but I believe my core problem is that different CPT cannot be children or parent to each other, is that correct?

    I can make a CPT hierarchical, but that just refers it to another post within the same CPT, not other CPTs.

    At this point in time, my head is in pain and I can’t seem to see light at the end of the tunnel.

    I am not very experienced with custom functions in the functions.php, but if there is an easy way to do this, I can call PHP code with the hooks in the Genesis framework quite easily, so that shouldn’t be a problem.

    Anyway, if you want to see for yourself, the site is: http://www.xhotels.net

    Thanks for your thoughts, if I get to a solution, I’ll make sure to post it here as I’ve seen loads of forum posts without one.

    Cheers!

Viewing 8 replies - 1 through 8 (of 8 total)
  • didnt try this personally but still give it a shot..
    dump this in functions.php:

    function mybreadcrumbs()
    {
    global $wp_query;
    echo '<ul>';
    $post = $wp_query->get_queried_object();
    if ( $post->post_parent == 0 ){
    echo "<li>  ".the_title('','', FALSE)."</li>";
    } else {
    $title = the_title('','', FALSE);
    $ancestors = array_reverse( get_post_ancestors( $post->ID ) );
    array_push($ancestors, $post->ID);
    foreach ( $ancestors as $ancestor ){
    if( $ancestor != end($ancestors) ){
    echo '<li>  <a href="'. get_permalink($ancestor) .'">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a></li>';
    } else {
    echo '<li>  '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</li>';
    }
    }
    }
    echo "</ul>";

    and call mybreadcrumbs(); where you want it displayed.
    let know if it works..

    Thread Starter titush

    (@titush)

    Hi and thanks for your help. Unfortunately, when pasting the code in, my site breaks (blank page). Is there maybe a syntax error?
    I am not an expert in PHP..

    Thanks, T.

    i think i missed the closing braces in the function:

    function mybreadcrumbs()
    {
    	global $wp_query;
    	echo '<ul>';
    	$post = $wp_query->get_queried_object();
    	if ( $post->post_parent == 0 ){
    		echo "<li>  ".the_title('','', FALSE)."</li>";
    	} else {
    		$title = the_title('','', FALSE);
    		$ancestors = array_reverse( get_post_ancestors( $post->ID ) );
    		array_push($ancestors, $post->ID);
    		foreach ( $ancestors as $ancestor ){
    			if( $ancestor != end($ancestors) ){
    				echo '<li>  <a href="'. get_permalink($ancestor) .'">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a></li>';
    			} else {
    				echo '<li>  '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</li>';
    			}
    		}
    	}
    	echo "</ul>";
    }

    and call function by:
    <?php mybreadcrumbs(); ?>

    Thread Starter titush

    (@titush)

    HI there and thanks for re-posting this.
    Unfortunately it doesn’t work, it just displays the name of the article.

    For example: http://www.xhotels.net/attraction/syntagma-square

    Any other thoughts? The attractions and districts are flagged as hierarchical and the city information is the parent…

    Thanks a lot!

    What about making attractions and districts custom taxonomies of your cpt cities?

    Thread Starter titush

    (@titush)

    That was my contingency plan 😉 The reason I don’t want to do that is because the text blocks of the CPTs are arranged with custom fields.

    So for example, there are custom fields for:

    – Introduction
    – How to get to the destination
    – The history

    etc.

    I did that so that I can re-arrange the order of these text blocks at a later stage. However, this creates the problem that I actually need the different CPT.

    There is one more option:

    creating a single CPT with ALL the custom fields of all the CPT so that there is one massive CPT containing all the text.

    I use WP Views (http://wp-types.com/) – which by the way is the coolest invention since sliced bread – so what I could do is create a custom view template for the city information and the subordinate pieces like attractions and districts.

    I’ve been struggling with this as I was too lazy to tackle this and first wanted to see if there really is no way to have CPT relate to each other such as categories and subcategories…

    Thanks for the thought though, if all goes sour, that’s precisely what I will do.

    Instead of using custom fields could you make your own meta boxes and save the data that way instead?

    Thread Starter titush

    (@titush)

    I think I might have found a solution. Basically what I did it to create a custom taxonomy (just like categories). Then, in BreadCumb Nax XT, I have set the taxonomy to be the criteria for the navigation trail.

    this way all content is ordered perfectly. However, I do need to reformat the taxonomy “archive” view, as it looks ugly.

    But it’s a step into the right direction…

    I’ll keep you posted and provide an update, as I am sure this can come in hand to others as well.

    cheers!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom Post Type Hierarchies and Breadcrumbs’ is closed to new replies.