OK, very simple task, I'm just not good at PHP.
I have a page where I want to list some staff using a styled list. Here is the page all working fine, I just need to divide the results - /?post_type=people
I downloaded a "custom content type" plugin and added the content type of "people" and added the appropriate fields. Now I want to filter the posts I have added by the custom field called "hierarchy".
Here is how I want the page to display:
Notice in the image I have headings for each group of posts filtered by the room. The custom field "hierarchy" contains the room variables of either "management", "babies_room" and "toddlers_room".
How do I amend the code below to filter the posts by the value held within <?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; ?>
OK, very simple task, I'm just not good at PHP.
I have a page where I want to list some staff using a styled list. Here is the page all working fine, I just need to divide the results - http://www.themontessoripeople.co.uk/montesori/?post_type=people
I downloaded a "custom content type" plugin and added the content type of "people" and added the appropriate fields. Now I want to filter the posts I have added by the custom field called "hierarchy".
Here is how I want the page to display:
Notice in the image I have headings for each group of posts filtered by the room. The custom field "hierarchy" contains the room variables of either "management", "babies_room" and "toddlers_room".
How do I amend the code below to filter the posts by the value held within <?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; ?>
Share
Improve this question
edited Aug 25, 2019 at 20:44
Glorfindel
6093 gold badges10 silver badges18 bronze badges
asked Sep 25, 2012 at 14:00
Sue.My.ChinSue.My.Chin
31 bronze badge
1 Answer
Reset to default -1Something like this should work:
meta_key=hierarchy&meta_value=management
This should be added into the query_posts function, that is not shown in your code block, but should come before it.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745215748a4617010.html
评论列表(0条)