Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** Breadcrumbs **** ( bbPress Forum - Twitter Bootstrap Breadcrumbs ) **********/
- /**
- * Output the page title as a breadcrumb
- *
- * @since bbp_shmooress (r2589)
- *
- * @param string $sep Separator. Defaults to '←'
- * @param bool $current_page Include the current item
- * @param bool $root Include the root page if one exists
- * @uses bbp_shmoo_get_breadcrumb() To get the breadcrumb
- */
- function bbp_shmoo_title_breadcrumb( $args = array() ) {
- echo bbp_shmoo_get_breadcrumb( $args );
- }
- /**
- * Output a breadcrumb
- *
- * @since bbp_shmooress (r2589)
- *
- * @param string $sep Separator. Defaults to '←'
- * @param bool $current_page Include the current item
- * @param bool $root Include the root page if one exists
- * @uses bbp_shmoo_get_breadcrumb() To get the breadcrumb
- */
- function bbp_shmoo_breadcrumb( $args = array() ) {
- echo bbp_shmoo_get_breadcrumb( $args );
- }
- /**
- * Return a breadcrumb ( forum -> topic -> reply )
- *
- * @since bbp_shmooress (r2589)
- *
- * @param string $sep Separator. Defaults to '←'
- * @param bool $current_page Include the current item
- * @param bool $root Include the root page if one exists
- *
- * @uses get_post() To get the post
- * @uses bbp_shmoo_get_forum_permalink() To get the forum link
- * @uses bbp_shmoo_get_topic_permalink() To get the topic link
- * @uses bbp_shmoo_get_reply_permalink() To get the reply link
- * @uses get_permalink() To get the permalink
- * @uses bbp_shmoo_get_forum_post_type() To get the forum post type
- * @uses bbp_shmoo_get_topic_post_type() To get the topic post type
- * @uses bbp_shmoo_get_reply_post_type() To get the reply post type
- * @uses bbp_shmoo_get_forum_title() To get the forum title
- * @uses bbp_shmoo_get_topic_title() To get the topic title
- * @uses bbp_shmoo_get_reply_title() To get the reply title
- * @uses get_the_title() To get the title
- * @uses apply_filters() Calls 'bbp_shmoo_get_breadcrumb' with the crumbs
- * @return string Breadcrumbs
- */
- function bbp_shmoo_get_breadcrumb( $args = array() ) {
- // Turn off breadcrumbs
- if ( apply_filters( 'bbp_shmoo_no_breadcrumb', is_front_page() ) )
- return;
- // Define variables
- $front_id = $root_id = 0;
- $ancestors = $crumbs = $tag_data = array();
- $pre_root_text = $pre_front_text = $pre_current_text = '';
- $pre_include_root = $pre_include_home = $pre_include_current = true;
- /** Home Text *********************************************************/
- // No custom home text
- if ( empty( $args['home_text'] ) ) {
- // Set home text to page title
- $front_id = get_option( 'page_on_front' );
- if ( !empty( $front_id ) ) {
- $pre_front_text = get_the_title( $front_id );
- // Default to 'Home'
- } else {
- $pre_front_text = __( 'Home', 'bbpress' );
- }
- }
- /** Root Text *********************************************************/
- // No custom root text
- if ( empty( $args['root_text'] ) ) {
- $page = bbp_get_page_by_path( bbp_get_root_slug() );
- if ( !empty( $page ) ) {
- $root_id = $page->ID;
- }
- $pre_root_text = bbp_get_forum_archive_title();
- }
- /** Includes **********************************************************/
- // Root slug is also the front page
- if ( !empty( $front_id ) && ( $front_id == $root_id ) )
- $pre_include_root = false;
- // Don't show root if viewing forum archive
- if ( bbp_is_forum_archive() )
- $pre_include_root = false;
- // Don't show root if viewing page in place of forum archive
- if ( !empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id == get_the_ID() ) ) )
- $pre_include_root = false;
- /** Current Text ******************************************************/
- // Forum archive
- if ( bbp_is_forum_archive() ) {
- $pre_current_text = bbp_get_forum_archive_title();
- // Topic archive
- } elseif ( bbp_is_topic_archive() ) {
- $pre_current_text = bbp_get_topic_archive_title();
- // View
- } elseif ( bbp_is_single_view() ) {
- $pre_current_text = bbp_get_view_title();
- // Single Forum
- } elseif ( bbp_is_single_forum() ) {
- $pre_current_text = bbp_get_forum_title();
- // Single Topic
- } elseif ( bbp_is_single_topic() ) {
- $pre_current_text = bbp_get_topic_title();
- // Single Topic
- } elseif ( bbp_is_single_reply() ) {
- $pre_current_text = bbp_get_reply_title();
- // Topic Tag (or theme compat topic tag)
- } elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && !bbp_is_topic_tag_edit() ) ) {
- // Always include the tag name
- $tag_data[] = bbp_get_topic_tag_name();
- // If capable, include a link to edit the tag
- if ( current_user_can( 'manage_topic_tags' ) ) {
- $tag_data[] = '<a href="' . bbp_get_topic_tag_edit_link() . '" class="bbp-edit-topic-tag-link">' . __( '(Edit)', 'bbpress' ) . '</a>';
- }
- // Implode the results of the tag data
- $pre_current_text = sprintf( __( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) );
- // Edit Topic Tag
- } elseif ( bbp_is_topic_tag_edit() ) {
- $pre_current_text = __( 'Edit', 'bbpress' );
- // Single
- } else {
- $pre_current_text = get_the_title();
- }
- /** Parse Args ********************************************************/
- // Parse args
- $defaults = array(
- // HTML
- 'before' => '<ul class="breadcrumb">',
- 'after' => '</ul>',
- 'sep' => __( '›', 'bbpress' ),
- 'pad_sep' => 1,
- // Home
- 'include_home' => $pre_include_home,
- 'home_text' => $pre_front_text,
- // Forum root
- 'include_root' => $pre_include_root,
- 'root_text' => $pre_root_text,
- // Current
- 'include_current' => $pre_include_current,
- 'current_text' => $pre_current_text
- );
- $r = bbp_parse_args( $args, $defaults, 'get_breadcrumb' );
- extract( $r );
- /** Ancestors *********************************************************/
- // Get post ancestors
- if ( is_page() || is_single() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() )
- $ancestors = array_reverse( get_post_ancestors( get_the_ID() ) );
- // Do we want to include a link to home?
- if ( !empty( $include_home ) || empty( $home_text ) )
- $crumbs[] = '<li><a href="' . trailingslashit( home_url() ) . '" class="bbp-breadcrumb-home">' . $home_text . '</a><span class="divider"> /</span></li>';
- // Do we want to include a link to the forum root?
- if ( !empty( $include_root ) || empty( $root_text ) ) {
- // Page exists at root slug path, so use its permalink
- $page = bbp_get_page_by_path( bbp_get_root_slug() );
- if ( !empty( $page ) ) {
- $root_url = get_permalink( $page->ID );
- // Use the root slug
- } else {
- $root_url = get_post_type_archive_link( bbp_get_forum_post_type() );
- }
- // Add the breadcrumb
- $crumbs[] = '<li><a href="' . $root_url . '" class="bbp-breadcrumb-root">' . $root_text . '</a><span class="divider"> /</span></li>';
- }
- // Ancestors exist
- if ( !empty( $ancestors ) ) {
- // Loop through parents
- foreach( (array) $ancestors as $parent_id ) {
- // Parents
- $parent = get_post( $parent_id );
- // Switch through post_type to ensure correct filters are applied
- switch ( $parent->post_type ) {
- // Forum
- case bbp_get_forum_post_type() :
- $crumbs[] = '<li><a href="' . bbp_get_forum_permalink( $parent->ID ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a><span class="divider"> /</span></li>';
- break;
- // Topic
- case bbp_get_topic_post_type() :
- $crumbs[] = '<li><a href="' . bbp_get_topic_permalink( $parent->ID ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a><span class="divider"> /</span></li>';
- break;
- // Reply (Note: not in most themes)
- case bbp_get_reply_post_type() :
- $crumbs[] = '<li><a href="' . bbp_get_reply_permalink( $parent->ID ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a><span class="divider"> /</span></li>';
- break;
- // WordPress Post/Page/Other
- default :
- $crumbs[] = '<li><a href="' . get_permalink( $parent->ID ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a><span class="divider"> /</span></li>';
- break;
- }
- }
- // Edit topic tag
- } elseif ( bbp_is_topic_tag_edit() ) {
- $crumbs[] = '<a href="' . get_term_link( bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id() ) . '" class="bbp-breadcrumb-topic-tag">' . sprintf( __( 'Topic Tag: %s', 'bbpress' ), bbp_get_topic_tag_name() ) . '</a>';
- }
- /** Current ***********************************************************/
- // Add current page to breadcrumb
- if ( !empty( $include_current ) || empty( $pre_current_text ) )
- $crumbs[] = '<li><span class="active">' . $current_text . '</span></li>';
- /** Separator *********************************************************/
- // Wrap the separator in a span before padding and filter
- if ( !empty( $sep ) )
- $sep = '<span class="bbp-breadcrumb-separator">' . $sep . '</span>';
- // Pad the separator
- if ( !empty( $pad_sep ) )
- $sep = str_pad( $sep, strlen( $sep ) + ( (int) $pad_sep * 2 ), ' ', STR_PAD_BOTH );
- /** Finish Up *********************************************************/
- // Filter the separator and breadcrumb
- $sep = apply_filters( 'bbp_shmoo_breadcrumb_separator', $sep );
- $crumbs = apply_filters( 'bbp_shmoo_breadcrumbs', $crumbs );
- // Build the trail
- $trail = !empty( $crumbs ) ? ( $before . implode( $sep, $crumbs ) . $after ) : '';
- return apply_filters( 'bbp_shmoo_get_breadcrumb', $trail, $crumbs, $r );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement