Remarque : WordPress SEO gère désormais cela de manière native
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><a>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>';
if ( !is_home() ) {$rendu .= '<span id="breadex">Vous êtes ici :</span> <span><a title="'. get_bloginfo('name') .'" id="breadh" href="'.home_url().'" rel="v:url">'. get_bloginfo('name') .'</a></span>';}
elseif ( is_home() ) {$rendu .= '<span id="breadex">Vous êtes ici :</span> <span>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 .= " » ".myget_category_parents($parentCat, true, " » ", true);
if ($thisCat->parent == 0) {$rendu .= " » ";}
if ( $ped 1 ) {
$rendu .= '<span><a href="' . get_category_link( $thisCat ) . '" rel="v:url">'.single_cat_title("", false).'</a></span>';}}
elseif ( is_author()){
global $author;$user_info = get_userdata($author);$rendu .= " » Articles de l'auteur ".$user_info->display_name."</span>";}
elseif ( is_tag()){
$tag=single_tag_title("",FALSE);$rendu .= " » Articles sur le thème <span>".$tag."</span>";}
elseif ( is_date() ) {
if ( is_day() ) {
global $wp_locale;
$rendu .= '<span><a href="'.get_month_link( get_query_var('year'), get_query_var('monthnum') ).'" rel="v:url">'.$wp_locale->get_month( get_query_var('monthnum') ).' '.get_query_var('year').'</a></span> ';
$rendu .= " » Archives pour ".get_the_date();}
else if ( is_month() ) {
$rendu .= " » Archives pour ".single_month_title(' ',false);}
else if ( is_year() ) {
$rendu .= " » 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 .= ' » Archives sur "'.$var.'"';}
elseif ( is_search()) {
$rendu .= " » Résultats de votre recherche <span>» ".get_search_query()."</span>";}
elseif ( is_404()){
$rendu .= " » 404 Page non trouvée";}
elseif ( is_single()){
$category = get_the_category();
$category_id = get_cat_ID( $category[0]->cat_name );
if ($category_id != 0) {
$rendu .= " » ".myget_category_parents($category_id,TRUE,' » ')."<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 .= ' » <span><a class="breadl" href="'.$urlarchive.'" title="'.$titrearchive.'" rel="v:url">'.$titrearchive.'</a></span> » <span>'.the_title('','',FALSE).'</span>';}}
elseif ( is_page()) {
$post = $wp_query->get_queried_object();
if ( $post->post_parent == 0 ){$rendu .= " » ".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 .= '» <span><a href="'. get_permalink($ancestor) .'" rel="v:url">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a></span>';}
else {$rendu .= ' » '.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 :
Cet article de SeoMix traite également de ce sujet : Fil d’ariane et BreadCrumbs
Laisser un commentaire