I’m going through some difficulty creating a wordpress page template which outputs a table containing the data I require.
I currently all the information correctly output but, the table and title reappears for every loop. Is it possible, and how, can I loop all the data into one table?
My page template is:
<?php
/**
* Template Name: GamesDBTable
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<?php get_header(); ?>
<div id="container">
<div id="content">
<?php
$type = 'game';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'paged' => $paged,
'orderby'=> 'title',
'order' => 'ASC',
);
$temp = $wp_query; // assign ordinal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
?>
<?php
if (have_posts()) : while (have_posts()) : the_post();
$game_identifier = get_game_identifier();
$developer = strip_tags( get_the_term_list( $wp_query->post->ID, 'developer', '', ', ', '' ) );
$genre = strip_tags( get_the_term_list( $wp_query->post->ID, 'genre', '', ', ', '' ) );
$payment = get_field('th_payment_model');
$arating = get_post_meta( $wp_query->post->ID, 'rating_average');
$rating = (($arating[0]) / 10);
;?>
<h4>Games Database</h2>
<table class="publisher">
<thead>
<tr>
<th>Game Name <a href="#" class="asc">a</a> <a href="#" class="desc">d</a></th>
<th>Genre <a href="#" class="asc">a</a> <a href="#" class="desc">d</a></th>
<th>Payment Model <a href="#" class="asc">a</a> <a href="#" class="desc">d</a></th>
<th>Developer <a href="#" class="asc">a</a> <a href="#" class="desc">d</a></th>
<th>Rating <a href="#" class="asc">a</a> <a href="#" class="desc">d</a></th>
</tr>
</thead>
<tbody>
<tr>
<td><a href='<?php the_permalink() ?>'
rel='bookmark' title='<?php the_title(); ?>'>
<?php the_title(); ?></a></td>
<td><?php echo $genre; ?></td>
<td><?php echo $payment; ?></td>
<td><?php echo $developer; ?></td>
<td><?php print_r($rating); ?>/10</td>
</tr>
</tbody>
</table>
<?php
endwhile; endif; ?>
<!-- PAGINATION --><hr class="light"/><br style="clear:both;"/><div class="aligncenter"><?php echo vpt_pagination(); ?></div>
</div><!-- #content -->
<?php get_sidebar(); ?>
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Help is greatly appreciated!
Just take the table header out of the loop and only include the table rows inside the loop;