Skip to content

Commit

Permalink
Re Issue #81 replace is_single() with is_singular('post'); re Issue #84
Browse files Browse the repository at this point in the history
… adds filter to breadcrumb
  • Loading branch information
chipbennett committed Sep 1, 2012
1 parent 405700f commit 6fd343f
Showing 1 changed file with 62 additions and 39 deletions.
101 changes: 62 additions & 39 deletions functions/custom.php
Expand Up @@ -66,12 +66,15 @@ function oenology_get_context() {
} else if ( is_attachment() ) { } else if ( is_attachment() ) {
// Attachment Page // Attachment Page
$context = 'attachment'; $context = 'attachment';
} else if ( is_single() ) { } else if ( is_singular( 'post' ) ) {
// Single Blog Post // Single Blog Post
$context = 'single'; $context = 'single';
} else if ( is_page() ) { } else if ( is_page() ) {
// Static Page // Static Page
$context = 'page'; $context = 'page';
} else if ( is_singular() ) {
// Single Custom Post
$context = get_post_type();
} else if ( is_home() ) { } else if ( is_home() ) {
// Blog Posts Index // Blog Posts Index
$context = 'home'; $context = 'home';
Expand Down Expand Up @@ -107,7 +110,7 @@ function oenology_get_current_page_layout() {
$layout .= $custom_layout; $layout .= $custom_layout;
} }
} }
else if ( is_single() ) { else if ( is_singular( 'post' ) ) {
if ( 'gallery' == get_post_format() || 'image' == get_post_format() || 'video' == get_post_format() ) { if ( 'gallery' == get_post_format() || 'image' == get_post_format() || 'video' == get_post_format() ) {
$layout .= 'full'; $layout .= 'full';
} }
Expand Down Expand Up @@ -871,45 +874,36 @@ function oenology_get_404_content() {
*/ */
function oenology_breadcrumb() { function oenology_breadcrumb() {


$containerBefore = '<li id="breadcrumbs">'; $containerBefore = apply_filters( 'oenology_breadcrumb_container_before', '<li id="breadcrumbs">' );
$containerAfter = '</li>'; $containerAfter = apply_filters( 'oenology_breadcrumb_container_after', '</li>' );
$containerCrumb = '<div class="crumbs">'; $containerCrumb = apply_filters( 'oenology_breadcrumb_container_open', '<div class="crumbs">' );
$containerCrumbEnd = '</div>'; $containerCrumbEnd = apply_filters( 'oenology_breadcrumb_container_close', '</div>' );
$delimiter = ' &raquo; '; $delimiter = apply_filters( 'oenology_breadcrumb_delimiter', ' &raquo; ' );
$name = 'Home'; //text for the 'Home' link $name = apply_filters( 'oenology_breadcrumb_home_text', 'Home' ); //text for the 'Home' link
$blogname = 'Blog'; //text for the 'Blog' link $blogname = apply_filters( 'oenology_breadcrumb_blog_text', 'Blog' ); //text for the 'Blog' link
$currentBefore = apply_filters( 'oenology_breadcrumb_current_before', '<strong>' );
$currentAfter = apply_filters( 'oenology_breadcrumb_current_after', '</strong>' );
$baseLink = ''; $baseLink = '';
$hierarchy = ''; $hierarchy = '';
$currentLocation = ''; $currentLocation = '';
$currentBefore = '<strong>';
$currentAfter = '</strong>';
$currentLocationLink = ''; $currentLocationLink = '';
$crumbPagination = ''; $crumbPagination = '';
$home = home_url('/');


global $post; global $post;

// Start of Container
echo $containerBefore;
// Start of Breadcrumbs
echo $containerCrumb;


// Output the Base Link // Base Link
if ( is_front_page() ) { $baselink = ( is_front_page() ? '<strong>' . $name . '</strong>' : '<a href="' . $home . '">' . $name . '</a>' );
echo '<strong>' . $name . '</strong>';
} else {
$home = home_url('/');
$baseLink = '<a href="' . $home . '">' . $name . '</a>';
echo $baseLink;
}
// If static Page as Front Page, and on Blog Posts Index // If static Page as Front Page, and on Blog Posts Index
if ( is_home() && ( 'page' == get_option( 'show_on_front' ) ) ) { if ( is_home() && ( 'page' == get_option( 'show_on_front' ) ) ) {
echo $delimiter . '<strong>' . $blogname . '</strong>'; $hierarchy = $delimiter;
$currentLocation = $blogname;
} }
// If static Page as Front Page, and on Blog, output Blog link // If static Page as Front Page, and on Blog, output Blog link
if ( ! is_home() && ! is_page() && ! is_front_page() && ( 'page' == get_option( 'show_on_front' ) ) ) { if ( ! is_home() && ! is_page() && ! is_front_page() && ( 'page' == get_option( 'show_on_front' ) ) ) {
$blogpageid = get_option( 'page_for_posts' ); $hierarchy = $delimiter;
$bloglink = '<a href="' . get_permalink( $blogpageid ) . '">' . $blogname . '</a>'; $currentLocation = '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blogname . '</a>';
echo $delimiter . $bloglink;
} }
// Define Category Hierarchy Crumbs for Category Archive // Define Category Hierarchy Crumbs for Category Archive
if ( is_category() ) { if ( is_category() ) {
Expand Down Expand Up @@ -948,7 +942,7 @@ function oenology_breadcrumb() {
$hierarchy = $delimiter . sprintf( __( 'Posts Published in: %s', 'oenology' ), $date_string ); $hierarchy = $delimiter . sprintf( __( 'Posts Published in: %s', 'oenology' ), $date_string );
} }
// Define Category Hierarchy Crumbs for Single Posts // Define Category Hierarchy Crumbs for Single Posts
elseif ( is_single() && !is_attachment() ) { elseif ( is_singular( 'post' ) ) {
$cat = get_the_category(); $cat = get_the_category();
$cat = $cat[0]; $cat = $cat[0];
$hierarchy = $delimiter . get_category_parents( $cat, TRUE, $delimiter ); $hierarchy = $delimiter . get_category_parents( $cat, TRUE, $delimiter );
Expand All @@ -969,7 +963,20 @@ function oenology_breadcrumb() {
// Note: Titles are forced for attachments; the // Note: Titles are forced for attachments; the
// filename will be used if none is specified // filename will be used if none is specified
$currentLocation = get_the_title(); $currentLocation = get_the_title();
} }
// Define Taxonomy Crumbs for Custom Post Types
elseif ( is_singular( get_post_type() ) && ! is_singular( 'post' ) && ! is_page() && ! is_attachment() ) {
global $post;
$post_type_object = get_post_type_object( get_post_type() );
$post_type_name = $post_type_object->labels->name;
$post_type_slug = $post_type_object->name;
$taxonomies = get_object_taxonomies( get_post_type() );
$taxonomy = ( ! empty( $taxonomies ) ? $taxonomies[0] : false );
$terms = ( $taxonomy ? get_the_term_list( $post->ID, $taxonomy ) : false );
$hierarchy = $delimiter . '<a href="' . get_post_type_archive_link( $post_type_slug ) . '">' . $post_type_name . '</a>';
$hierarchy .= ( $terms ? $delimiter . $terms . $delimiter : $delimiter );
$currentLocation = get_the_title();
}
// Define Current Location for Parent Pages // Define Current Location for Parent Pages
elseif ( ! is_front_page() && is_page() && ! $post->post_parent ) { elseif ( ! is_front_page() && is_page() && ! $post->post_parent ) {
$hierarchy = $delimiter; $hierarchy = $delimiter;
Expand Down Expand Up @@ -1005,6 +1012,18 @@ function oenology_breadcrumb() {
$hierarchy = $delimiter . __( 'Tag Archive:', 'oenology' ) . ' '; $hierarchy = $delimiter . __( 'Tag Archive:', 'oenology' ) . ' ';
$currentLocation = single_tag_title( '' , FALSE ); $currentLocation = single_tag_title( '' , FALSE );
} }
// Define current location for Custom Taxonomy Archives
elseif ( is_tax() ) {
$post_type_object = get_post_type_object( get_post_type() );
$post_type_name = $post_type_object->labels->name;
$post_type_slug = $post_type_object->name;
global $wp_query;
$custom_tax = $wp_query->query_vars['taxonomy'];
$custom_tax_object = get_taxonomy( $custom_tax );
$hierarchy = $delimiter . '<a href="' . get_post_type_archive_link( $post_type_slug ) . '">' . $post_type_name . '</a>';
$hierarchy .= $delimiter .__( 'Archive for:', 'oenology' ) . ' ';
$currentLocation = single_term_title( '', false );
}
// Define current location for Author Archives // Define current location for Author Archives
elseif ( is_author() ) { elseif ( is_author() ) {
$hierarchy = $delimiter . __( 'Posts Written by:', 'oenology' ) . ' '; $hierarchy = $delimiter . __( 'Posts Written by:', 'oenology' ) . ' ';
Expand All @@ -1020,6 +1039,13 @@ function oenology_breadcrumb() {
$hierarchy = $delimiter . __( 'Post Format Archive:', 'oenology' ) . ' '; $hierarchy = $delimiter . __( 'Post Format Archive:', 'oenology' ) . ' ';
$currentLocation = get_post_format_string( get_post_format() ) . 's'; $currentLocation = get_post_format_string( get_post_format() ) . 's';
} }
// Define current location for Custom Post Type Archives
elseif ( is_post_type_archive( get_post_type() ) ) {
$hierarchy = $delimiter . __( 'Archive Index for:', 'oenology' ) . ' ';
$post_type_object = get_post_type_object( get_post_type() );
$post_type_name = $post_type_object->labels->name;
$currentLocation = $post_type_name;
}


// Build the Current Location Link markup // Build the Current Location Link markup
$currentLocationLink = $currentBefore . $currentLocation . $currentAfter; $currentLocationLink = $currentBefore . $currentLocation . $currentAfter;
Expand All @@ -1036,14 +1062,11 @@ function oenology_breadcrumb() {
$crumbPagination = ' (Page ' . get_query_var('page') . ') '; $crumbPagination = ' (Page ' . get_query_var('page') . ') ';
} }


// Output the resulting Breadcrumbs // Build the resulting Breadcrumbs

$breadcrumb = $containerBefore . $containerCrumb . $baselink . $hierarchy . $currentLocationLink . $crumbPagination . $containerCrumbEnd . $containerAfter;
echo $hierarchy; // Output Hierarchy
echo $currentLocationLink; // Output Current Location // Output the result
echo $crumbPagination; // Output page number, if Post or Page is paginated echo apply_filters( 'oenology_breadcrumb', $breadcrumb );
echo $containerCrumbEnd; // End of BreadCrumbs

echo $containerAfter; // End of Container


} }


Expand All @@ -1062,7 +1085,7 @@ function oenology_infobar_navigation() {
} }
} }


if ( is_single() && ! is_attachment() ) { if ( is_singular( 'post' ) && ! is_attachment() ) {
echo '<div class="prevnextpostlinks">'; echo '<div class="prevnextpostlinks">';
next_post_link( '%link', '&lArr; ' ); next_post_link( '%link', '&lArr; ' );
previous_post_link( '%link', ' &rArr;' ); previous_post_link( '%link', ' &rArr;' );
Expand Down

0 comments on commit 6fd343f

Please sign in to comment.