My first question would be to what would be the determiner of which posts? Certain category?
Thread Starter
Chris_K
(@handysolo)
Not category. The determiner would be me remembering to add the custom field to the applicable posts.
Elaboration of original post: Long story short, I want to manually/periodically add a custom field to some of my more popular posts. If that field is set or of a certain value (aka “True”) I want to add some code to the post.
What code? The new tagometer!
So, the idea is that I’d add a custom field to the applicable posts. Then, in single.php, I’d check for the tag and add code as necessary.
For my plugin posts (to display download and source view links) I currently test off $post_meta_cache, like so:
if( $post_meta_cache[$post->ID]['wp'] ) :
With ‘wp’ the key for the desired custom field. Your mileage may vary…
Thread Starter
Chris_K
(@handysolo)
Ah, there we go. Don’t need a plugin, just need a kick in the rear. Thanks guys!
Here’s what I ended up with:
<?php if( $post_meta_cache[$post->ID]['ShowDtag'] ) { ?>
<script src="http://images.del.icio.us/static/js/blogbadge.js"></script>
<?php } ?>
ShowDtag is my custom field. Only exists on posts that I want to show the del.icio.us thingy on.
Thread Starter
Chris_K
(@handysolo)
That little code snippet no longer works since I’ve upgraded to 2.1.
Can I not use $post_meta_cache[$post->ID]['ShowDtag']
in that fashion any more?
Use the API function get_post_meta($post_id, $key, $single = false)
e.g.
<?php if( get_post_meta($post->ID, 'ShowDtag', true) ) { ?>
<script src="http://images.del.icio.us/static/js/blogbadge.js"></script>
<?php } ?>
The third param just tells it that you’re expecting a single result… otherwise you get an array of results.
Thread Starter
Chris_K
(@handysolo)
Thank you, Mark. Will give that a shot soon. 🙂
[Update] Worked great. Thanks!