Support » Fixing WordPress » Custom fields on home page and blog page

  • Hi there,

    I have a static page set as my home page, and I´m struggling to display custom fields on this home page. Is there a different practice for including custom fields on a page that is set as the home pages? This is the code I´m using:

    <?php get_post_meta($post->ID, “punchline”, true); ?>

    The “punchline” field is definitely defined in the admin panel, so what could be the problem then?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • What are you using to grab these posts in the home page’s template file?

    Actually, you need to add a template for the home page, say home.php, which has a loop to query the posts. and in the loop, you will call <?php get_post_meta($post->ID, “punchline”, true); ?> to get the custom field value for each post.

    You can have a look at some samples to learn. samples let you learn faster. If you don’t mind, you can take a look at Aurelius theme. If you look at the home.php file, you will find how to code to get the custom values.

    or you can look in the codex document.

    good luck!!

    Thread Starter norbag

    (@norbag)

    I´m using a template for the home page. I´m using this code to grab the content of the page:

    <?php if(have_posts()) while(have_posts()) : the_post(); ?>

    try this http://wordpress.org/extend/plugins/fields/ you then can display custom field by putting a shortcode, e.g. [field key=’punchline’] inside the post content without having to modify the template

    That code will only display the content of the static home page itself (as added via Edit Page). Is that what you want or are you trying to display a number of posts?

    Also get_post_meta only grabs the custom field data – it doesn’t display it. For that, you need <?php echo get_post_meta($post->ID, "punchline", true); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom fields on home page and blog page’ is closed to new replies.