Accueil > WordPress > Comment afficher l’image à la une sur les articles pour Genesis

Comment afficher l’image à la une sur les articles pour Genesis

mercredi 4 mai 2016, par Philippe Donnart

Par défaut les images à la une ne s’affichent pas toujours pour les thèmes sous Genesis, voici un bout de code qui devrait vous aider.

J’avais testé le plugin Display Featured Image for Genesis mais il y a une solution toute simple, ajouter le code suivant dans le functions.php

//* Display featured image before single post title
add_action( 'genesis_before_entry', 'featured_post_image', 8 );
function featured_post_image() {
  if ( ! is_singular( 'post' ) )  return;
	the_post_thumbnail('post-image');
}

Pour afficher l’image à la une sur les pages et articles
 5 -> image avant le titre
 15 -> image après l’article

add_action( 'genesis_entry_header', 'single_post_featured_image', 15 );

Ou

function single_post_featured_image() {
	
	if ( ! is_singular() )
		return;
	
	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img );
	
}

Sans le lien sur l’image (le dimensions de l’image sont celles choisies pour l’affichage dans les archives)

add_action( 'genesis_entry_header', 'single_post_featured_image', 15 );

function single_post_featured_image() {
	
	if ( ! is_singular() )
		return;
	
	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( $img );
	
}

Trouvé ici -> https://wpsites.net/web-design/display-featured-image-before-or-after-entry-title-on-single-posts-pages/

Je me garde sous le coude le code que j’avais mis sur Traducsongs

add_shortcode('field', 'field_func');
// image à la une
add_action( 'genesis_entry_header', 'single_post_featured_image', 15 );

function single_post_featured_image() {
	
	if ( ! is_singular() )
		return;
	
	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( $img );
	
}

function field_func2($atts) {
   global $post;
   $name = $atts['name'];
   if (empty($name)) return;

   return get_post_meta($post->ID, $name, true);
}

add_shortcode('field', 'field_func2');