1

OK、非常に単純なタスクです。私は PHP が苦手です。

スタイル付きリストを使用して一部のスタッフをリストしたいページがあります。ここにページがあります - http://www.themontessoripeople.co.uk/montesori/?post_type=people

「カスタム コンテンツ タイプ」プラグインをダウンロードし、「人」のコンテンツ タイプを追加し、適切なフィールドを追加しました。「hierarchy」というカスタムフィールドで追加した投稿をフィルタリングしたいと思います。

ページを表示する方法は次のとおりです- 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; ?>

ありがとう、ベン。

これは、参照用にフィルタリングされた結果の2つのセットを示す作業コードです-

<?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 -->
4

2 に答える 2

1

コードを簡略化しました。フィルターも追加されます。

<?php
    $col = 1;
    while (have_posts())
    {
        the_post();
        if ($col == 1) echo "<div class=\"row\">";

        // filter
        $hierarchy = get_custom_field('hierarchy');
        // if it does not match continue (skip)
        if ($hierarchy != "boss") continue;
        // if it matches continue (skip)
        //if ($hierarchy == "notboss") continue;

        // needed fields
        $id = the_ID();
        $job = get_custom_field('job');
        $title = the_title();
        $img = get_custom_field('staff_image:to_image_src');
        $edit = edit_post_link('Edit Post', '');

        echo <<< END
                <div class="post col$col" id="post-$id">
                    <div class="people-spacer">
                        <div class="people"><a class="animate" >
                        <div class="bio">
                        <p class="titles">$title<br/>
                        <span class="job">$job</span> </p><br />
                        </div>
                        <img src="$img" width="160" height="160" alt="$title-image" />
                        </div>
                        <div class="people-link-edit">$edit</div>
                    </div>
                </div>
END;

        if ($col == 1) echo "</div>";
        (($col==1) ? $col=2 : $col=2);
    }
?>

編集: print_custom_field の代わりに get_custom_field。

于 2012-09-25T23:41:06.923 に答える
0

でクエリ引数を定義できますquery_posts($args)- query_postsを見てください。多分あなたは試すことができますget_posts

于 2012-09-25T23:41:35.663 に答える