Ich baue gerade eine Filme-Seite, in der ich Post Types, Taxonomies und Custom Fields einsetze. Jetzt macht mir die Ausgabe der Custom Fields im Template Mühe, und ich kann den Fehler nicht entdecken.
zunächst die functions.php:
PHP
<?php
/* Define Custom Boxes and Related Functions */
add_action('admin_init', 'init_custom_boxes');
/* Save Inputs to Custom Boxes */
add_action('save_post', 'save_details');
/**
* Description of add_meta_box() Function's Required Arguments
*
* $id HTML 'id' attribute of the edit screen section
* $title Title of the edit screen section, visible to user
* $callback Function that prints out the HTML for the edit screen section.
* $page The type of Write screen on which to show the edit screen section ('post', 'page', 'link', or 'custom_post_type' where custom_post_type is the custom post type slug)
*/
/* Add Boxes To Editor */
function init_custom_boxes() {
add_meta_box('produced-meta','Production Date','prod_date','bdmov');
}
/* Print Box Content */
function prod_date() {
global $post; /* IMPORTANT for get_post_custom Queries */
$custom = get_post_custom($post -> ID);
$proddate = $custom['proddate'][0];
?>
<label>Production Date:</label><br />
<input name="proddate" value="<?php echo $proddate ?>"/>
<?php
}
function save_details(){
global $post;
update_post_meta($post -> ID, 'proddate', $_POST['proddate']);
}
Alles anzeigen
Und das ist in meiner single.php:
PHP
<?php
/**
* Sample template for displaying single bdmov posts.
* This sample code was based off of the Starkers Baseline theme: http://starkerstheme.com/
*/
get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<h2>Movie Details:</h2><br />
<strong>Production date:</strong> <?php echo $proddate; ?><br />
<?php endwhile; // end of the loop. ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Alles anzeigen
Wieso wird hinter "Produktion Date" nichts angezeigt? Auch fehlt mir die Sidebar und der Footer, obwohl ich glaube, dass der Loop ordentlich beendet wird mit endwhile!
Ich sehe mittlerweile wohl vor lauter Bäumen den Wald nicht, daher bitte ich um Eure Hilfe.