Hey there,
To put WordPress posts into an html table, in the file where you are editing code, start the HTML table’s opening tag:
<table>
Then, start running a custom query using this (http://codex.wordpress.org/Class_Reference/WP_Query)
Make sure to include the columns and rows in the table for each loop iteration. For example, inside the loop for each one, you might do something like this:
<tr>
<td><?php the_title(); ?></td>
<td><?php the_content(); ?></td>
<td><?php the_date('Y-m-d'); ?></td>
</tr>
And then after the loop is done, close the html table again
</table>
Hello,
Thanks for responding so quickly.
I thought that’s what I did. Here is my code.
<?php
/*
Template Name: PostTable Template
*/
?>
<table>
<tr>
<th>Title</th>
<th>Created Date</th>
<th>Author</th>
<th>Hits</th>
</tr>
<?php while ( have_posts() ) : the_post(); ?>
<tr>
<td>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></td>
<td><?php the_time(‘F jS, Y’); ?></td>
<td><?php the_author_posts_link(); ?></td>
<td><?php get_HitsMechanic();?></td>
</tr>
<?php endwhile; ?>
</table>
Isn’t this enough?
You’re getting close – but you haven’t actually gotten the posts in order to loop through them. WordPress Page Templates don’t automatically have a “loop” built into them – like other standardized pages in WordPress Themes (like archive.php).
So you need to do some extra setup in order to make the loop work.
Check out that link I sent you because it has some great examples. Specifically, you need something like this in order to get the loops contents:
//Set up the args we want to make this loop custom:
$args = array(
'post_type' => 'post',
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
Your table stuff goes here and then we end the loop
}
}
Thanks a million!
Now I got it working!
Yay!
You have a great day!