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 want to include a horizontal section at the very top of my site, above the header, that shows the next six events. I've created a custom post type called "events", and I've created about 150 events.

That's all fine, but what I'm having trouble with is figuring out how to create this new section above the header to get these events to display. Would I need to edit each page's PHP to add that? Or is there something more global.

share|improve this question
add comment

1 Answer

You could take the code used for the custom post type and save it as a file (in this case I'll call it top.php). Upload top.php to the root of your theme folder. Make sure you remove the call to the header and footer. It might look something like this:

<?php 
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('showposts=' . $limit . '&paged=' . $paged);
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $loop = new WP_Query( array (
      'post_type' => 'portfolio', 
      'posts_per_page' => 5 )
      ); 
  while ( 
  $loop->have_posts() ) : 
  $loop->the_post();
  $custom = get_post_custom($post->ID);
  ?>
<div class="section entry" id="entry<?php the_ID(); ?>">
  <div class="posttitle">
    <h2><?php the_title(); ?></h2>
  </div>
    <div class="portfolio-image">  
      <a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
        <?php the_post_thumbnail('thumbnail'); ?>
      </a>
    </div>
  <?php the_excerpt(); ?>
</div><!-- section entry -->
<?php endwhile; ?>

Once the file has been uploaded to your server inside the theme's root folder, you can then place it inside the header.php file like so:

<?php get_template_part('top'); ?>

I hope that helps. Let me know if you have any questions.

share|improve this answer
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.