Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How do I make custom post types not appear as blog posts? WordPress

  • SOLVED

I am using a paid theme (TrueThemes Sterling) and a 3rd party plugin (MusoPress Discography). The plugin uses custom post types which work as expected in other themes that I've tried, but in this particular theme, the discography breadcrumb and posts appear as if they're part of the blog, not part of the plugin's structure.

I'm not a developer, but I am hoping that I can at least get some idea of where to start looking for a solution. The plugin developer feels that the theme probably has breadcrumb code that does not work well with custom posts. The theme vendor does not support this kind of 'customization'.


http://www.scholamagdalena.ca/wp/discography/

Note when you click on an album it should show Recordings > Title in the breadcrumb. Instead it shows the blog path. Also note that both the recordings nav and updates (blog) nav are in their selected state.

Update:

The plugin vendor also noted the following:

It seems wordpress is interpreting the "single album" as a "single post", which shouldn't be happening. Maybe there's a custom function in the theme which is causing this to happen?

So this is probably a 2-parter:

Part 1: replace the breadcrumb
Part 2: figure out why the post is being displayed using the wrong template/page type.

Answers (5)

2012-09-28

Arnav Joy answers:

can you show me the function from your theme which is producing breadcrumb?

BTW where is album link?


ilowelife comments:

The album link is when you click on an album cover here: http://www.scholamagdalena.ca/wp/discography/

I'm not sure what you mean by the function. The theme uses another plugin "Simple Breadcrumb Navigation"

I think this is what you're asking for:


function simple_breadcrumb(){
$this->options = array( //change this array if you want another output scheme
'before' => '',
'after' => ' → ',
'delimiter' => ''
);

$markup = $this->options['before'].$this->options['delimiter'].$this->options['after'];

global $post;
echo '<a href="'.home_url().'">';

/*
* get user entered breadcrumb home text,
* if empty we show default "home" for home page link
* @since version 2.6 development.
*/
global $ttso;
$home_text = stripslashes($ttso->st_breadcrumbs_home_text);
if(!empty($home_text)){
echo $home_text;
}
else{
echo 'Home';
}

echo "</a>";
if(!is_front_page()){echo $markup;}

$output = $this->simple_breadcrumb_case($post);

echo "<span class='current_crumb'>";
if ( is_page() || is_single()) {
the_title();
}else{
echo $output;
}
echo " </span>";
}

2012-09-28

Abdelhadi Touil answers:

Hi.
It's possible to disable the theme breadcrumbs from theme options page? If yes then maybe you can use a plugin to generate working breadcrumbs, or try breadcrumbs built in the famous WordPress SEO by Yoast plugin, or the Breadcrumb NavXT plugin.

[[LINK href="http://wordpress.org/extend/plugins/wordpress-seo/"]]http://wordpress.org/extend/plugins/wordpress-seo/[[/LINK]]

[[LINK href="http://wordpress.org/extend/plugins/breadcrumb-navxt/"]]http://wordpress.org/extend/plugins/breadcrumb-navxt/[[/LINK]]

Good luck.


Abdelhadi Touil comments:

If it's not possible to disable the built in theme breadcrumbs, I'v found a working breadcrumbs function that you can use instead of the theme one:

// WooCommerce Compatable Breadcrumbs
function limelight_breadcrumbs()
{
global $post, $wp_query;
if ( ! $home ) $home = __( 'Home', 'limelight' );
$home_link = home_url();
$delimiter = ' &raquo; ';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
$wrap_before = ' <nav id="breadcrumbs">';
$wrap_after = '</nav> ';

if ( get_option('woocommerce_prepend_shop_page_to_urls') == "yes" && woocommerce_get_page_id( 'shop' ) && get_option( 'page_on_front' ) !== woocommerce_get_page_id( 'shop' ) )
$prepend = '<a href="' . get_permalink( woocommerce_get_page_id('shop') ) . '">' . get_the_title( woocommerce_get_page_id('shop') ) . '</a> ' . $delimiter;
else $prepend = '';

if ( ( ! is_home() && ! is_front_page() && ! ( is_post_type_archive() && get_option( 'page_on_front' ) == woocommerce_get_page_id( 'shop' ) ) ) || is_paged() ) {

echo $wrap_before . '<a class="home" href="' . $home_link . '">' . $home . '</a> ' . $delimiter ;

if ( is_category() ) {

$cat_obj = $wp_query->get_queried_object();
$this_category = get_category( $cat_obj->term_id );

if ( $this_category->parent != 0 ) {
$parent_category = get_category( $this_category->parent );
echo get_category_parents($parent_category, TRUE, $delimiter );
}

echo $currentBefore . single_cat_title( '', false ) . $currentAfter;

} elseif ( is_tax('product_cat') ) {

echo $prepend;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

$parents = array();
$parent = $term->parent;
while ( $parent ) {
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) );
$parent = $new_parent->parent;
}

if ( ! empty( $parents ) ) {
$parents = array_reverse( $parents );
foreach ( $parents as $parent ) {
$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
echo '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>' . $delimiter;
}
}

$queried_object = $wp_query->get_queried_object();
echo $currentBefore . $queried_object->name . $currentAfter;

} elseif ( is_tax('product_tag') ) {

$queried_object = $wp_query->get_queried_object();
echo $prepend . $currentBefore . __('Products tagged &ldquo;', 'limelight') . $queried_object->name . '&rdquo;' . $currentAfter;

} elseif ( is_search() ) {

echo $currentBefore . __( 'Search results for &ldquo;', 'limelight' ) . get_search_query() . '&rdquo;' . $currentAfter;

} elseif ( is_day() ) {

echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter;
echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $delimiter;
echo $currentBefore . get_the_time('d') . $currentAfter;

} elseif ( is_month() ) {

echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter;
echo $currentBefore . get_the_time('F') . $currentAfter;

} elseif ( is_year() ) {

echo $currentBefore . get_the_time('Y') . $currentAfter;

} elseif ( is_post_type_archive('product') && get_option('page_on_front') !== woocommerce_get_page_id('shop') ) {

$_name = woocommerce_get_page_id( 'shop' ) ? get_the_title( woocommerce_get_page_id( 'shop' ) ) : ucwords( get_option( 'woocommerce_shop_slug' ) );

if ( is_paged() ) {

echo $currentBefore . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $currentAfter;

} else {

echo $currentBefore . $_name . $currentAfter;

}

} elseif ( is_single() && !is_attachment() ) {

if ( get_post_type() == 'product' ) {

echo $prepend;

if ( $terms = wp_get_object_terms( $post->ID, 'product_cat' ) ) {
$term = current( $terms );
$parents = array();
$parent = $term->parent;

while ( $parent ) {
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, 'product_cat' );
$parent = $new_parent->parent;
}

if ( ! empty( $parents ) ) {
$parents = array_reverse($parents);
foreach ( $parents as $parent ) {
$item = get_term_by( 'id', $parent, 'product_cat');
echo '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>' . $delimiter;
}
}

echo '<a href="' . get_term_link( $term->slug, 'product_cat' ) . '">' . $term->name . '</a>' . $delimiter;

}

echo $currentBefore . get_the_title() . $currentAfter;

} elseif ( get_post_type() != 'post' ) {

$post_type = get_post_type_object( get_post_type() );
$slug = $post_type->rewrite;
echo $currentBefore . '<a href="' . get_post_type_archive_link( get_post_type() ) . '">' . $post_type->labels->singular_name . '</a>' . $currentAfter . $delimiter;
echo $currentBefore . get_the_title() . $currentAfter;

} else {

$cat = current( get_the_category() );
echo get_category_parents( $cat, true, $delimiter );
echo $currentBefore . get_the_title() . $currentAfter;

}

} elseif ( is_404() ) {

echo $currentBefore . __( 'Error 404', 'limelight' ) . $currentAfter;

} elseif ( ! is_single() && ! is_page() && get_post_type() != 'post' ) {

$post_type = get_post_type_object( get_post_type() );

if ( $post_type )
echo $currentBefore . $post_type->labels->singular_name . $currentAfter;

} elseif ( is_attachment() ) {

$parent = get_post( $post->post_parent );
$cat = get_the_category( $parent->ID );
$cat = $cat[0];
echo get_category_parents( $cat, true, '' . $delimiter );
echo $currentBefore . '<a href="' . get_permalink( $parent ) . '">' . $parent->post_title . '</a>' . $currentAfter . $delimiter;
echo $currentBefore . get_the_title() . $currentAfter;

} elseif ( is_page() && !$post->post_parent ) {

echo $currentBefore . get_the_title() . $currentAfter;

} elseif ( is_page() && $post->post_parent ) {

$parent_id = $post->post_parent;
$breadcrumbs = array();

while ( $parent_id ) {
$page = get_page( $parent_id );
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title( $page->ID ) . '</a>';
$parent_id = $page->post_parent;
}

$breadcrumbs = array_reverse( $breadcrumbs );

foreach ( $breadcrumbs as $crumb )
echo $crumb . '' . $delimiter;

echo $currentBefore . get_the_title() . $currentAfter;

} elseif ( is_tag() ) {

echo $currentBefore . __( 'Posts tagged &ldquo;', 'limelight' ) . single_tag_title('', false) . '&rdquo;' . $currentAfter;

} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . __( 'Author:', 'limelight' ) . ' ' . $userdata->display_name . $currentAfter;

}

if ( get_query_var( 'paged' ) )
echo ' (' . __( 'Page', 'limelight' ) . ' ' . get_query_var( 'paged' ) . ')';

echo $wrap_after;

}
}


I think you can just make the function name as it's in your theme, so instead of limelight_breadcrumbs() you let as in your theme: simple_breadcrumb(), so the function should become:

function simple_breadcrumb() {
global $post, $wp_query;
if ( ! $home ) $home = __( 'Home', 'limelight' );
$home_link = home_url();
$delimiter = ' &raquo; ';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
$wrap_before = ' <nav id="breadcrumbs">';
$wrap_after = '</nav> ';

if ( get_option('woocommerce_prepend_shop_page_to_urls') == "yes" && woocommerce_get_page_id( 'shop' ) && get_option( 'page_on_front' ) !== woocommerce_get_page_id( 'shop' ) )
$prepend = '<a href="' . get_permalink( woocommerce_get_page_id('shop') ) . '">' . get_the_title( woocommerce_get_page_id('shop') ) . '</a> ' . $delimiter;
else $prepend = '';

if ( ( ! is_home() && ! is_front_page() && ! ( is_post_type_archive() && get_option( 'page_on_front' ) == woocommerce_get_page_id( 'shop' ) ) ) || is_paged() ) {

echo $wrap_before . '<a class="home" href="' . $home_link . '">' . $home . '</a> ' . $delimiter ;

if ( is_category() ) {

$cat_obj = $wp_query->get_queried_object();
$this_category = get_category( $cat_obj->term_id );

if ( $this_category->parent != 0 ) {
$parent_category = get_category( $this_category->parent );
echo get_category_parents($parent_category, TRUE, $delimiter );
}

echo $currentBefore . single_cat_title( '', false ) . $currentAfter;

} elseif ( is_tax('product_cat') ) {

echo $prepend;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

$parents = array();
$parent = $term->parent;
while ( $parent ) {
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) );
$parent = $new_parent->parent;
}

if ( ! empty( $parents ) ) {
$parents = array_reverse( $parents );
foreach ( $parents as $parent ) {
$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
echo '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>' . $delimiter;
}
}

$queried_object = $wp_query->get_queried_object();
echo $currentBefore . $queried_object->name . $currentAfter;

} elseif ( is_tax('product_tag') ) {

$queried_object = $wp_query->get_queried_object();
echo $prepend . $currentBefore . __('Products tagged &ldquo;', 'limelight') . $queried_object->name . '&rdquo;' . $currentAfter;

} elseif ( is_search() ) {

echo $currentBefore . __( 'Search results for &ldquo;', 'limelight' ) . get_search_query() . '&rdquo;' . $currentAfter;

} elseif ( is_day() ) {

echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter;
echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $delimiter;
echo $currentBefore . get_the_time('d') . $currentAfter;

} elseif ( is_month() ) {

echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter;
echo $currentBefore . get_the_time('F') . $currentAfter;

} elseif ( is_year() ) {

echo $currentBefore . get_the_time('Y') . $currentAfter;

} elseif ( is_post_type_archive('product') && get_option('page_on_front') !== woocommerce_get_page_id('shop') ) {

$_name = woocommerce_get_page_id( 'shop' ) ? get_the_title( woocommerce_get_page_id( 'shop' ) ) : ucwords( get_option( 'woocommerce_shop_slug' ) );

if ( is_paged() ) {

echo $currentBefore . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $currentAfter;

} else {

echo $currentBefore . $_name . $currentAfter;

}

} elseif ( is_single() && !is_attachment() ) {

if ( get_post_type() == 'product' ) {

echo $prepend;

if ( $terms = wp_get_object_terms( $post->ID, 'product_cat' ) ) {
$term = current( $terms );
$parents = array();
$parent = $term->parent;

while ( $parent ) {
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, 'product_cat' );
$parent = $new_parent->parent;
}

if ( ! empty( $parents ) ) {
$parents = array_reverse($parents);
foreach ( $parents as $parent ) {
$item = get_term_by( 'id', $parent, 'product_cat');
echo '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>' . $delimiter;
}
}

echo '<a href="' . get_term_link( $term->slug, 'product_cat' ) . '">' . $term->name . '</a>' . $delimiter;

}

echo $currentBefore . get_the_title() . $currentAfter;

} elseif ( get_post_type() != 'post' ) {

$post_type = get_post_type_object( get_post_type() );
$slug = $post_type->rewrite;
echo $currentBefore . '<a href="' . get_post_type_archive_link( get_post_type() ) . '">' . $post_type->labels->singular_name . '</a>' . $currentAfter . $delimiter;
echo $currentBefore . get_the_title() . $currentAfter;

} else {

$cat = current( get_the_category() );
echo get_category_parents( $cat, true, $delimiter );
echo $currentBefore . get_the_title() . $currentAfter;

}

} elseif ( is_404() ) {

echo $currentBefore . __( 'Error 404', 'limelight' ) . $currentAfter;

} elseif ( ! is_single() && ! is_page() && get_post_type() != 'post' ) {

$post_type = get_post_type_object( get_post_type() );

if ( $post_type )
echo $currentBefore . $post_type->labels->singular_name . $currentAfter;

} elseif ( is_attachment() ) {

$parent = get_post( $post->post_parent );
$cat = get_the_category( $parent->ID );
$cat = $cat[0];
echo get_category_parents( $cat, true, '' . $delimiter );
echo $currentBefore . '<a href="' . get_permalink( $parent ) . '">' . $parent->post_title . '</a>' . $currentAfter . $delimiter;
echo $currentBefore . get_the_title() . $currentAfter;

} elseif ( is_page() && !$post->post_parent ) {

echo $currentBefore . get_the_title() . $currentAfter;

} elseif ( is_page() && $post->post_parent ) {

$parent_id = $post->post_parent;
$breadcrumbs = array();

while ( $parent_id ) {
$page = get_page( $parent_id );
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title( $page->ID ) . '</a>';
$parent_id = $page->post_parent;
}

$breadcrumbs = array_reverse( $breadcrumbs );

foreach ( $breadcrumbs as $crumb )
echo $crumb . '' . $delimiter;

echo $currentBefore . get_the_title() . $currentAfter;

} elseif ( is_tag() ) {

echo $currentBefore . __( 'Posts tagged &ldquo;', 'limelight' ) . single_tag_title('', false) . '&rdquo;' . $currentAfter;

} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . __( 'Author:', 'limelight' ) . ' ' . $userdata->display_name . $currentAfter;

}

if ( get_query_var( 'paged' ) )
echo ' (' . __( 'Page', 'limelight' ) . ' ' . get_query_var( 'paged' ) . ')';

echo $wrap_after;

}
}


I'v found the breadcrumbs function here:

[[LINK href="http://wordpress.org/support/topic/help-fix-breadcrum-function-for-custom-post-types?replies=2"]]http://wordpress.org/support/topic/help-fix-breadcrum-function-for-custom-post-types?replies=2[[/LINK]]

Good luck.


ilowelife comments:

Thank you. This sort of works (the breadcrumb is referencing the custom post hierarchy) but it's displaying the wrong text now.

I am officially in over my head at this point :)


Abdelhadi Touil comments:

You are welcome.
Have you tried to disable the built in theme breadcrumbs and use a plugin instead?

2012-09-28

John Cotton answers:

It's tricky trying to get a theme and a plugin - neither of which know anything about the other - to work together.

I've not seen the Sterling code, but there are clues as to what's wrong in the plugin code. This is one from line 274 of the plugin:


/**
* Uses the page.php template for single albums.
*
* @uses locate_template() To get the template's location.
*
* @since Musopress Discography 0.1
* @return string
*/
function muso_get_album_template( $single_template ) {

global $post;

if ( 'muso-album' == $post->post_type ) {
$locate = locate_template( 'page.php' );
if ( !empty( $locate ) )
$single_template = $locate;
}

return $single_template;

}


So if the theme has a page.php, that's what will be used. Without it, then the ultra-default index.php will be used. I suspect that's what's happening, but you could check in your theme folder to see if a file called page.php exists.

The next clue comes from line 82:


//Use Page template for Single Albums if single-muso-album.php doesn't exist.
if ( '' == ( locate_template( 'single-muso-album.php' ) ) )
add_filter( 'single_template', 'muso_get_album_template' );


So that first piece of code can be sidestepped by creating a file (in the theme folder) called single-muso-album.php. Have you tried that?

If not, that's what you should do. Copy the contents of index.php (or page.php if that exists) into this new file. Then delete the breadcrumb code and stick something obvious like '@@@@@@@@@@@@@@' in it's place. When you view the page again do you see the @@@@@?

If so, you're almost there. You just need some slightly tweaked breadcrumb code to display exactly as you want in place of your temporary marker.

But get to that point first and let me know.


ilowelife comments:

Thank you John:

The theme does indeed have a page.php but it doesn't seem to be getting found by the plugin.

I will try creating the single-muso-album.php and see if that gets around this part of the problem. That combined with Abdelhadi Touil's help may just save my day.


ilowelife comments:

Ah, here's a puzzle.

I created the single-muso-album.php using the contents of page.php and placed it in the theme. As a test, I added a class to some of the output HTML.

When I look at my album post now, I do not see the test class in the markup, so it's obviously not picking up the right page.

I think I am just going to resort to using pages for these albums instead of the plugin.


John Cotton comments:

Are you sure you're not looking at a cached page? One of the pains of developing is making sure you're always looking at the output of the latest code and not so local or proxy cached version. Many of the really good hosters cache very aggressive which is great for your site performance, but a pain for developing.

If you are convinced you have the latest versions then something is seriously wrong with your set up (or, perhaps, the way that particular theme works).

I'd do a few things to check what was going on before I abandoned the plugin (which looks reasonably well written to me).

Stick these lines in your header.php (or somewhere you can easily see the output):


<?php
echo 'Templates:<br/>';
echo locate_template( 'page.php' );
echo '<br/>--<br/>';
echo locate_template( 'single-muso-album.php' );
echo '<br/>end templates:<br/>';


What do you see? If you don't get the names of the files in your theme, that's where you problem is. If you do get them, I'll be scratching my head....


ilowelife comments:

Ok. Not sure what was going on but I'm not seeing the right page template appear. The stack is page.php then single-muso-album

I think that I'm almost there, as you put it. I just need to twiddle the breadcrumb.

Thanks so much

2012-09-28

Plugarized answers:

The following plugin allows custom post types in breadcrumbs and is free.

http://mtekk.us/code/breadcrumb-navxt/

Yoas breadcrumbs also allows custom post types. http://wordpress.org/extend/plugins/breadcrumbs/

<blockquote>Make sure you have this in your custom post function for yoast:

'has_archive' => true,

Once you have that in place, the Yoast SEO plugin will let you select the custom post type as the parent page.</blockquote>


Plugarized comments:

The breadcrumb plugin implemented in the theme is over 4 years old, To be honest is better to disable this breadcrumb and implement Yoast, it provides better SEO and more control.

I am testing the sterling theme on my test website. http://auto-sal.es/wp/ i installed the discography plugin and imported 2 albums, on my breadcrumb it shows the correct permalink but the wrong title. you can check here;

http://auto-sal.es/wp/discography/01-chanson-to-e-by-magdalena/

The issue is that is that the plugin is not compatible with custom post types and I ultimately recommend disabling it.

2012-09-28

daas answers:

In my opinion, problem is not caused by the plugin at all. Your theme does not recognize custom post type and incorrectly handle its breadcrumbs, heading and description. I have never seen Sterling's code, so it is quiet difficult to find exact solution.
If I were you I would look after piece of code starting with:
<section class="small_banner">
and ending with:
</section>
It could be located in 'header.php' file of your template. ( See Appearance -> Editor )


ilowelife comments:

Thank you Max. There's a file in the theme called template-part-small-banner.php but I can't find the block you're referring to.

Note that the plugin developer also thinks that the theme is using single post instead of single page to display the custom post type.