Maybe I simply do not understand what
get_template_part() is doing …
I have a file called
event-list.php that should work as template for other pages and files so all my events (a custom post type) get listed!
event-list.php I have this …
<?php $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $wr_event_fields = get_post_custom(); $event_date_timestamp = $wr_event_fields['_wr_event_date']; $event_date = strftime('%d.%m.%Y', $event_date_timestamp); $event_time = $wr_event_fields['_wr_event_time']; $event_speaker = $wr_event_fields['_wr_event_speaker']; //get_template_part( 'event-item' ); ?> <!-- event-item.php --> <div id="event-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="event-date"><?php echo $event_date; ?></div> <div class="event_time"><?php echo $event_time; ?></div> <div class="event-speaker"><?php echo $event_speaker; ?></div> <div class="event-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div> <div class="event-description-excerpt"><?php the_excerpt(); ?></div> </div> <!-- event-item.php --> <?php endwhile; ?>
So what I want to do is include another template inside of
event-item.php which only holds the layout of an event. I want to use this
event-item.php maybe later also in different loops. It should just be the markup for each single event-item on my website. If I make a change inside of this
even-item.php template all "events" in any of my loops on my entire website should change.
The problem I have with this is the one in the above sample code.
get_template_part( 'event-item' ); to include the
event-item.php layout structure within my loop. And I get its custom post-meta outside of this template. However that does not work!
As you can see in my sample above I have to copy the entire layout structure from my
event-item.php inside of my
event-list.php so the post-meta stuff is filled in.
Any ideas what I don't get here or what I'm doing wrong here?
Thank you in advance.