am trying to make grid view of posts for a specific category any one to help
<?php
$args = array(
'post_type' => 'post',
'category_name' => 'featured',
'posts_per_page' => 5,
'post__not_in' => get_option( 'sticky_posts' )
);
$the_query = new WP_Query( $args );?>
am trying to make grid view of posts for a specific category any one to help
<?php
$args = array(
'post_type' => 'post',
'category_name' => 'featured',
'posts_per_page' => 5,
'post__not_in' => get_option( 'sticky_posts' )
);
$the_query = new WP_Query( $args );?>
Share
Improve this question
edited Mar 6, 2020 at 15:50
fuxia♦
107k39 gold badges255 silver badges459 bronze badges
asked Mar 6, 2020 at 10:47
Mulusa ProMulusa Pro
75 bronze badges
1 Answer
Reset to default 0You need to build the query and then loop through it afterwards.
<ul>
<?php
//Your Args
$args = array(
'post_type' => 'post',
'category_name' => 'featured',
'posts_per_page' => 5,
'post__not_in' => get_option( 'sticky_posts' )
);
// The Query
$query = new WP_Query( $args );
// The Loop
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
?>
</ul>
Then where the code echos the title, you would include your HTML to build your grid. And obviously have extra CSS elsewhere to style it as a grid.