Can you paste some of the code from your template? Be sure to use the “code” formatting so we can read it.
This in my home.php
<?php
/**
* The main template file
*/
?>
<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/html-header', 'parts/shared/header' ) ); ?>
<div id="slider"> </div>
<div id="container">
<div id="content">
<?php if ( have_posts() ): ?>
<ol>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<article class="home">
<div id="meta">
<h2><a href="<?php esc_url( the_permalink() ); ?>" title="<?php the_title(); ?>" rel="bookmark">
<?php the_title(); ?>
</a></h2>
<time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate>
<?php the_date(); ?>
</time>
<div class="categoria">
<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if($categories){
foreach($categories as $category) {
$output .= '<span>Categoria:</span> <a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
}
echo trim($output, $separator);
}
?>
</div>
<div class="difficolta"> <span>Difficoltà:</span><?php print_custom_field('difficolta'); ?></div>
<?php the_excerpt(); ?>
</div>
<div class="image">
<?php the_post_thumbnail( 'medium' ); ?>
</div>
</article>
</li>
<?php endwhile; ?>
</ol>
</div>
<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/sidebar' ) ); ?>
</div>
</div>
<?php else: ?>
<h2>No Post</h2>
<?php endif; ?>
<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/footer','parts/shared/html-footer') ); ?>
That looks like it should work — WP relies insanely on global variables, however, so it’s tough to know exactly what it’s going. The loop is an Ok idea, but WP’s implementation hurts my brain.
I do not know what to say!
So just as it is written should work whenever generates an Article?
Because, this is the problem. If I have a single article… this code works if the items are more than two code only works in one of the articles just!!
The loop is a pain: it’s very hard to debug. I don’t know what to say either other than WordPress is a pain. You can try using the built-in get_post_meta() function instead of the CCTM’s print_custom_field() function and see if that’s any better.
<?php $meta_values = get_post_meta($post_id, $key, $single); ?>
the parentheses should put the name of my field right?
I added this code
<?php $meta_values = get_post_meta('difficolta'); ?>
but I have always the same problem. The custom field is printed only once
Please read the docs: http://codex.ww.wp.xz.cn/Function_Reference/get_post_meta
You’re using the function incorrectly.