Last active
February 1, 2017 19:11
-
-
Save titomus/1cf1ec7c7ab79ab4c1d84f1ef0cc8e92 to your computer and use it in GitHub Desktop.
Codes Wordpress pour monter un Silo Seo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#lier le logo en header à la catégorie | |
add_filter( 'genesis_seo_title', 'child_header_title', 10, 3 ); | |
function child_header_title( $title, $inside, $wrap ) { | |
if(is_singular('post')){ | |
$category_id = get_the_category(); | |
$id = $category_id[0]->term_id; | |
$name = ucfirst($category_id[0]->name); | |
$inside = sprintf( '<a href="%s" title="%s">%s</a>', get_category_link( $id ),esc_attr( $name ), get_the_category_by_ID($id) ); | |
}else{ $inside = sprintf( '<a href="%s" title="%s">%s</a>', esc_url( home_url()),esc_attr( get_bloginfo( 'name' ) ), get_bloginfo( 'name' ) ); } | |
return sprintf( '<%1$s class="site-title">%2$s</%1$s>', $wrap, $inside ); | |
} | |
#widget des derniers articles de la catégorie | |
add_filter( 'widget_posts_args', 'silo_ja_widget_posts_args'); | |
function silo_ja_widget_posts_args($args) { | |
if ( is_category() or is_single() ) { //si categorie ou article | |
$category = get_the_category(); | |
return array( | |
'posts_per_page' => 5,//nombre d'articles | |
'no_found_rows' => true, | |
'post_status' => 'publish', | |
'ignore_sticky_posts' => true, | |
'cat' => $category[0]->term_id//id de la categorie | |
); | |
} | |
else { | |
return $args; | |
} | |
} | |
#shortcode des derniers commentaires d'une catégorie | |
add_shortcode('last_comments', 'silo_ja_widget_comments_args'); | |
function silo_ja_widget_comments_args($args) { | |
extract( | |
shortcode_atts( | |
array( | |
'title' => 'Derniers Commentaires', | |
'num' => '5', | |
), | |
$args | |
) | |
); | |
$category = get_the_category(); | |
$firstCategory = $category[0]->term_id; | |
$i = 0; | |
$comments = get_comments("number=50&status=approve"); | |
$excerptLen = 50; | |
echo '<h4 class="widget-title widgettitle">'.$title.'</h4>'; | |
echo '<ul id="recentcomments">'; | |
foreach ($comments as $comment){ | |
$comm_post_id = $comment->comment_post_ID; | |
if (in_category($firstCategory, $comm_post_id)){ | |
$i++; | |
if($i >= $num){break;}else{ | |
// Output the comment, author and whatever you need | |
// I'll just output the comment excerpt to keep my code simple | |
$aRecentComment = get_comment($comment->comment_ID); | |
$aRecentCommentTxt = trim( mb_substr( strip_tags( apply_filters( 'comment_text', $aRecentComment->comment_content )), 0, $excerptLen )); | |
if(strlen($aRecentComment->comment_content)>$excerptLen){ | |
$aRecentCommentTxt .= "..."; | |
} | |
echo '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('<span class="recentcommentsauthor">%1$s</span> a dit %2$s', 'widgets'), get_comment_author_link($comment->comment_ID), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . $aRecentCommentTxt . '</a>') . '</li>'; | |
} | |
} | |
} | |
echo '</ul>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code à retrouver dans l'article Silo Seo Wordpress