I’m not quite sure what you changed. It looks the same to me.
I’m not surprised by the resulting behavior. If you look at the structure of your pages ‘Dienstleistungen’ is the parent that you get to from the home page. ‘Engineering’ is the child page you get to from ‘Dienstleistungen’. This is reflected in the breadcrumbs.
For your CPT, ‘Germany|Ober-Ramstadt’ is the parent you get to from the home page. ‘Child Company’ is the child page you get to from ‘Germany|Ober-Ramstadt’. This is also reflected in the breadcrumbs.
The breadcrumbs represent the path that you took through the website to get to where you are now. Since you did not have to navigate the archive, it isn’t included in the breadcrumbs.
Under the hood, this uses the WP function, ‘get_post_ancestors’, which will not return the archive page. You would have to modify the PHP block if you want this behavior.
<?php $breadcrumbs = PG_Helper::getBreadcrumbs( 'parents', true, 'Home'); ?>
<?php if( !empty( $breadcrumbs ) ) : ?>
<div cms-breadcrumbs-home cms-breadcrumbs-separator="span">
<p><?php _e( 'Breadcrumb', 'st2' ); ?></p>
<ul>
<?php for( $breadcrumbs_i = 0; $breadcrumbs_i < count( $breadcrumbs ); $breadcrumbs_i++) : ?>
<?php $breadcrumb = $breadcrumbs[ $breadcrumbs_i ]; ?>
<li>
<a href="<?php echo esc_url( $breadcrumb[ 'link' ] ); ?>"><?php echo $breadcrumb[ 'name' ]; ?></a>
</li>
//insert new code here
<?php if( $breadcrumbs_i < count( $breadcrumbs ) - 1 ) : ?>
<span>></span>
<?php endif; ?>
<?php endfor; ?>
</ul>
</div>
<?php endif; ?>
Here is the generated PHP when you use the WP Action in Pinegrow - yours may slightly differ based on your separator, plus I had a holder of ‘Breadcrumb’ that is in the code. The $breadcrumbs
variable is populated with an array of all the post ancestors. I’ve indicated where to insert the code that I show below.
The easiest way I see to get the solution you want is to create a single-companies.php page for displaying the companies and to alter the PHP for the breadcrumbs on that page.
Let’s walk through the code a little. The first line populates the $breadcrumbs
variable. Next, we set up an if loop to only display the breadcrumbs if they exist. Next is a <div>
element for the breadcrumb output , followed by my placeholder in a <p>
. Now we get to the main part.
The breadcrumbs are set up in an unordered list, <ul>
. Nested in this is a for loop that goes through each of the elements of the $breadcrumbs array. Each element is outputted into a <li>
element with a link(<a>
) and name.
<li>
<a href="<?php echo esc_url( $breadcrumb[ 'link' ] ); ?>"><?php echo $breadcrumb[ 'name' ]; ?></a>
</li>
That is then followed by an if statement to insert your separator if there is another item in the breadcrumb array.
So, what you want to do is inject a link between the home breadcrumb and the first page breadcrumb. We can do this by inserting an if statement along with another divider above the existing if statement.
<?php if($breadcrumbs_i === 0) : ?>
<span>></span>
<li>
<a href="<?php echo get_site_url() . '/companies/'; ?>"><?php echo 'Companies'; ?></a>
</li>
<?php endif; ?>
So, in the second line this code will add your span after the ‘Home’ breadcrumb. You will need to change this to reflect your separator. It then adds a link for the archive, assuming you have pretty permalinks the allows access to the archive at ‘https://your-site.com/companies’ .
Hope this helps,
Bob