WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Breadcrumbs and custom post types (3 posts)

  1. Roy
    Member
    Posted 3 years ago #

    I know, this is not the first thread, but I'm not enough of a coder to manage myself. I want to make the following kind of breadcrumbs.
    home -> posttitle (for normal posts)
    home -> custom post type -> post title (for custom post types)

    There are breadcrumbs scripts enough, such as this one. They all seem to be category based. I also tried a few plugins, but I can't manage to make them do what I want. A few remarks.
    1. I have a multi install, several plugins see the main site as 'home' and the subsite next. I would not mind home->sub->c.p.t.->title, but everything I tried to far either has home->title or sub->title. Both are fine, but I just wanted to make a note about the network.
    2. A bigger problem seems to be that I have several custom post types, but the "slug" is not always the same as the page that I use to display them. I do not remember why I made it so, but I do know that it took a very long time to get the c.p.t.'s running, so I suppose this setup was the only one working properly. So I have for example gangleri.nl/musicreviews/music-blog in which music-blog is a page to display c.p.t.'s that in single view have as url gangleri.nl/musicreviews/blog/title. I don't know if this could cause the malfunctioning, but another c.p.t. for which both the page and the slug are "stories" works with one plugin, not with another.

    In most cases, the c.p.t. (or some of them) do not make part of the breadcrumbs, sometimes they display as a space or blank line with no link.

    What I would like is a simple code for my functions.php for breadcrumbs just for website (custom post type) title. I don't mind if the c.p.t. part is the c.p.t. slug or the page name, but I suppose the first is easier to make. There need not be any reference to categories, tags, dates or whatever.

    I intend to use the breadcrumbs only in the single.php, if that makes any difference.

    Thanks is advance.

  2. Roy
    Member
    Posted 3 years ago #

    I ran into this nice little script that looks like a promising start:

    function the_breadcrumb() {
    	if (!is_home()) {
    		echo '<a href="';
    		echo get_option('home');
    		echo '">';
    		bloginfo('name');
    		echo "</a> » ";
    		if (is_category() || is_single()) {
    			the_category('title_li=');
    			if (is_single()) {
    				echo " » ";
    				the_title();
    			}
    		} elseif (is_page()) {
    			echo the_title();
    		}
    	}
    }

    Like I said, I don't want the category part, so I hoped it would be as simple as replacing the_category with something like the_post_types, but that's not a valid tag? There is a get_post_types, but I think that's not what I need.

  3. Roy
    Member
    Posted 3 years ago #

    Ah, the Breadcrumb NavXT is flexible enough to make what I want. Why didn't I notice that the first three times I installed it and before I started to look for a non-plugin sollution :-) ?

Topic Closed

This topic has been closed to new replies.

About this Topic