Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been given a design for a WordPress site which will be mostly made up of pages rather than posts. However, at the top of each page there needs to be three featured items in a row. Each featured item will have an image, title, a small bit of summary text, and a link to another page.

Can anyone tell me the best way of implementing these featured items for a page? Would they need to be a custom content type? And if so how would I implement it in the template? They need to be fairly easy for administrators to edit, and change, and link to other pages.

I am an experienced Drupal designer, but am new to WordPress.

Any help would be much appreciated.

Ben

share|improve this question
    
The right solution depends entirely on the purpose of the featured items? What criteria determines what they are (selected arbitrarily? by date? taxonomy? something else?). –  mrwweb Jul 7 '12 at 20:42
    
Hi mrwweb, the featured items are a way of highlighting different pages for a section of the website. So each section of the website could highlight pages within that section. The featured items would generally be fixed but could be changed by administrators. –  Ben Jul 12 '12 at 12:47
add comment

1 Answer

up vote 1 down vote accepted

Since I don't know the complete scope of the project I can only give a suggestion on what I would do.

Since you will be using a page for placing the 3 images with title and excerpt, I'd create a custom page template that has two loops. The first loop would use query_posts to bring in the 3 images (title, and excerpt). I would then use a second loop to show the content of the page.

The part that would need some planning would be how to set up the first loop. If the 3 featured items can be randomly chosen from a given category you can simply use query_posts to retrieve the posts. If not it will be a little bit more work.

If you have several different pages that will use this structure it would be best to use conditional tags so you won't have to make a custom page for each category. I've put together a sample custom page to show you what I'm talking about. I haven't tested it live, but I believe the code is correct. In the example I'm using 3 posts with a custom image and the excerpt for a brief bit of text from category 8 being the id. I've commented the code to explain some of the code:

<?php
/*
Template Name: Featured
*/
?>
<?php get_header(); ?>
<div class="inner">

<?php /** Use WP_Query instead of query_posts, Thanks to Chris_O for the heads up */ ?>

  <?php 
    $custom_query = new WP_Query( 'posts_per_page=3&cat=8' );
    while ( $custom_query->have_posts() ) : $custom_query->the_post(); 
    ?>    
    <div class="featured">
      <?php
        /**
        * Here is where you bring in the 3 post from the category
        * (with the id of 8 for this example)
        */
      ?>
      <a href="<?php the_permalink(); //Makes the image Link to the Full Post ?>">
      <?php the_post_thumbnail(); // Gets The Posts Thumnail ?></a>
      <h2>
        <a href="<?php the_permalink(); //Gets the Title/Link to the post ?>">
        <?php the_title(); ?></a>
      </h2>
      <?php the_excerpt(); // The excerpt can be customized for amount of text displayed ?>
    </div>

  <?php endwhile; ?>  
  <?php wp_reset_query(); ?>

    <div class="wrapper">
      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
      <div class="entry">
        <h2><?php the_title(); ?></h2>
        <?php the_content(); ?>
        <p class="postmetadata">Posted in <?php the_category(', ') ?> <strong>|</strong>
          <?php edit_post_link( 'Edit','','<strong>|</strong>' ); ?>
          <?php comments_popup_link( 'No Comments &#x27A6;', '1 Comment &#x27A6;', '% Comments &#x27A6;' ); ?>
        </p>
      </div><!-- End Entry -->
      <?php endwhile; ?>
    </div>

  <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
  <?php endif; ?>

</div><!-- END POST -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Let me know if you need more help.

EDITED: Changed the code to use WP_Query per Chris_O's advice.

share|improve this answer
    
I would recommend doing a new WP_Query instead of using query_posts. See wordpress.stackexchange.com/a/1755/251 for more info. –  Chris_O Jul 8 '12 at 7:52
    
I've updated the code as advised. Thanks for taking the time to point it out, I appreciate the link and advice, regards –  Jeremy Jared Jul 8 '12 at 9:37
    
Hi Jeremy Jared, thank you very much for taking the time to answer my query and for your example. It is very helpful, especially as I am new to Wordpress. It is also helpful in showing me the approach to take to solve my problem. –  Ben Jul 12 '12 at 12:44
    
@Ben I'm glad it was useful. One of the benefits of wordpress.stackexchange.com is the ability to learn as you try to help others as I did in this question. –  Jeremy Jared Jul 12 '12 at 12:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.