Remarque : le plugin YARPP gère désormais cela de manière native
Pour faire apparaître les articles relatifs :
[pastacode lang= »php » message= » » highlight= » » provider= »manual » manual= »%3C%3Fphp%20if%20(function_exists(‘related_posts’))%20%7B%20related_posts()%3B%20%7D%20%3F%3E »/]
Voici d’autres codes complémentaires liés à YARPP mais non présents dans le livre.
Activez les miniatures d’article dans functions.php :
[pastacode lang= »php » message= » » highlight= » » provider= »manual » manual= »add_theme_support(‘post-thumbnails’)%3B%0Aadd_image_size(‘thumb200’%2C%20200%2C%20200%2C%20true)%3B »/]
Récupérer une image à la une si elle n’est pas définie dans functions.php :
[pastacode lang= »php » message= » » highlight= » » provider= »manual » manual= »function%20get_post_thumbnail()%20%7B%0A%20%24files%20%3D%20get_children(‘post_parent%3D’.get_the_ID().’%26post_type%3Dattachment%26post_mime_type%3Dimage’)%3B%0A%20if(%24files)%20%3A%0A%20%24keys%20%3D%20array_reverse(array_keys(%24files))%3B%0A%20%24j%3D0%3B%0A%20%24num%20%3D%20%24keys%5B%24j%5D%3B%0A%20%24image%3Dwp_get_attachment_image(%24num%2C%20’large’%2C%20false)%3B%0A%20%24imagepieces%20%3D%20explode(‘%22’%2C%20%24image)%3B%0A%20%24imagepath%20%3D%20%24imagepieces%5B1%5D%3B%0A%20%24thumb%3Dwp_get_attachment_thumb_url(%24num)%3B%0A%20return%20%24thumb%3B%0A%20endif%3B%0A%7D »/]
Le template des articles relatifs :
[pastacode lang= »php » message= » » highlight= » » provider= »manual » manual= »%3C%3Fphp%20if%20(function_exists(%22icl_register_string%22))%20%7Bicl_register_string(%22Yet%20Another%20Related%20Posts%20Plugin%22%2C%22related%20posts%20header%22%2C%22Related%20Posts%22)%3Bicl_register_string(%22Yet%20Another%20Related%20Posts%20Plugin%22%2C%22no%20related%20posts%20message%22%2C%22No%20related%20posts.%22)%3B%7D%3F%3E%0A%3C%3Fphp%20if%20(%24related_query-%3Ehave_posts())%3A%3F%3E%0A%20%20%3Cdiv%20class%3D%22solcol%22%3E%0A%20%20%20%20%3C%3Fphp%20while%20(%24related_query-%3Ehave_posts())%20%3A%20%24related_query-%3Ethe_post()%3B%20%3F%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22solb%22%3E%0A%20%20%20%20%20%20%20%20%3Ca%20href%3D%22%3C%3Fphp%20the_permalink()%20%3F%3E%22%20rel%3D%22bookmark%22%20title%3D%22%3C%3Fphp%20the_title()%3B%20%3F%3E%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3Cimg%20src%3D%22%3C%3Fphp%20%24id%20%3D%20%24post-%3EID%3B%24thumbnail_src%20%3D%20wp_get_attachment_image_src(get_post_thumbnail_id(%24id)%2C%20’thumb200’)%3B%24thumb%3D%24thumbnail_src%5B0%5D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(%24thumb%20!%3D%20%22%22)%20%7B%24thumbdirectory%20%3D%20get_bloginfo(‘template_directory’)%3B%24thumb%3D%20%24nothumb.’%2Fimages%2Fnothumb.jpg’%3B%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20echo%20%24thumb%3B%3F%3E%22%20alt%3D%22%3C%3Fphp%20the_title()%3B%20%3F%3E%22%20class%3D%22article-thumb%22%20height%3D%22200%22%20width%3D%22200%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3Cspan%3E%3C%3Fphp%20the_title()%3B%20%3F%3E%3C%2Fspan%3E%0A%20%20%20%20%20%20%20%20%3C%2Fa%3E%0A%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%20%20%3Cdiv%20class%3D%22solbe%22%3E%3C%2Fdiv%3E%0A%20%20%20%20%3C%3Fphp%20endwhile%3B%20%3F%3E%0A%20%20%3C%2Fdiv%3E%0A%3C%3Fphp%20else%3A%20%3F%3E%0A%20%20%3Cp%3EPas%20encore%20d’article%20similaires%3C%2Fp%3E%0A%3C%3Fphp%20endif%3B%20%3F%3E »/]
Mettre en page les articles relatifs :
[pastacode lang= »css » message= » » highlight= » » provider= »manual » manual= ».solb%2C.solbe%7Btext-align%3Acenter%7D%0A.solcol%7Bmargin%3A0.5em%200%201em%3Bpadding-top%3A0.2em%3Bwidth%3A900px%7D%0A.solb%7Bdisplay%3Atable-cell%3Bmargin%3A0%204px%200%204px%3Bpadding%3A6px%3Bwidth%3A200px%3Bbackground%3A%23e9f0f8%3Bborder%3A1px%20solid%20%23b2d6ff%7D%0A.solbe%7Bdisplay%3Atable-cell%3Bmargin%3A0%204px%200%204px%3Bpadding%3A6px%3Bwidth%3A6px%3Bbackground%3Atransparent%7D%0A.solb%3Ahover%7Bbackground%3A%23b2d6ff%7D%0A.solb%20a%7Btext-decoration%3Anone%7D%0A.solb%20a%20span%3Ahover%7Btext-decoration%3Aunderline%7D%0A.solb%7B-moz-box-shadow%3A0%202px%203px%20rgba(0%2C0%2C0%2C.4)%3B-webkit-box-shadow%3A0%202px%203px%20rgba(0%2C0%2C0%2C.4)%3Bbox-shadow%3A0%202px%203px%20rgba(0%2C0%2C0%2C.4)%7D%0A.solb%7Bborder-radius%3A7px%3B-moz-border-radius%3A7px%3B-khtml-border-radius%3A7px%3B-webkit-border-radius%3A7px%7D »/]
Cet article de SeoMix parle en détail des articles relatifs de YARPP.
28 novembre 2018 at 13 h 24 min
Bonjour, depuis peu YARPP n’existe plus. Auriez vous une plugin alternatif à recommander ?
28 novembre 2018 at 15 h 07 min
Pas pour le moment malheureusement