WordPress en Tumblr : le flux RSS aussi
Il est facile dans un thème de WordPress de manipuler l’affichage des différents éléments d’un Post. Si je devais récapituler ce que chacun de mes formats de Post contient, ça donnerait :
| content | excerpt | featured image | custom field | |
| Article | Oui | Facultatif | Facultatif | – |
| Lien | Oui | – | – | Oui |
| Image | Oui | – | Oui | – |
| Citation | Oui | Oui | – | Oui |
| Brève | Oui | – | – | – |
Avec cette répartition des infos, des Conditional Tags et des Templates de Post Format, je peux manipuler à ma guise l’affichage différencié.
Modifier le flux RSS
Seul le flux RSS subsistait dans l’affichage érroné de mes billets. En effet, il n’affiche que le titre (title) et le contenu (content). Par contre, pas de featured image, d’excerpt ou de custom field.
Il fallait y remédier grâce aux filtres WordPress.
Lien
Image
Citation
Code
Voici le code présent dans mon functions.php :
add_filter('the_content_feed', 'tumblr_content');
function tumblr_content($content)
{
global $post;
$format = get_post_format($post->ID);
$permalink = get_permalink($post->ID);
if ($format == 'image') {
$thumbnail = get_the_post_thumbnail($post->ID, 'medium');
$content = '<p>' . $thumbnail . '</p>' . $content;
}
if ($format == 'quote') {
$excerpt = $post->post_excerpt;
$content = '<blockquote><p>' . $excerpt . '</p></blockquote>' . $content;
}
if ($format == 'link') {
$content = $content . '<p><a href="' . $permalink . '">∞ Permalien</a></p>';
}
return $content;
}
add_filter('the_permalink_rss', 'tumblr_link');
function tumblr_link($link)
{
global $post;
$format = get_post_format($post->ID);
if ($format == 'link') {
$link_url = get_post_meta($post->ID, 'link_url', true);
$link = $link_url;
}
return $link;
}
add_filter('the_title_rss', 'tumblr_title');
function tumblr_title($title)
{
global $post;
$format = get_post_format($post->ID);
if ($format == 'link') {
$title = '→ ' . $title;
}
return $title;
}
PS : je devrais peut-être rajouter le même syntax highlighter que pour mon tuto WordPress.



