好的,非常简单的任务,我只是不擅长 PHP。
我有一个页面,我想在其中使用样式列表列出一些员工。这是页面 - http://www.themontessoripeople.co.uk/montesori/?post_type=people
我下载了一个“自定义内容类型”插件并添加了“人”的内容类型并添加了相应的字段。现在我想过滤我通过名为“层次结构”的自定义字段添加的帖子。
这是我希望页面显示的方式 - http://i47.tinypic.com/oqymwh.jpg
自定义字段“hierarchy”包含“management”、“babies_room”和“toddlers_room”的房间变量。
如何修改下面的代码以按其中包含的值过滤帖子<?php print_custom_field('hierarchy'); ?>
?
<?php $col = 1; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ($col == 1) echo "<div class=\"row\">"; ?>
<div class="post col<?php echo $col;?>" id="post-<?php the_ID(); ?>">
<div class="people-spacer">
<div class="people"><a class="animate" >
<div class="bio">
<p class="titles"><?php the_title(); ?><br/>
<span class="job"> <?php print_custom_field('job'); ?></span> </p><br />
</div>
<img src="<?php print_custom_field('staff_image:to_image_src'); ?>" width="160" height="160" alt="<?php the_title(); ?>-image" />
</div>
<div class="people-link-edit"><?php edit_post_link('Edit Post', ''); ?></div>
</div>
</div>
<?php if ($col == 1) echo "</div>"; (($col==1) ? $col=2 : $col=2); ?>
<?php endwhile; ?>
谢谢,本。
这是显示两组过滤结果以供参考的工作代码 -
<?php $col = 1; ?>
<?php if (have_posts()) : ?>
<div class="text-box">
<h2>Management</h2>
<?php while (have_posts()) : the_post(); ?>
<?php if (get_custom_field('hierarchy') != "management") continue; ?>
<?php if ($col == 1) echo "<div class=\"row\">"; ?>
<div class="post col<?php echo $col;?>" id="post-<?php the_ID(); ?>">
<div class="people-spacer">
<div class="people"><a class="animate" >
<div class="bio">
<p class="titles">
<?php the_title(); ?>
<br/>
<span class="job"> <?php print_custom_field('job'); ?></span> </p>
<br />
</div>
<img src="<?php print_custom_field('staff_image:to_image_src'); ?>" width="160" height="160" alt="<?php the_title(); ?>-image" /> </div>
<div class="people-link-edit">
<?php edit_post_link('Edit Post', ''); ?>
</div>
</div>
</div>
<?php if ($col == 1) echo "</div>"; (($col==1) ? $col=2 : $col=2); ?>
<?php endwhile; ?>
</div><!-- close text box -->
<div class="text-box">
<h2>Babies Room</h2>
<?php while (have_posts()) : the_post(); ?>
<?php if (get_custom_field('hierarchy') != "babies_room") continue; ?>
<?php if ($col == 1) echo "<div class=\"row\">"; ?>
<div class="post col<?php echo $col;?>" id="post-<?php the_ID(); ?>">
<div class="people-spacer">
<div class="people"><a class="animate" >
<div class="bio">
<p class="titles">
<?php the_title(); ?>
<br/>
<span class="job"> <?php print_custom_field('job'); ?></span> </p>
<br />
</div>
<img src="<?php print_custom_field('staff_image:to_image_src'); ?>" width="160" height="160" alt="<?php the_title(); ?>-image" /> </div>
<div class="people-link-edit">
<?php edit_post_link('Edit Post', ''); ?>
</div>
</div>
</div>
<?php if ($col == 1) echo "</div>"; (($col==1) ? $col=2 : $col=2); ?>
<?php endwhile; ?>
</div><!-- close text box -->