最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

design - How to display posts i grid photo

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

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.

发布评论

评论列表(0)

  1. 暂无评论