Custom Fields and Custom Templates
-
I’m using a custom field to put a short blurb in the sidebar for some of my posts and pages. This works fine with the following index.php file:
<?php get_header(); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2 class="storytitle"><?php the_title(); ?></h2> <div class="storycontent"> <?php the_content(__('(Read more...)')); ?> </div> </div> <?php endwhile; else: ?> <?php _e('Sorry, no posts matched your criteria.'); ?> <?php endif; ?> <?php get_footer(); ?>However, I have a static front page and use the following template and a page called ‘News’ to display some recent short posts (it’s mostly a static site):
<?php /* Template Name: News */ ?> <?php get_header();?> <h2 class="storytitle">News</h2> <div class="storycontent"> <?php query_posts('showposts=10'); global $more; $more = 0; while (have_posts()) : the_post(); ?> <h3><?php the_time('j/m/y'); ?>: <a>" alt="Read this article..."><?php the_title(); ?></a></h3> <?php the_content(__('(Read more...)')); ?> <?php endwhile; ?> </div> <?php get_footer(); ?>The special field is called in the sidebar:
get_post_meta($post->ID, sidebar, true)This works fine with the first index.php code, but doesn’t return anything for the news.php file.
It looks like something to do with the Loop, but I can’t figure out the code to use, as I thought
$post->IDwould work outside the loop anyway.All help gratefully received.
The topic ‘Custom Fields and Custom Templates’ is closed to new replies.