WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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:

  $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() ) : 
  $custom = get_post_custom($post->ID);
<div class="section entry" id="entry<?php the_ID(); ?>">
  <div class="posttitle">
    <h2><?php the_title(); ?></h2>
    <div class="portfolio-image">  
      <a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
        <?php the_post_thumbnail('thumbnail'); ?>
  <?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

Your Answer


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.