Wordpress页面模板
我在创建wordpress页面模板时遇到了一些困难,该模板输出一个包含我所需数据的表 我当前正确地输出了所有信息,但每个循环都会重新显示表和标题。是否可能,以及如何将所有数据循环到一个表中 我的页面模板是:Wordpress页面模板,wordpress,Wordpress,我在创建wordpress页面模板时遇到了一些困难,该模板输出一个包含我所需数据的表 我当前正确地输出了所有信息,但每个循环都会重新显示表和标题。是否可能,以及如何将所有数据循环到一个表中 我的页面模板是: <?php /** * Template Name: GamesDBTable * * Selectable from a dropdown menu on the edit page screen. */ ?> <?php get_header(); ?>
<?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(); ?>
游戏数据库
游戏名称
体裁
支付模式
开发商
评级
/10
非常感谢您的帮助 只需将表头从循环中取出,并且只包含循环中的表行
<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>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$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);
?>
<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>
<?php endwhile; endif; ?>
</tbody>
</table>
游戏名称
体裁
支付模式
开发商
评级
/10
有效,所有内容都显示在一个表中。然而,现在看来,除了页面标题之外,没有任何东西能够获得正确的数据。现在,体裁、支付、开发者和评级只需要回复第一篇文章的数据。有办法解决吗?对不起,伙计,这是我太草率了,没有在为变量赋值的部分复制。我已经更新过了,效果很好。非常感谢McNab!