WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Breacrumb fails to display on author pages is author has no posts (9 posts)

  1. Jonathan
    Member
    Posted 1 year ago #

    I am trying to get this breadcrumb function to dispay on author pages, even if the author has no posts. For some reasons, it works fine if the author has a post, but fails completely if they do not. Because most of my "authors" will in fact just be "members" and will never post, this does not work at all.

    I have tried to explore the code of Justin Tadlocks's Breadcrumb Trail plugin, which doesn't display a crumb reagardless of if the author has posted, but with no luck, nothing I do maked any difference.

    PLEASE HELP!

    ( and please don't tell me to just use the plugin, I like to avoid dependeding on plugins whenever possible.)

    function limelight_breadcrumbs()	{
        $css_class = ''; // just in case the id="crumbs" isn't enough
                         // and you'd also like a class on the wrapper
        $show_on_home = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
        $delimiter = "ยป"; // delimiter between crumbs
                                // if delimiter is set to "li" then crumbs becomes an unordered list.
        $home = 'Home'; // text for the 'Home' link
        $show_current = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
        $before = '<span class="current">'; // tag before the current crumb
        $after = '</span>'; // tag after the current crumb
    
        if($delimiter == "li") {
            $crumb_tag = "ul";
            $crumb_list = TRUE;
        } else {
            $crumb_tag = "div";
            $crumb_list = FALSE;
        }
    
        global $post,$wp_query;
        $homeLink = get_bloginfo('url');
        if (is_home() || is_front_page()) {
            if ($show_on_home == 1) {
                echo '<' . $crumb_tag . ' id="breadcrumbs" class="' . $css_class . '">';
                    if($crumb_list) echo '<li>';
                        echo '<a href="' . $homeLink . '">' . $home . '</a>';
                    if($crumb_list) echo '</li>';
                echo '</' . $crumb_tag . '>';
            }
        } else {
            echo '<' . $crumb_tag . ' id="breadcrumbs" class="' . $css_class . '">';
            if($crumb_list) echo '<li>';
                echo '<a href="' . $homeLink . '">' . $home . '</a>';
            echo ($crumb_list) ? '</li>' : ' ' . $delimiter . ' ';
    
            if ( is_category()) {
                $cat_obj = $wp_query->get_queried_object();
                $this_cat = $cat_obj->term_id;
                $this_cat = get_category($this_cat);
                $parentCat = get_category($this_cat->parent);
                if ($this_cat->parent != 0) {
                    if($crumb_list) echo '<li>';
                        echo(get_category_parents($parentCat, TRUE, ($crumb_list) ? '</li><li>' : ' ' . $delimiter . ' '));
                    if($crumb_list) echo '</li>';
                }
                if($crumb_list) echo '<li>';
                    echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
                if($crumb_list) echo '</li>';
    
    } elseif ( is_tax() ) {
    $post_type = get_post_type_object(get_post_type());
    $slug = $post_type->rewrite;
    
    		$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    
                    if($crumb_list) echo '<li>';
                        echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->name . '</a>';
     echo ($crumb_list) ? '</li>' : ' ' . $delimiter . ' ';
    if($crumb_list) echo '</li>';
    		$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' ));
    
     if($crumb_list) echo '<li>';
    
    				echo '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>';
    
     echo ($crumb_list) ? '</li><li>' : ' ' . $delimiter . ' '; 
    
    			}
    		}
    
    		$queried_object = $wp_query->get_queried_object();
    		echo $before . $queried_object->name . $after;
    if($crumb_list) echo '</li>';
    
    /*echo ($crumb_list) ? '</li><li>' : ' ' . $delimiter . ' ';*/
    
            } elseif ( is_search() ) {
                if($crumb_list) echo '<li>';
                    echo $before . 'Search results for "' . get_search_query() . '"' . $after;
                if($crumb_list) echo '</li>';
            } elseif ( is_day() ) {
                if($crumb_list) echo '<li>';
                    echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>';
                echo ($crumb_list) ? '</li><li>' : ' ' . $delimiter . ' ';
                    echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a>';
                echo ($crumb_list) ? '</li><li>' : ' ' . $delimiter . ' ';
                    echo $before . get_the_time('d') . $after;
                if($crumb_list) echo '</li>';
            } elseif ( is_month() ) {
                if($crumb_list) echo '<li>';
                    echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>';
                echo ($crumb_list) ? '</li><li>' : ' ' . $delimiter . ' ';
                    echo $before . get_the_time('F') . $after;
                if($crumb_list) echo '</li>';
            } elseif ( is_year() ) {
                if($crumb_list) echo '<li>';
                    echo $before . get_the_time('Y') . $after;
                if($crumb_list) echo '</li>';
            } elseif ( is_single() && !is_attachment() ) {
                if ( get_post_type() != 'post' ) {
                    $post_type = get_post_type_object(get_post_type());
                    $slug = $post_type->rewrite;
                    if($crumb_list) echo '<li>';
                        echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->name . '</a>';
                    if($crumb_list) echo '</li>';
                    if ($show_current == 1) {
                        echo ($crumb_list) ? '<li>' : ' ' . $delimiter . ' ';
                            echo $before . get_the_title() . $after;
                        if($crumb_list) echo '</li>';
                    }
                } else {
                    $cat = get_the_category(); $cat = $cat[0];
                    $cats = get_category_parents($cat, TRUE, ($crumb_list) ? '</li><li>' : ' ' . $delimiter . ' ');
                    if ($show_current == 0) {
                        if($crumb_list) $cats = substr($cats, 0, -4);
                        else $cats = substr($cats, 0, -2-(strlen($delimiter)) );
                    }
                    if($crumb_list) echo '<li>';
                        echo $cats;
                    if ($show_current == 1) {
                            echo $before . get_the_title() . $after;
                        if($crumb_list) echo '</li>';
                    }
                }
            } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
                $post_type = get_post_type_object(get_post_type());
                if($crumb_list) echo '<li>';
                    echo $before . $post_type->labels->name . $after;
                if($crumb_list) echo '</li>';
            } elseif ( is_attachment() ) {
                $parent = get_post($post->post_parent);
                $cat = get_the_category($parent->ID);
                $cat = $cat[0];
                echo get_category_parents($cat, TRUE, ($crumb_list) ? '</li><li>' : ' ' . $delimiter . ' ');
                    echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>';
                if($crumb_list) echo '</li>';
                if ($show_current == 1) {
                    if($crumb_list) echo '<li>';
                        echo $before . get_the_title() . $after;
                    if($crumb_list) echo '</li>';
                }
            } elseif ( is_page() && !$post->post_parent ) {
                if ($show_current == 1) {
                    if($crumb_list) echo '<li>';
                        echo $before . get_the_title() . $after;
                    if($crumb_list) echo '</li>';
                }
            } 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);
                $counter = 0;
                $breadcrumb_count = count($breadcrumbs);
                foreach ($breadcrumbs as $crumb) {
                    $counter++;
                    if($crumb_list) echo '<li>';
                        echo $crumb;
                    if($crumb_list) {
                        echo '</li>';
                    } else {
                        if($show_current == 1 || $counter!=$breadcrumb_count) {
                            echo ' ' . $delimiter . ' ';
                        }
                    }
                }
                if ($show_current == 1) {
                    if($crumb_list) echo '<li>';
                        echo $before . get_the_title() . $after;
                    if($crumb_list) echo '</li>';
                }
            } elseif ( is_tag() ) {
                if($crumb_list) echo '<li>';
                    echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
                if($crumb_list) echo '</li>';
            } elseif ( is_author() ) {
                global $author;
                $userdata = get_userdata($author);
                if($crumb_list) echo '<li>';
                    echo $before . 'Member Profile: ' . $userdata->display_name . $after;
                if($crumb_list) echo '</li>';
            } elseif ( is_404() ) {
                if($crumb_list) echo '<li>';
                    echo $before . 'Error 404' . $after;
                if($crumb_list) echo '</li>';
            }
            if ( get_query_var('paged') ) {
                if($crumb_list) echo '<li>';
                elseif ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
                    echo __('Page') . ' ' . get_query_var('paged');
                if($crumb_list) echo '</li>';
                elseif ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
            }
            echo '</' . $crumb_tag . '>';
        }
    }

    this author has a post:
    http://inthelimelight.net/~sandbox/profile/grandpa/

    and this one does not:
    http://inthelimelight.net/~sandbox/profile/bingo-bob/

  2. bcworkz
    Member
    Posted 1 year ago #

    It appears that is_author() does more than determine if the query is for an author or not, but if the user actually authored something. I don't quite follow the code, but it looks like is_author() returns false if there is no author in the post objects returned by the query. So if no posts, no author exists to trigger a TRUE.

    It appears you need to create an equivalent to a is_profile() tag somehow. Perhaps by the template used?

  3. Jonathan
    Member
    Posted 1 year ago #

    Thank you,

    Any idea how I might create and is_profile function?

  4. Jonathan
    Member
    Posted 1 year ago #

    What is truly making me tear my hair out over this one, is that withing author.php I can calls to display the author name, bio, etc., and these work regardless of whether the author has posted, but I can not get this to work in the breadcrumb no matter what I try.

    There MUST be an obvious and simple solution, but it's eluding me.

    BTW, to the person who deleted their reply, I don't want to use the plugin because I am developing this site for a clients, and hate making client websites reliant on them. If down the road the plugin stops working, or the author abandons it, then I end up having to fix a client's website, often without being paid. I don't mind fixing my own theme framework if it breaks, but don't want to waste time with anything else.

  5. Jonathan
    Member
    Posted 1 year ago #

    Well I fixed it by moving the "is_author" if statement up the line to before "is_search" and now everything works perfectly. Obviously there was some kind of conflict.

    If someone could explain what the reason for it was, I'd be curious. Otherwise, consider this one closed.

  6. marcogodles
    Member
    Posted 1 year ago #

    Hi there!
    maybe you can help me with a similar issue im having.
    I have author bio being outputted (name, avatar, description, etc) using author.php and everything gets displayed fine when the author has a post but if there is no post, none of the bio gets published, almost like it cant get the author ID.
    maybe its in the global call im doing?

    <?php
    global $post;
    $author_id=$post->post_author;
    ?>

    any help would be great!

  7. bcworkz
    Member
    Posted 1 year ago #

    @marco,
    author.php for twentyeleven theme? That behavior is by design. No posts, then no bio. Nothing to do with your global. You could create a simple child theme that has a custom author.php where the bio etc. is output regardless of post status.

  8. Jonathan
    Member
    Posted 1 year ago #

    @marcogodles

    I think you will find your answer here:
    http://codex.wordpress.org/Author_Templates

    read section on "$curauth"

  9. marcogodles
    Member
    Posted 1 year ago #

    Thank you!
    The "$curauth" worked with what i needed after a few tweaks :)

Topic Closed

This topic has been closed to new replies.

About this Topic