这是我的WordPress模板文件。它获取6个最近的帖子,并在每个rpw的两列中显示这6个帖子。列div是变量:$hol=1和$hol=2。
这是我的模板文件的代码:
<div id="page-full-width"><?php query_posts('showposts=6'); ?>
<?php $hol = 1; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if (in_category('3')) continue; ?>
<?php if (in_category('4')) continue; ?>
<?php if ($hol == 1) echo "<div class='"main-content'">"; ?>
<div class="large-6 columns post hol<?php echo $hol;?>" id="post-<?php the_ID(); ?>">
<?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?>
<?php } else { ?>
<?php } ?>
<h2><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?><br></p>
<?php if ($hol == 2) echo "</div>";
(($hol==1) ? $hol=2 : $hol=1); ?>
</div><!--/post-->
<?php endwhile; ?>
<?php endif; ?>
我尝试了几种解决方案,比如将线路改为
<?php if ($hol == 3) echo "</div>";
(($hol==1) ? $hol=3 : $hol=2 : $hol=1); ?>
但它总是导致一个白色屏幕。我的问题是:是否可以修改查询并将内容显示在3列而不是2列中(当然,每个div都是"大4列")?
我可以仅从自定义帖子类型(即作业)查询帖子吗?
谢谢。
下面呈现的是3列结构,而不是两列结构。id为"页面全宽"的Div在此代码中未关闭。希望你知道它在哪里关闭。
<div id="page-full-width">
<?php query_posts('post_type'=> 'jobs', 'showposts=6'); ?>
<?php $hol = 1; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if (in_category('3')) continue; ?>
<?php if (in_category('4')) continue; ?>
<div class="main-content">
<?php for($hol;$hol<=3;$hol++){ ?>
<div class="large-4 columns post hol<?php echo $hol;?>" id="post-<?php the_ID(); ?>">
<?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?>
<?php } else { ?>
<?php } ?>
<h2><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?><br></p>
</div>
<?php } ?>
</div><!--end .main-content-->
<?php endwhile; ?>
<?php endif; ?>
对于仅从自定义帖子类型"jobs"查询帖子,您可以更新"query_posts"如下:
query_posts( array( 'post_type'=>'jobs', 'posts_per_page'=>6 ) );
希望这能有所帮助。