Use custom fields..
http://codex.wordpress.org/Using_Custom_Fields
Then switch the content depending on the presence of a custom field, or the value of that field…
Thank you. That was not what I was asking about, but I’ve found a solution myself. 🙂
Custom fields would handle the situation you presented, but if you have a solution then that’s what matters… 😉
Well, I knew that custom fields are exactly what I needed, and I had no problem using them. They worked okay. What I had problem with was the actual switching, since I’m not that good with PHP. 🙂 While searching for the solution I finally found a Codex article describing the Variable Sidebar: http://codex.wordpress.org/Conditional_Tags and I worked from there. In the single post template in the place where I needed the content switched I put this conditional tag with categories’ id. Since there are only two categories, it was easier to do:
<?php
if (in_category('3')) {
echo "<div class=\"press-meta\"> <span class=\"press-copy\"> ";
$author = get_post_meta($post->ID, 'author', true);
echo($author);
echo " | ";
$source = get_post_meta($post->ID, 'source', true);
echo($source);
echo " </span> ";
the_time('d.m.Y');
echo " </div>";
} else {
echo "<small> ";
the_time('d.m.Y');
echo " @ ";
the_time('G:i');
echo " ";
the_tags(' | ', ', ', '');
echo " </small> <br />";
}
?>
So, if WP sees the post belongs to the Articles category, it displays the author and the name of the original publisher along with the publish date, and when it sees it’s a News post, it displays the date and the time of the news along with the post’s tags.
If it works… 🙂
Although i have to point out there is one small addition you could make here…
$author = get_post_meta($post->ID, 'author', true);
You’re not performing any check to see if this returns a value (same with $source)….
Essentially this won’t return anything when the field doesn’t exist, but i’d do it like so….
$author = get_post_meta($post->ID, 'author', true);
if($author) {echo $author;}
Not sure it’ll make a huge difference, but the current way still echo’s $author even if it doesn’t have any value…
Also..
echo($source) need not have brackets…
echo $source; will work fine…
Perhaps it might be a little easier on the eyes like so…
<?php if(in_category('3')) : ?>
<div class="press-meta">
<span class="press-copy">
<?php
$author = get_post_meta($post->ID, 'author', true);
$source = get_post_meta($post->ID, 'source', true);
if($author) {
echo $author;
}
echo ' | ';
if($source) {
echo $source;
}
?>
</span>
<?php the_time('d.m.Y');?>
</div>
<?php else :?>
<small>
<?php the_time('d.m.Y'); ?> @ <?php the_time('G:i');?> <?php the_tags(' | ', ', ', '');?>
</small>
<br />
<?php endif;?>
Like I said, I’m not good with PHP 🙂 My version does work for me and that’s okay. But thank you for your corrections, I’ll be glad to apply them if you don’t mind. 🙂
Go for it… 😉
Any problems, post back… 🙂