0

I got a wp theme that can display a category page with thumbs (of posts)

    $cat_args = array(
      'orderby' => 'name',
      'order' => 'ASC',
   // 'number' => $num,
      'child_of' => 0,
      'show_count' => 1
      );
 $categories =   get_categories($cat_args); 
 foreach($categories as $category) {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "Toutes les vidéos de %s" ), $category->name ) . '" ' . '><div class="video video_">';
echo '<h3>' . $category->name.'</h3>';


 $post_args = array(
  'numberposts' => 1,
  'category' => $category->term_id 
);
$posts = get_posts($post_args);
foreach($posts as $post) {
?>
    <div class="thumbnail">
        <?php if ( has_post_thumbnail() ) { echo the_post_thumbnail();}else{ ?>
            <img src="<?php echo get_post_meta($post->ID,   get_option('wptuber_thumbs'), true); ?>" alt="<?php the_title(); ?>" />
        <?php } ?>
        </div>
    <?php 
    } 
echo '<em>Toutes les videos ('.$category->count.')</em>';
echo '</div></a>';
} 
?>

but when I try to change it to get the same with "tag" every thing works fine but the thumb is not showing. Can someone help me?

    $tag_args = array(
    'orderby' => 'name',
    'order' => 'ASC',
 // 'number' => $num,
    'child_of' => 0,
    'show_count' => 1
     );
$tags =   get_tags($tag_args); 
foreach($tags as $tag) {
   echo '<a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "Toutes les videos de %s" ), $tag->name ) . '" ' . '><div class="video video_">';
echo '<h3>' . $tag->name.'</h3>';


$post_args = array(
  'numberposts' => 1,
  'tag' => $tag->term_id 
);
$posts = get_posts($post_args);
foreach($posts as $post) {
?>
    <div class="thumbnail">
        <?php if ( has_post_thumbnail() ) { echo the_post_thumbnail();}else{ ?>
            <img src="<?php echo get_post_thumbnail($post->ID, get_option('wptuber_thumbs'), true); ?>" alt="<?php the_title(); ?>" />
        <?php } ?>
        </div>
    <?php 
    }

    echo '<em>Toutes les videos de ('.$tag->count.')</em>';
echo '</div></a>';
} 

What am I missing?

1 Answer 1

1

What am i missing?

'tag' may be a valid argument for get_posts() via WP_Query, but requires the tag slug in that case. Try using 'tag_id' instead.

get_posts() apparently enables 'category', but expects the the ID, even though in WP_Query the same argument is 'cat' (vs. 'category_name', et al).

A little confusing, perhaps, altogether. I know it still confuses me.

https://codex.wordpress.org/Template_Tags/get_posts https://codex.wordpress.org/Class_Reference/WP_Query#Parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.