WordPress et Référencement

Logo SeoMix
  • Accueil
  • Codes
  • Témoignages
  • Acheter le guide
  • Contact
Fil d'ariane
Vous êtes ici : WP-Referencement » Codes WordPress » Ajouter un chemin de navigation à WordPress

Un guide de 120 pages pour maîtriser le référencement naturel de WordPress

J'achète le guide

Ajouter un chemin de navigation à WordPress

Tweeter

Copiez-collez ce code dans le fichier functions.php :

//***Fil d'Arianne
function myget_category_parents($id, $link = false,$separator = '/',$nicename = false,$visited = array()) {
    $chain = '';$parent = &get_category($id);
        if (is_wp_error($parent))return $parent;
        if ($nicename)$name = $parent->name;
        else $name = $parent->cat_name;
        if ($parent->parent && ($parent->parent != $parent->term_id ) && !in_array($parent->parent, $visited)) {
                $visited[] = $parent->parent;$chain .= myget_category_parents( $parent->parent, $link, $separator, $nicename, $visited );}
        if ($link) $chain .= '<span typeof="v:Breadcrumb"><a href="' . get_category_link( $parent->term_id ) . '" title="Voir tous les articles de '.$parent->cat_name.'" rel="v:url" property="v:title">'.$name.'</a></span>' . $separator;
        else $chain .= $name.$separator;
        return $chain;}
function mybread() {
    global $wp_query;$ped=get_query_var('paged');$rendu = '<div xmlns:v="http://rdf.data-vocabulary.org/#">';
    if ( !is_home() ) {$rendu .= '<span id="breadex">Vous &ecirc;tes ici :</span> <span typeof="v:Breadcrumb"><a title="'. get_bloginfo('name') .'" id="breadh" href="'.home_url().'" rel="v:url" property="v:title">'. get_bloginfo('name') .'</a></span>';}
    elseif ( is_home() ) {$rendu .= '<span id="breadex">Vous &ecirc;tes ici :</span> <span typeof="v:Breadcrumb">Accueil de '. get_bloginfo('name') .'</span>';}
    if ( is_category() ) {
        $cat_obj = $wp_query->get_queried_object();$thisCat = $cat_obj->term_id;$thisCat = get_category($thisCat);$parentCat = get_category($thisCat->parent);
        if ($thisCat->parent != 0) $rendu .= " &raquo; ".myget_category_parents($parentCat, true, " &raquo; ", true);
        if ($thisCat->parent == 0) {$rendu .= " &raquo; ";}
        if ( $ped <= 1 ) {$rendu .= single_cat_title("", false);}
        elseif ( $ped > 1 ) {
            $rendu .= '<span typeof="v:Breadcrumb"><a href="' . get_category_link( $thisCat ) . '" title="Voir tous les articles de '.single_cat_title("", false).'" rel="v:url" property="v:title">'.single_cat_title("", false).'</a></span>';}}
    elseif ( is_author()){
        global $author;$user_info = get_userdata($author);$rendu .= " &raquo; Articles de l'auteur ".$user_info->display_name."</span>";}
    elseif ( is_tag()){
        $tag=single_tag_title("",FALSE);$rendu .= " &raquo; Articles sur le th&egrave;me <span>".$tag."</span>";}
        elseif ( is_date() ) {
                if ( is_day() ) {
                        global $wp_locale;
                        $rendu .= '<span typeof="v:Breadcrumb"><a href="'.get_month_link( get_query_var('year'), get_query_var('monthnum') ).'" rel="v:url" property="v:title">'.$wp_locale->get_month( get_query_var('monthnum') ).' '.get_query_var('year').'</a></span> ';
                        $rendu .= " &raquo; Archives pour ".get_the_date();}
        else if ( is_month() ) {
                        $rendu .= " &raquo; Archives pour ".single_month_title(' ',false);}
        else if ( is_year() ) {
                        $rendu .= " &raquo; Archives pour ".get_query_var('year');}}
    elseif ( is_archive() && !is_category()){
                $posttype = get_post_type();
        $tata = get_post_type_object( $posttype );
        $var = '';
        $the_tax = get_taxonomy( get_query_var( 'taxonomy' ) );
        $titrearchive = $tata->labels->menu_name;
        if (!empty($the_tax)){$var = $the_tax->labels->name.' ';}
                if (empty($the_tax)){$var = $titrearchive;}
        $rendu .= ' &raquo; Archives sur "'.$var.'"';}
    elseif ( is_search()) {
        $rendu .= " &raquo; R&eacute;sultats de votre recherche <span>&raquo; ".get_search_query()."</span>";}
    elseif ( is_404()){
        $rendu .= " &raquo; 404 Page non trouv&eacute;e";}
    elseif ( is_single()){
        $category = get_the_category();
        $category_id = get_cat_ID( $category[0]->cat_name );
        if ($category_id != 0) {
            $rendu .= " &raquo; ".myget_category_parents($category_id,TRUE,' &raquo; ')."<span>".the_title('','',FALSE)."</span>";}
        elseif ($category_id == 0) {
                $post_type = get_post_type();
            $tata = get_post_type_object( $post_type );
                $titrearchive = $tata->labels->menu_name;
                $urlarchive = get_post_type_archive_link( $post_type );
            $rendu .= ' &raquo; <span typeof="v:Breadcrumb"><a class="breadl" href="'.$urlarchive.'" title="'.$titrearchive.'" rel="v:url" property="v:title">'.$titrearchive.'</a></span> &raquo; <span>'.the_title('','',FALSE).'</span>';}}
    elseif ( is_page()) {
        $post = $wp_query->get_queried_object();
        if ( $post->post_parent == 0 ){$rendu .= " &raquo; ".the_title('','',FALSE)."";}
        elseif ( $post->post_parent != 0 ) {
            $title = the_title('','',FALSE);$ancestors = array_reverse(get_post_ancestors($post->ID));array_push($ancestors, $post->ID);
            foreach ( $ancestors as $ancestor ){
                if( $ancestor != end($ancestors) ){$rendu .= '&raquo; <span typeof="v:Breadcrumb"><a href="'. get_permalink($ancestor) .'" rel="v:url" property="v:title">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a></span>';}
else {$rendu .= ' &raquo; '.strip_tags(apply_filters('single_post_title',get_the_title($ancestor))).'';}}}}
    if ( $ped >= 1 ) {$rendu .= ' (Page '.$ped.')';}
    $rendu .= '</div>';
    echo $rendu;}

Copiez ensuite ce code à l'endroit où vous voulez faire apparaître le chemin de navigation dans WordPress :

<?php if (function_exists('mybread')) mybread();?>

Cet article de SeoMix traite également de ce sujet : Fil d'ariane et BreadCrumbs


Découvrez aussi :

Optimisez la balise TITLE de votre thème WordPress Optimisez la balise TITLE de votre thème WordPress
Lister les auteurs d’un blog WordPress Lister les auteurs d’un blog WordPress

Plus d'informations sur cet article

Article rédigé par +Daniel Roch.

© 2012 SeoMix
Guide par Daniel Roch & édité par Olivier Andrieu
Design du site par Willy Bahuaud.
Intégration par Daniel sur le CMS WordPress.