| | 1810 | |
| | 1811 | /** |
| | 1812 | * Outputs breadcrumb navigation with user arguments for post type and other parameters |
| | 1813 | */ |
| | 1814 | |
| | 1815 | function wp_breadcrumbs( $args = '' ) { |
| | 1816 | $defaults = array( |
| | 1817 | 'post_type' => 'post', |
| | 1818 | 'home_label' => __( 'Home' ), |
| | 1819 | 'item_sep' => ' › ', |
| | 1820 | 'cat_sep' => ' | ', |
| | 1821 | 'show_title' => true, |
| | 1822 | 'start_wrap' => '', |
| | 1823 | 'end_wrap' => '', |
| | 1824 | ); |
| | 1825 | $args = wp_parse_args ( $args, $defaults ); |
| | 1826 | if ( 'post' == $args['post_type'] ) { |
| | 1827 | $home_url = home_url( '/' ); |
| | 1828 | $cat_list = get_the_category_list(); |
| | 1829 | if ( ! empty ( $cat_list) ) { |
| | 1830 | $post_category = get_the_category_list( $args['cat_sep'] ) . $args['item_sep']; |
| | 1831 | } else { |
| | 1832 | $post_category = null; |
| | 1833 | } |
| | 1834 | |
| | 1835 | if ( $args['show_title'] == true ) { |
| | 1836 | $post_title = '<span itemprop="title">' . get_the_title() . '</span>'; |
| | 1837 | } else { |
| | 1838 | $post_title = null; |
| | 1839 | } |
| | 1840 | |
| | 1841 | echo $args['start_wrap'] . '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> |
| | 1842 | <a href=" ' . $home_url . '" itemprop="url">' . $args['home_label'] . '</a> ' . $args['item_sep'] . $post_category . $post_title . '</div>' . $args['end_wrap']; |
| | 1843 | } |
| | 1844 | elseif ( 'page' == $args['post_type'] ) { |
| | 1845 | global $post; |
| | 1846 | $home_url = home_url( '/' ); |
| | 1847 | if ( $args['show_title'] == true ) { |
| | 1848 | $post_title = '<span itemprop="title">' . get_the_title() . '</span>'; |
| | 1849 | } else { |
| | 1850 | $post_title = null; |
| | 1851 | } |
| | 1852 | if ( $post->post_parent == true ) { |
| | 1853 | $parent_title = get_the_title ($post->post_parent); |
| | 1854 | $parent_link = get_the_permalink ($post->post_parent); |
| | 1855 | $parent_output = '<a href="' . $parent_link . '">' . $parent_title . '</a>' . $args['item_sep']; |
| | 1856 | } else { |
| | 1857 | $parent_output = null; |
| | 1858 | } |
| | 1859 | |
| | 1860 | echo $args['start_wrap'] . '<div class="nav codon-breadcrumbs"> |
| | 1861 | <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> |
| | 1862 | <a href=" ' . $home_url . '" itemprop="url">' . $args['home_label'] . '</a>' . $args['item_sep'] . $parent_output . $post_title . '</div>' . $args['end_wrap']; |
| | 1863 | } else { |
| | 1864 | if ( post_type_exists ( $args['post_type'] ) == true ) { |
| | 1865 | global $post; |
| | 1866 | $home_url = home_url( '/' ); |
| | 1867 | if ( $args['show_title'] == true ) { |
| | 1868 | $post_title = '<span itemprop="title">' . get_the_title() . '</span>'; |
| | 1869 | } else { |
| | 1870 | $post_title = null; |
| | 1871 | } |
| | 1872 | if ( $post->post_parent == true ) { |
| | 1873 | $parent_title = get_the_title ($post->post_parent); |
| | 1874 | $parent_link = get_the_permalink ($post->post_parent); |
| | 1875 | $parent_output = '<a href="' . $parent_link . '">' . $parent_title . '</a>' . $args['item_sep']; |
| | 1876 | } else { |
| | 1877 | $parent_output = null; |
| | 1878 | } |
| | 1879 | if ( get_post_type_archive_link( $args['post_type'] ) == true ) { |
| | 1880 | $post_type_name = ucwords ( $args['post_type'] ); |
| | 1881 | $archive_url = get_post_type_archive_link( $args['post_type'] ); |
| | 1882 | $post_type_archive_link = '<a href="' . $archive_url . '">' . $post_type_name . '</a>' . $args['item_sep']; |
| | 1883 | } else { |
| | 1884 | $post_type_archive_link = null; |
| | 1885 | } |
| | 1886 | |
| | 1887 | echo $args['start_wrap'] . '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> |
| | 1888 | <a href=" ' . $home_url . '" itemprop="url">' . $args['home_label'] . '</a>' . $args['item_sep'] . $parent_output . $post_type_archive_link . $post_title . '</div>' . $args['end_wrap']; |
| | 1889 | } else { |
| | 1890 | // no output if post type is invalid |
| | 1891 | return; |
| | 1892 | } |
| | 1893 | } |
| | 1894 | |
| | 1895 | } |