Not sure what you mean by
how to say “actual post” instead of a specific post id.
But get_post_meta() seems to be a valid approach.
I want to display the custum field in the single page. So, the code will go in “single.php”
The code “get_post_meta” use tree parameters. 1. $post_id 2. $key 3. $single
For example, I have 2 post with the metadata “author”
The value of the key for post #1 is “Paul” and for post #2 “Edward”.
If I add the line <?php echo get_post_meta(1, 'author', true); ?> in the file “single.php”, then, I will always get “Paul” as the author, because the cose is looking for the key author in the post #1.
What I want is, if I look at the page 1, I got “Paul” and for the page 2, I got “Edward”. So, for “$post_id” I don’t want to put a number, but I want the function that is used in “get_post_custom_values”. The “Default” value for “$post_id is “Current post”. And… if I write “current post” instead of a number, it did not work…
Is it more clear…?
This should work:
<?php echo get_post_meta($post->ID, 'author', true); ?>
Next “problem”
We have a specific code for the page “index.php”. The code give the title and excerpt for each article published in the last issue (it’s a student paper website).
What we actualy do is that we create a “summary” page that is displayed (it contain mostly nothing but metadata).
I changed the page “single.php” in order to display the summary with the script of “single2.php” and all the other with “single1.php”, however, the code of “index.php”, if pasted in “single2.php” will still display the last issue and not the content of the “summary” we are looking at.
The actual code is the following :
<?php get_header(); ?>
<?php global $post; $myposts = get_posts('numberposts=1&offset=0&category=6'); foreach($myposts as $post) : setup_postdata($post); $jouredition = get_the_time('j.m.Y'); ?>
<p>Édition du <?php the_time('j F Y') ?></p>
<p>Éditorial</span><br />
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
<?php the_excerpt(); ?></p>
<?php endforeach; ?>
<p>Société
<?php global $post; $myposts = get_posts('category=5'); foreach($myposts as $post) : setup_postdata($post); $jourpub = get_the_time('j.m.Y'); ?>
<?php if ($jourpub == $jouredition) : ?>
<br />
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
<?php the_excerpt(); ?></p>
<?php endif; ?>
<?php endforeach; ?>
<?php get_footer(); ?>
This code invoque the articles in the “Éditorial” and “Société” section, but not from the issue we are lookink for, but for the last published.
Note, the is some french in it.
Édition du = Edition of the (date)
jouredition= day of edition
jourpub = day of publication (I think)
Éditorial and Société = Editorial and Society (these are some of the sections in the paper).
You can ask questions if it’s not clear.