• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Including the Parent/Child Custom Post Relationship in Breadcrumbs – Genesis

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Including the Parent/Child Custom Post Relationship in Breadcrumbs – Genesis

This topic is: resolved

Tagged: breadcrumb, CPT

  • This topic has 5 replies, 4 voices, and was last updated 3 years, 5 months ago by perlastudio.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • October 12, 2019 at 7:25 am #493970
    perlastudio
    Participant

    Hello,

    I created a custom post type for products. The breadcrumbs work great on these posts except for the child posts don't show the parent product.

    Current: Home > Products > Child Product
    Desired: Home > Products > Parent Product > Child Product

    My settings:

    add_filter( 'genesis_breadcrumb_args', 'sp_breadcrumb_args' );
    function sp_breadcrumb_args( $args ) {
    	$args['home'] = 'Home';
    	$args['sep'] = ' / ';
    	$args['list_sep'] = ', '; // Genesis 1.5 and later
    	$args['prefix'] = '<div class="breadcrumb">';
    	$args['suffix'] = '</div>';
    	$args['heirarchial_attachments'] = true; // Genesis 1.5 and later
    	$args['heirarchial_categories'] = true; // Genesis 1.5 and later
    	$args['display'] = true;
    	$args['labels']['prefix'] = 'You are here: ';
    	$args['labels']['author'] = 'Archives for ';
    	$args['labels']['category'] = 'Archives for '; // Genesis 1.6 and later
    	$args['labels']['tag'] = 'Archives for ';
    	$args['labels']['date'] = 'Archives for ';
    	$args['labels']['search'] = 'Search for ';
    	$args['labels']['tax'] = 'Archives for ';
    	$args['labels']['post_type'] = 'Archives for ';
    	$args['labels']['404'] = 'Not found: '; // Genesis 1.5 and later
    return $args;
    }
    /* CPT PRODUCTS */
    
    add_action( 'init', 'products_init' );
    
    function products_init() {
      $labels = array(
        'name'               => 'Products',
        'singular_name'      => 'Products',
        'singular_label'     => 'Products',
        'add_new'            => 'Add Product',
        'add_new_item'       => 'Add Product',
        'edit'               => 'Edit',
        'edit_item'          => 'Edit Product',
        'new_item'           => 'New Product',
        'view'               => 'View Product',
        'view_item'          => 'View Product',
        'search_items'       => 'Search Product',
        'not_found'          => 'Nie znaleziono pasuj?…cych wpisów. Spróbuj ponownie.',
        'not_found_in_trash' => 'Nie znaleziono pasuj?…cych wpisów. Spróbuj ponownie.',
      );
    
      $args = array(
        'labels'             => $labels,
        'public'             => true,
        'show_ui'            => true,
        'capability_type'    => 'page',
        'has_archive'        => true,
        'hierarchical'          => true,
        'rewrite'            => array( 'slug' => 'products' ),
        'supports'           => array( 
            'title', 
            'editor', 
            'custom-fields', 
            'thumbnail', 
            'page-attributes',
            'genesis-seo',
            'genesis-layouts',
            'genesis-simple-sidebars',
            'genesis-cpt-archives-settings'
        )
      );
    
      register_post_type( 'products', $args );
    }

    Please, help me 🙁

    Best regards,
    Tomasz Perliński

    October 12, 2019 at 6:51 pm #493973
    Anita
    Keymaster

    Check out Bill's Erickson's post here. Be sure to review the second paragraph.


    Love coffee, chocolate and my Bella!

    October 13, 2019 at 5:02 am #493976
    perlastudio
    Participant

    Anita,

    Thanks for article... It was helpful...

    I wrote code:

    /**********************************
     * BREADCRUMB *
     **********************************/
    function cpt_rolety_zewnetrzne_breadcrumb( $crumb, $args ) {
    	// Only modify the breadcrumb if in the 'rolety_zewnetrzne' post type
    	if( 'rolety_zewnetrzne' !== get_post_type() )
    		return $crumb;
    	
            $parentID = wp_get_post_parent_id($post->ID);
        
            if($parentID == 0) 
                return $crumb;
        
            $parent = get_post($parentID);
    	
            if(!empty($parent))
            {
                
                // Build the breadcrumb
                $crumb = '<a href="' . get_post_type_archive_link( 'rolety_zewnetrzne' ) . '">Rolety zewnętrzne</a>' . $args['sep'] . '<a href="'.get_the_permalink($parent->ID).'">'.$parent->post_title.'</a>' . $args['sep'] . get_the_title();
                
            }
    	
    		
    	return $crumb;
    }
    add_filter( 'genesis_single_crumb', 'cpt_rolety_zewnetrzne_breadcrumb', 10, 2 );

    Function working, but links in breadcrumb showing without tag "span" and "class".

    Current:
    <a href="http://xxx/xxx/xxx/">Link Breadcrumb</a>

    Desired:

    <span class="breadcrumb-link-wrap">
        <a class="breadcrumb-link" href="http://xxx/xxx/xxx/">
            <span class="breadcrumb-link-text-wrap">Link Breadcrumb</span>
        </a>
    </span>

    how to fix it?

    Thanks for help.

    Best regards,
    Tomasz Perliński

    October 13, 2019 at 5:19 am #493977
    levanquyen
    Member

    https://www.facebook.com/groups/genesiswp/permalink/2814306448620534/

    October 13, 2019 at 9:57 am #493981
    JiveDig
    Participant

    You’re building the link HTML already in your $crumb variable, so you can add the extra spans/markup there.


    Lead developer of Mai Theme

    October 15, 2019 at 2:45 am #494005
    perlastudio
    Participant

    JiveDig,

    thanks for help!

    This code working:

    /**********************************
     * BREADCRUMB FOR CPT*
     **********************************/
    function cpt_rolety_zewnetrzne_breadcrumb( $crumb, $args ) {
        
        // Set register CPT
        $registerCustomPostType = 'rolety_zewnetrzne';
        
    	// Only modify the breadcrumb if in the 'rolety_zewnetrzne' post type
    	if( $registerCustomPostType !== get_post_type() )
    		return $crumb;
        
    	    $postType = get_post_type_object(get_post_type());
        
            $parentID = wp_get_post_parent_id($post->ID);
        
            if($parentID == 0) 
                return $crumb;
        
            $parent = get_post($parentID);
        
            $link1 = '<span class="breadcrumb-link-wrap"><a class="breadcrumb-link" href="' . get_post_type_archive_link( $registerCustomPostType ) . '"><span class="breadcrumb-link-text-wrap">' . $postType->labels->singular_name . '</span></a></span>';
    	
            $link2 = '<span class="breadcrumb-link-wrap"><a class="breadcrumb-link" href="'.get_the_permalink($parent->ID) . '"><span class="breadcrumb-link-text-wrap">'.$parent->post_title.'</span></a></span>';
                
            if(!empty($parent))
            {
                
                // Build the breadcrumb
                $crumb = $link1 . $args['sep'] . $link2 . $args['sep'] . get_the_title();
                
            }
    		
    	return $crumb;
    }
    add_filter( 'genesis_single_crumb', 'cpt_rolety_zewnetrzne_breadcrumb', 10, 2 );
  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Including the Parent/Child Custom Post Relationship in Breadcrumbs – Genesis’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble