好的,非常簡單的任務,我只是不擅長PHP。如何通過wordpress中的字段過濾自定義帖子?
我有一個頁面,我想列出一些使用樣式列表的工作人員。這是網頁 - http://www.themontessoripeople.co.uk/montesori/?post_type=people
我下載了一個「自定義內容類型」插件,並添加了「people」的內容類型並添加了相應的字段。現在我想篩選我通過名爲「層次結構」的自定義字段添加的帖子。
這裏是我想要的頁面顯示 - http://i47.tinypic.com/oqymwh.jpg
自定義字段「層次」既包含「管理」,「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 -->
我認爲這將得到更快的答覆,如果它被問到在WordPress的堆棧交換站點 – Kristian
相信我,它沒有。我已經問過兩次了 - http://wordpress.stackexchange.com/questions/66216/how-do-i-filter-a-custom-post-type-loop-by-a-field:s –
wordpress stack exchange甚至沒有像堆棧溢出那樣有用。大多數WP問題都可以提出並「通用化」,只是一個編程問題(許多程序員知道WordPress的PHP平臺如何工作的基礎知識) – Xhynk