WordPress.org

Ready to get started?Download WordPress

Forums

Breadcrumb NavXT
[resolved] Custom post type support (56 posts)

  1. DreadLox
    Member
    Posted 3 years ago #

    Hello,

    I was looking forward custom postype support but 3.6 doesn't follow the rewrite slug I define.

    Custom post type are not always blog posts, I personnaly use custom post types as pages. I often redifine the rewrite slug and remove the front blog prefix. Example, for a school posttype I set

    Rewrite Slug: informations/schools (information and schoold are exiting pages. Doing this way a my_school school url would look like this:

    informations/schools/my_school

    But the breadcrumb shows:

    Home > Blog > my_school

    Whereas it should display:

    Home > Informations > Schools > my_school

    So here are my questions: is that behavior possible to achieve in in 3.6?

    If not, is it planned?

    Best regards

  2. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    Dreadlox,

    The current implementation was done several months ago and I asked for input on it. From the little feedback I received, it did what the users were looking for. See this post on the explanation of what is supported in 3.6.0's custom post type support: http://mtekk.us/archives/wordpress/plugins-wordpress/breadcrumb-navxt-custom-post-type-support/

    You are running into what seems to be two (or three) issues.

    The first is that I assumed (carried over from the old post type) that flat post types would be a child of "blog", while all hierarchical posts (carried over from old page type) are children of only the root page. I see where this is not always the case and can add in the option (it will hit the SVN trunk probably late this week, I well respond in this post when I have committed it to the SVN trunk).

    The second seems to be you are performing a "hierarchy flip" (somewhat covered in the linked post above). Traditionally, the solution here is to have Schools and Informations be terms of a hierarchical taxonomy (this is a fully supported method in 3.6.0, minus the "blog" breadcrumb that was explained above).

    If Informations and Schools are pages (the post type of page that has been in WordPress since 1.5 or so), and Schools is a child page of Informations, then my_school would need to be a child of Schools. This is not exactly supported at the moment. The underlying code is there for one flat to hierarchical post type "hierarchy flip" (as long as the destination is of the type page), but the front end (settings page) does not support it for all types. However, if you can set the 'post_POSTTYPEHERE_taxonomy_type' array member in the opt array (part of the bcn_breadcrumb_trail class) to "post". Note that you need to replace POSTTYPEHERE with the name of the post type you are using for my_school.

    Ok that was probably long and confusing. The good news is I'm going to change the settings page to accommodate custom taxonomies and post types in a easier to understand way, and at the same time I will add in the extra code to make what you are tying to do work (provided that you make sure my_school has Schools set as its parent).

    -John Havlik

  3. DennisMadsen
    Member
    Posted 3 years ago #

    Are there any news regarding this situation?

    I've a custom post type called demaweb_products. I've a page called products using a custom template from my theme which display a archive of my demaweb_products. It's on the page: /products/.

    The url for my custom posts are eg.: /products/cms/

    When I eg. visit /products/cms/ the breadcrumb only displays: Home > CMS.

    I would like it to be:
    Home > Products > CMS.

    Is that possible?

  4. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    DreadLox and DennisMadsen,

    The current SVN trunk should allow you to use pages as a hierarchy type for any flat post type. The "core" of Breadcrumb NavXT allows for any hierarchical post type to be the hierarchy for any post type, I just need to finish extending the "front end"/settings page.

    As for removing the blog part in DreadLox's post, I am working on the modifications to the "core" tonight for that.

  5. DennisMadsen
    Member
    Posted 3 years ago #

    Thanks.
    From where can I download the SVN trunk?

  6. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    Grab the "Development Version" from this page: http://wordpress.org/extend/plugins/breadcrumb-navxt/download/

  7. DennisMadsen
    Member
    Posted 3 years ago #

    When activating the taxonomy display for my custom post type, I got this error when displaying the creadcrumb in frontend:
    Fatal error: Cannot access protected property bcn_breadcrumb::$title in ...\wp-content\plugins\breadcrumb-navxt\breadcrumb_navxt_class.php on line 455

  8. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    My bad, I forgot to update that section of code. The SVN Trunk should now have that fixed.

  9. DennisMadsen
    Member
    Posted 3 years ago #

    How can I change the "Untagged" to a link to my product page?

  10. DennisMadsen
    Member
    Posted 3 years ago #

    I inserted 'post_demaweb_product_taxonomy_type' => 'post' into the array and made the custom post type hierarchical. Now it displays the parent post. Thats a nice feature - but not what I wanted.

    Instead I would like the opportunity to define a custom taxonomy to be displayed before the product in the breadcrumb trail - instead of the parent product. I was told on this forum, that the best way to create an archive for my products, was to create a custom page template and create a page using that template. Because of that WP does not know, which page that is parent for my products. Therefore it would be great, if I could create a custom product taxonomy in the backend under the product tab. Here I would like to define the URL to the product archive (In my case /products/) - the title of the page can be queried from the page title.

    Maybe I'm wrong. But how could I else create a custom archive for my product on /products/ in a way, that will work with your plugin?

    Thanks for your time!

  11. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    The untagged thing should be dynamic in the SVN Trunk now (forgot to update that earlier).

    I inserted 'post_demaweb_product_taxonomy_type' => 'post' into the array and made the custom post type hierarchical. Now it displays the parent post. Thats a nice feature - but not what I wanted.

    By setting the taxonomy type for the demaweb_product custom post type to post (not an available option in the settings page), you are telling Breadcrumb NavXT to use posts as the taxonomy, and inherit the post's taxonomy. However, if demaweb_product is a hierarchal custom post type, it should ignore the taxonomy_type setting (automatically crawls the hierarchy until it gets to the root page of the site).

    Instead I would like the opportunity to define a custom taxonomy to be displayed before the product in the breadcrumb trail - instead of the parent product.

    You can do this, no problem. Just set the custom post type to "normal/flat" (non-hierarchical), and define which taxonomies are valid for that type. Then, in the settings page of Breadcrumb NavXT, under the tab for the post type you are using, you should be able to select from the valid taxonomies for that post type.

    I was told on this forum, that the best way to create an archive for my products, was to create a custom page template and create a page using that template. Because of that WP does not know, which page that is parent for my products.

    This has caused many issues before. I don't know who keep recommending this, but they must not be aware of some of these issues with it. The only advantage to that method is you can have some custom text on the products page that can be edited via the standard edit panels. The way I'd suggest doing this is to have a template file for your custom taxonomy, and have it display the taxonomy tag description for your additional information.

    Therefore it would be great, if I could create a custom product taxonomy in the backend under the product tab. Here I would like to define the URL to the product archive (In my case /products/) - the title of the page can be queried from the page title

    Where are you talking about for this?

  12. DennisMadsen
    Member
    Posted 3 years ago #

    This has caused many issues before. I don't know who keep recommending this, but they must not be aware of some of these issues with it. The only advantage to that method is you can have some custom text on the products page that can be edited via the standard edit panels. The way I'd suggest doing this is to have a template file for your custom taxonomy, and have it display the taxonomy tag description for your additional information.

    I'm going 2 steps back and starting over again. I would like to use your solution, but I did not get point completely.

    Here is the code for my custom post type:

    register_post_type( 'demaweb_product',
    		array(
    			'labels' => array(
    							'name' => __( 'Products' ),
    							'singular_name' => __( 'Product' ),
    						),
    			'public' => true,
    			'rewrite' => array('slug' => 'products'),
    			'supports' => array('title','editor','excerpt','page-attributes','revisions'),
    		)
    	);

    I found this example of how to create a custom taxonomy:
    http://codex.wordpress.org/Function_Reference/register_taxonomy#Example

    But how should I define the taxonomy? Should I eg. create this hierachical taxonomy called "product":

    register_taxonomy('product',array('demaweb_product'), array(
        'hierarchical' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'products' ),
      ));

    I then guess, that the URL /products/ would act like the normal /category/ URL - but now showing a archive for the taxonomy? But how can I then create a custom file in my theme defining the layout of my /products/ page? Right now I got the 404-page.

  13. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    For a taxonomy to show up for a custom post type (from what I have seen), you need to use something like:

    register_post_type( 'demaweb_product',
    array(
    	'labels' => array(
    		'name' => __( 'Products' ),
    		'singular_name' => __( 'Product' ),
    	),
    	'public' => true,
    	'rewrite' => array('slug' => 'products'),
    	'supports' => array('title','editor','excerpt','page-attributes','revisions'),
    	'taxonomies' => array('product')
    )
    );

    I then guess, that the URL /products/ would act like the normal /category/ URL - but now showing a archive for the taxonomy

    Yes, /products/ should then show your products archive. To add the extra template for your theme, you'll want to create a taxonomy-product.php (see http://codex.wordpress.org/Template_Hierarchy for more information).

  14. DennisMadsen
    Member
    Posted 3 years ago #

    I've tried with this custom post type and custom taxonomy:

    register_post_type( 'demaweb_product',
    		array(
    			'labels' => array(
    				'name' => __( 'Products' ),
    				'singular_name' => __( 'Product' ),
    			),
    			'public' => true,
    			'rewrite' => array('slug' => 'products'),
    			'supports' => array('title','editor','excerpt','page-attributes','revisions'),
    			'taxonomies' => array('product')
    		)
    	);
    
    register_taxonomy('product',array('demaweb_product'), array(
        'hierarchical' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'products' ),
     ));

    When visiting the /products/ URL I got the 404.php file. I've created a empty files for both taxonomy.php and archive.php, but none of them are called. I've created three posts in my custom post type but I have not created any items in my product-taxconomy - even if I create a dummy item here, I still got the 404.php file.

    Do you know what the problem is?

  15. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    Make sure you register your taxonomy first. Regardless of this, I've inadvertently lead you astray. I forgot that WordPress still does not do "global" (for a lack of a better word) archives for taxonomies (e.g. an archive containing all categorized or all tagged, or all custom taxonomied post types). Before the advent of custom post types (and custom taxonomies) this did not make sense to have, now, IMHO, it does. I need to ponder on this for a little bit (I have a project that is going to run into this issue shortly).

  16. DennisMadsen
    Member
    Posted 3 years ago #

    Ok, hope you will come back, when you found the way to do it.. In the mean time, I'll keep using the method with the custom page template.

    Thank you!

  17. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    @DreadLox:

    In the SVN Trunk there is a version that should have the fixes you need for both of your issues. Let me know if it works, or if you have suggestions for improvements. Note that this doesn't work on archive pages yet (forgot to add it as of now, will add early this week). Do note that I may need to change the way this works to fix an issue that Dennis ran into (and that I'm about to run into myself) but that won't come for another week or so.

  18. DreadLox
    Member
    Posted 3 years ago #

    I installed the svn version and I could remove the "Blog" element from the breadcrumb. I am currently building a music label website, so I have an "artist" post_type witch is held by an "Artists" page. So I set the rewrite slug for that post type to artists/ .

    But the breadcrumb still shows Home > Artist name instead of Home > Artists > Artist name ...

  19. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    DeadLox,

    What type of custom post type are "artists"? If they are flat, and have a taxonomy, you'll need to set their taxonomy, under the "Artist" tab in Breadcrumb NavXT's settings page, to "Pages". Then you will have to make sure every artist post has the correct page set as the parent (a real PITA and is why I do not recommend doing it this way). This is similar to the issue Dennis has, and the change in behavior I am going to work on eliminates this issue (essentially instead of turning on and off the blog breadcrumb, you will specify the "root" for the post type).

  20. DreadLox
    Member
    Posted 3 years ago #

    This is similar to the issue Dennis has, and the change in behavior I am going to work on eliminates this issue (essentially instead of turning on and off the blog breadcrumb, you will specify the "root" for the post type).

    Exactly what is needed but why don't you do code it? Let me explain.

    Saying I have a custom post type "Computers" and a "holding page" under Products > Computers (both are pages)

    Then, I set the rewrite slug to 'products/computers' and front=false. So basically you could

    1. read the front parameter to decide whereas "Blog" has to be added
    2. and explode the rewrite slug using the '/' parameters and do something like:

    <?php
    
    $post_for_trail = array();
    
    $post_type = get_post_type_object($post_type);
    
    $rewrite_array = explode('/', $post_type->rewrite->slug);
    
    foreach ($rewrite_array as $post_slug) {
    
    	$post_id = get_post_by_slug($post_slug); // function to be written
    
    	// one rewrite slug part is not a post we do not add anything to trail and exit
    	if( !$post = get_post($post_id) ) {
    		$post_for_trail = array();
    		break;
    	}
    
    	$post_for_trail[] = $post;
    }

    ?>

  21. DreadLox
    Member
    Posted 3 years ago #

    Any thought about my last post?

  22. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    Sorry for the delay, I've been swamped the past few days. Hopefully tomorrow I'll get a chance to look at it/think about it.

  23. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    I could do it the way you suggested with your code. Though I'm not sure if it would work if there are taxonomies mixed in. Typically, I prefer to add options when they are useful, and not duplicating something that I could find from what a user specified elsewhere in their install. It looks like I may have time tomorrow to work on coding this again (as long as I don't get another deluge of support requests again (not all related to Breadcrumb NavXT)).

  24. pokes
    Member
    Posted 3 years ago #

    This sounds like something I could use too, I'm looking to have a flat Custom Post sitting below a Page hierarchy.

    Horrible I know, but I haven't figured out how to use a hierarchical Custom Post and have it automatically add to the site navigation menus like Pages do.

  25. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    Ok guys, there is preliminary support for this in the SVN trunk. I know it has some bugs in it still (archive pages in particular). Let me know how bad it "crashes and burns" :)

  26. pokes
    Member
    Posted 3 years ago #

    Custom Posts. Set a Root Page, Display Yes, Taxonomy to Pages.

    Custom Posts still seem to sit below the Home page..

    Changing Product Root Page has no effect. Setting Taxonomy to Post Tag or Category drops the respective breadcrumb in between Home and my Custom Post.

    What am I missing?

  27. iporter
    Member
    Posted 3 years ago #

    Super work mtekk - you've made my day, it's exactly what I needed for a project I need to finish today!

    I've installed the development version and it seems to be working fine.

    Thank you.

  28. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    Custom Posts still seem to sit below the Home page.

    Well, all pages/posts/etc are going to sit under a home/front page if you have a static front page. Note that I have not tested this in a non static frontpage setups yet as I have several kinks to work out when there are static frontpages (no ETA for this yet).

  29. pokes
    Member
    Posted 3 years ago #

    Perhaps I could have worded that more accurately - 'Custom Posts still seem to sit directly below the Home page.'

    Approaching from another angle - what exactly does the Root Page setting do and are there any prerequisites for its operation?

    Thanks for your time on this mtekk, really appreciated.

  30. John Havlik
    Member
    Plugin Author

    Posted 3 years ago #

    The post type root page works like the "Page on Front" and "Posts Page" settings in WordPress. Since equivalents for custom post types do not exist (at the moment), I added this setting (for the time being).

    So, you want to set it to the "root" page for your custom post type. Breadcrumb NavXT will then build the breadcrumb trail starting with the custom post type, working backwards up to the root page for that type. Then, it will follow the root page's hierarchy to the "Page on Front".

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic