Lister articles wordpress par images à la une

sia - Modifié par jordane45 le 24/02/2014 à 22:38
 sia - 25 févr. 2014 à 16:00
Bonjour,
voilà j'ai créé une page qui doit contenir tous les articles d une catégorie. Seulement au lieu de lister le nom de l'article qui me renvoie vers l'article en question, je voudrais que mes liens soient les imags à la une des articles. du genre:
<a href="lien_article-1"><img  src="adress_img_a_la_une_article_1" alt="img1"/></a>
<a href="lien_article-2"><img  src="adress_img_a_la_une_article_2" alt="img2"/></a>

j'ai trouvé ceci http://www.bibichette.com/afficher-articles-categorie/ qui fonctionne bien , mais je n'ai pas les images , mais les noms des articles.

Je ne trouve pas, pouvez vous m'aider ? Merci

Edit : Ajout des balises de code

3 réponses

J'ai finalement trouvé !
<div id="gk-mainbody">
<?php while ( have_posts() ) : the_post(); ?>
<?php gk_content_nav(); ?>
<?php get_template_part( 'content', 'single' );
// récupère titre de la page qui est la même que celle de ma catégorie
$cat=get_the_title();
//récupère id de la catégorie
$id=get_cat_id($cat);
?>
<!-- requête affichants les posts de la catégorie dont id est $id -->
<?php query_posts("cat=$id");
while ( have_posts() ) : the_post();
echo '<li><a href="'.get_permalink().'">'
.get_the_post_thumbnail(
$post->ID,
array(150,150),
array('class' => 'post_thumbnail')
).'</a></li>';
endwhile;
// Reset Query
wp_reset_query();
?>

<?php endwhile; ?>
2
Ou bien sous formes de balises img
<div id="gk-mainbody">
<?php while ( have_posts() ) : the_post(); ?>
<?php gk_content_nav(); ?>
<?php get_template_part( 'content', 'single' );
// récupère titre de la page qui est la même que celle de ma catégorie
$cat=get_the_title();
//récupère id de la catégorie
$id=get_cat_id($cat);
?>
<!-- requête affichants les posts de la catégorie dont id est $id -->
<?php query_posts("cat=$id");?>
<div classs="img_articles_categ">
<?php while ( have_posts() ) : the_post();
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo '<a href="'.get_permalink().'"><img src="'
.$feat_image.'" alt="img_post"</a>';
endwhile;
// Reset Query
wp_reset_query();
?></div>

<?php endwhile; ?>

</div>
Bien sûr il faudra voir le css
1
jordane45 Messages postés 38157 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 4 mai 2024 344
24 févr. 2014 à 22:57
Bonsoir,

Sans certitude (je n'ai pas de wordpress sous la main), je pense que tu peux t'inspire d'un truc du genre :

<?php
	$args = array( 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'ASC', 'post_mime_type' => 'image' ,'post_status' => null, 'numberposts' => null, 'post_parent' => $post->ID );

$attachments = get_posts($args);
if ($attachments) {
	foreach ( $attachments as $attachment ) {
        $alt = get_post_meta($attachment->ID,'_wp_attachment_image_alt', true);
	$image_title = $attachment->post_title;
	$caption = $attachment->post_excerpt;
	$description = $image->post_content;
?>
<a href="<?php echo wp_get_attachment_url( $attachment->ID); ?>" 
rel="lightbox" title="<?php echo $image_title; ?>">
<img src="<?php echo get_bloginfo('template_directory');?>
/timthumb.php?h=75&w=75&zc=1&src=<?php echo wp_get_attachment_url( $attachment->ID , false ); ?>" 
alt="<?php echo $alt; ?>" width="75" height="75" border="0" /></a>
 <?php } } ?>


Trouvé sur le site de wordpress (si on a un souci avec un logiciel.. autant commencer par chercher sur son site... )
http://wordpress.org/support/topic/get-title-alt-or-caption-from-media-library-and-insert-into-theme

0
je vais essayer merci :)
0
je dois bien mettre ce code dans le fichier php de ma page créée? car ca ne m affiche rien du tout...merci voila ma page
<?php

/*
* Template Name: Model_category
*/

global $wp_query, $post;

$fullwidth = true;

gk_load('header');
gk_load('before', null, array('sidebar' => false));

?>

<div id="gk-mainbody">
<?php while ( have_posts() ) : the_post(); ?>
<?php gk_content_nav(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php
$args = array( 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'ASC', 'post_mime_type' => 'image' ,'post_status' => null, 'numberposts' => null, 'post_parent' => $post->ID );

$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
$alt = get_post_meta($attachment->ID,'_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
$caption = $attachment->post_excerpt;
$description = $image->post_content;
?>
<a href="<?php echo wp_get_attachment_url( $attachment->ID); ?>"
rel="lightbox" title="<?php echo $image_title; ?>">
<img src="<?php echo get_bloginfo('template_directory');?>
/timthumb.php?h=75&w=75&zc=1&src=<?php echo wp_get_attachment_url( $attachment->ID , false ); ?>"
alt="<?php echo $alt; ?>" width="75" height="75" border="0" /></a>
<?php } } ?>

<?php endwhile; ?>

</div>

<?php

gk_load('after', null, array('sidebar' => false));
gk_load('footer');

// EOF
0
Rejoignez-nous