How to display posts i grid photo
-
19-04-2021 - |
Vra
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 );?>
Oplossing
You 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.
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan wordpress.stackexchange