| | 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 | 'echo' => true, |
| | 1825 | ); |
| | 1826 | |
| | 1827 | $params = wp_parse_args ( $args, $defaults ); |
| | 1828 | |
| | 1829 | $args = apply_filters( 'wp_breadcrumb_args', $params ); |
| | 1830 | |
| | 1831 | // get args and values |
| | 1832 | global $post; |
| | 1833 | $home_url = home_url( '/' ); |
| | 1834 | |
| | 1835 | if ( $args['show_title'] ) { |
| | 1836 | $post_title = get_the_title(); |
| | 1837 | } else { |
| | 1838 | $post_title = null; |
| | 1839 | } |
| | 1840 | |
| | 1841 | $cat_list = get_the_category_list(); |
| | 1842 | if ( ! empty ( $cat_list) ) { |
| | 1843 | $post_category = get_the_category_list( $args['cat_sep'] ) . $args['item_sep']; |
| | 1844 | } else { |
| | 1845 | $post_category = null; |
| | 1846 | } |
| | 1847 | |
| | 1848 | if ( $args['show_title'] == true ) { |
| | 1849 | $post_title = '<span itemprop="title">' . get_the_title() . '</span>'; |
| | 1850 | } else { |
| | 1851 | $post_title = null; |
| | 1852 | } |
| | 1853 | |
| | 1854 | if ( $args['echo'] ) { |
| | 1855 | $print = true; |
| | 1856 | } else { |
| | 1857 | $print = false; |
| | 1858 | } |
| | 1859 | |
| | 1860 | // output for posts |
| | 1861 | if ( 'post' == $args['post_type'] ) { |
| | 1862 | $output = $args['start_wrap'] . '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href=" ' . $home_url . '" itemprop="url">' . $args['home_label'] . '</a> ' . $args['item_sep'] . $post_category . $post_title . '</div>' . $args['end_wrap']; |
| | 1863 | if ( $print ) { |
| | 1864 | echo $output; |
| | 1865 | } else { |
| | 1866 | return $output; |
| | 1867 | } |
| | 1868 | } |
| | 1869 | |
| | 1870 | // output for pages |
| | 1871 | elseif ( 'page' == $args['post_type'] ) { |
| | 1872 | if ( $post->post_parent ) { |
| | 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 | |
| | 1880 | $output = $args['start_wrap'] . '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> |
| | 1881 | <a href=" ' . $home_url . '" itemprop="url">' . $args['home_label'] . '</a>' . $args['item_sep'] . $parent_output . $post_title . '</div>' . $args['end_wrap']; |
| | 1882 | if ( $print ) { |
| | 1883 | echo $output; |
| | 1884 | } else { |
| | 1885 | return $output; |
| | 1886 | } |
| | 1887 | } else { |
| | 1888 | |
| | 1889 | // output for passed custom post types |
| | 1890 | if ( post_type_exists ( $args['post_type'] ) ) { |
| | 1891 | |
| | 1892 | if ( get_post_type_archive_link( $args['post_type'] ) ) { |
| | 1893 | $post_type_name = ucwords ( $args['post_type'] ); |
| | 1894 | $archive_url = get_post_type_archive_link( $args['post_type'] ); |
| | 1895 | $post_type_archive_link = '<a href="' . $archive_url . '">' . $post_type_name . '</a>' . $args['item_sep']; |
| | 1896 | } else { |
| | 1897 | $post_type_archive_link = null; |
| | 1898 | } |
| | 1899 | |
| | 1900 | $output = $args['start_wrap'] . '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> |
| | 1901 | <a href=" ' . $home_url . '" itemprop="url">' . $args['home_label'] . '</a>' . $args['item_sep'] . $post_type_archive_link . $post_title . '</div>' . $args['end_wrap']; |
| | 1902 | if ( $print ) { |
| | 1903 | echo $output; |
| | 1904 | } else { |
| | 1905 | return $output; |
| | 1906 | } |
| | 1907 | |
| | 1908 | } else { |
| | 1909 | // nothing if post type is invalid |
| | 1910 | return; |
| | 1911 | } |
| | 1912 | } |
| | 1913 | |
| | 1914 | } |