i wrote a widget and i want to use category template which is located in "themename"/template-parts/content.php".
<?php
// Category.php
while ( have_posts() ) : the_post();
get_template_part( 'content', '' );
endwhile;
?>
In my widget i used $myposts=get_posts(); and i want to use this data with the content.php template for sure. But i dont know what is the proper way to pass this data.
I tried this but it didnt work.
<?php
// Widget.php
$myposts = get_posts($another_array);
foreach($myposts as $post) {
include(locate_template('template-parts/content.php'));
}
?>
And my template file.
Post: <?php the_title(); ?>
Comment Count: <?php echo get_comments_number(); ?>
Url: <?php echo get_permalink(); ?>
I tried like this too. But still not working.
Post: <?php the_title($post->ID); ?>
Comment Count: <?php echo get_comments_number($post->ID); ?>
Url: <?php echo get_permalink($post->ID); ?>