• Hello I am trying to target to target specific posts that are categorized to be displayed on specific pages.

    I am building a home builders website, so I have post categories like

    1) Homes for sale 2) Show homes 3) Features homes 4) Available lots

    and I have pages that corespond to categories. 1)Show homes 2) Available Homes 3) Available Lots

    What I am trying to accomplish is that I want to display combinations like this

    On page (AVAILABLE HOMES) – All posts that are in category / slugs “Homes for sale”

    On page (SHOW HOMES) – All posts that are in category / slugs “Show Homes”

    I am not sure how to accomplish this….

    This is how far I got:

    <?php if(have_posts()):?>
    <?php while(have_posts()) : the_post();
          $categoris = get_the_category();
    
          print_r($categoris);
    
          if($categories){
              $class_names = array();
    
              foreach($categories as $category){
                  $class_names[] = $category->slug;
              }
    
              $classes = join(' ', $class_names);
          }
    ?>
    
    <div class="row">
        <div class="large-4 columns">
            <div class="panel bodyHeight">
             <?php if(has_post_thumbnail()) : ?>
             <a href="<?php the_permalink();?>"><?php the_post_thumbnail(); ?></a>
             <?php endif;?>
            </div>
         </div>
         <div class="large-8 columns">
            <div class="panel bodyHeight">
            <p>Price:
                      <?php $custom_fields = get_post_custom();
                      $price = $custom_fields['price'];
                      foreach($price as $key => $value){
                      echo $value;
                      }
                      ?>
            </p>
            <p>SqF:
                      <?php $custom_fields = get_post_custom();
                      $sqf = $custom_fields['sqf'];
                      foreach($sqf as $key => $value){
                      echo $value;
                      }
                      ?>
            </p>
            <p>Number of Bedrooms:
                      <?php $custom_fields = get_post_custom();
                      $bed = $custom_fields['num_bedrooms'];
                      foreach($bed as $key => $value){
                      echo $value;
                      }
                      ?>
            </p>
            <p>Number of Bathrooms:
                      <?php $custom_fields = get_post_custom();
                      $bath = $custom_fields['num_bathrooms'];
                      foreach($bath as $key => $value){
                      echo $value;
                      }
                      ?>
            </p>
            <p>Home Description:
                      <?php $custom_fields = get_post_custom();
                      $desc = $custom_fields['description'];
                      foreach($desc as $key => $value){
                      echo $value;
                      }
                      ?>
            </p>
            <p>Home Location:
                      <?php $custom_fields = get_post_custom();
                      $address = $custom_fields['address'];
                      foreach($address as $key => $value){
                      echo $value;
                      }
                      ?>
            </p>
            </div>
         </div>
    </div>
    <?php endwhile;?>
    <?php else: ?>
    <div class="row">
        <div class="large-4 columns">
            <div class="panel bodyHeight">
            <h3>No posts were found.</h3>
            </div>
        </div>
    </div> <?php endif;?>

    Now I am wondering how can I filter this or how can i accomplish what I am trying to do?

    Thanks

The topic ‘How to target posts to pages?’ is closed to new replies.