简体   繁体   中英

How to retrieve Posts in WordPress into a custom HTML Table?

My question is How can I create two rows with 2 columns <td> in a Dynamic way, receiving posts from the query_post() !

I spent sometime using the query_post() in WordPress to create this :

在此处输入图片说明

I made a drastic mistake and this is the snippet:

http://pastebin.com/cp6RSTQQ

this gives me the recent posts of a category called watch using the offset in the query_post() in this way:

<?php
            $args = array( 'posts_per_page' => 1, 'order'=> 'DESC','category' => 'watch', 'orderby' => 'post_date','offset' => 0 );
            $postslist = get_posts( $args );
            foreach ($postslist as $post) :  setup_postdata($post); ?> 

            <td class="leftBoxes">

            <div class="imgMargin"> <?php the_post_thumbnail(); ?> </div>
           <br>

            <div class="boxScrollsBlogsView">
            <h2><?php the_title(); ?> </h2>
            <P> 
            <?php the_excerpt(); ?> 
            </P>
            <h3><a href="<?php the_permalink(); ?>"> ReadMore</a></h3>
            </div>

            </td>
            <?php endforeach; ?>

After I wanted to go forward, I realized that I can't do pagination in the way I wrote th code!

I have looked at this QUESTION on wordpress website, but I can't understand how he is doing it honestly!

Just deleted the the right box and I changed the code to look like this

<?php
        $args = array( 'posts_per_page' => 4, 'order'=> 'DESC','category' => 'watch', 'orderby' => 'post_date','offset' => 0 );
        $postslist = get_posts( $args );
        foreach ($postslist as $post) :  setup_postdata($post); ?> 

        <td class="leftBoxes">

        <div class="imgMargin"> <?php the_post_thumbnail(); ?> </div>
       <br>

        <div class="boxScrollsBlogsView">
        <h2><?php the_title(); ?> </h2>
        <P> 
        <?php the_excerpt(); ?> 
        </P>
        <h3><a href="<?php the_permalink(); ?>"> ReadMore</a></h3>
        </div>

        </td>
        <?php endforeach; ?>

and it creates one TD after another eventually it goes to the new line for making rows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM