{"id":151,"date":"2014-06-18T11:17:59","date_gmt":"2014-06-18T11:17:59","guid":{"rendered":"http:\/\/localhost\/syllogic\/wp\/?p=151"},"modified":"2024-02-02T12:22:27","modified_gmt":"2024-02-02T12:22:27","slug":"fixing-custom-post-breadcrumbs","status":"publish","type":"post","link":"http:\/\/localhost:10008\/fixing-custom-post-breadcrumbs\/","title":{"rendered":"Fixing Custom Post breadcrumbs"},"content":{"rendered":"\n
When using a ready made theme such as one of the excellent Elegant Themes one is confronted to small issues of broken sections of the page templates when introducing custom post and getting them to display properly in the page templates<\/p>\n\n\n\n
One such issue is the breadcrumbs link not working properly as a result of the custom taxonomies not being picked up properly by the core functions. Here is some workaround for this.<\/p>\n\n\n\n
In the case of the Elegant themes, you will find the So for example in the single post page template, the breadcrumbs are displayed using the following code.<\/p>\n\n\n\n So we can include the following lines in order to ensure it works with our custom post<\/p>\n\n\n\n When using a ready made theme such as one of the excellent Elegant Themes one is confronted to small issues of broken sections of the page templates when introducing custom post and getting them to display properly in the page templates One such issue is the breadcrumbs link not working properly as a result of […]<\/p>\n","protected":false},"author":2,"featured_media":319,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"yoast_head":"\nbreadcrumbs.php<\/code> file in the
includes\/<\/code> directory.<\/p>\n\n\n\n
...\n\/\/some code to display the authors link followed by\n$category = get_the_category(); \/\/returns the categories of this post\n$catlink = get_category_link( $category[0]->cat_ID ); \/\/gets the links for the first category\necho ('<a href=\"'.esc_url($catlink).'\">'.esc_html($category[0]->cat_name).'<\/a> '.'<span class=\"raquo\">»<\/span> '.get_the_title()); \n\/\/displays the category in the breadcrumb\n<\/code><\/pre>\n\n\n\n
global $post; \/\/we need to ensure we have access to the post object breadcrumbs are handled in its own template\n...\nswitch ( get_post_type($post) ){ \/\/switch on the post_type\n case 'my_custom_post_type': \/\/\n $category = get_the_terms($post->ID, 'my_custom_taxonomy');\n $first_term = reset($category);\n $catlink = get_term_link( $first_term );\n echo (''.esc_html($first_term->name).'<\/a> '.'\u00bb<\/span> '.get_the_title());\n break;\n default: \/\/default 'post'and below is the default code \n $category = get_the_category();\n $catlink = get_category_link( $category[0]->cat_ID );\n echo (''.esc_html($category[0]->cat_name).'<\/a> '.'\u00bb<\/span> '.get_the_title());\n break;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"