I’m running wp 2.0.11 with “Get Custom Field Values 2.1” and had hoped that this thread might resolve the difficulty I am having because not every post uses the fields. I read the thread Anyone using “Get Custom Field Values” plugin in WP2.2? and also have stared many times at WP Codex: Using Custom Fields but have been unsuccessful at translating the contents. (I have only a vague understanding of PHP…)
This is the code I am currently using that does not break the page:
<?php // add custom fields
if (function_exists('c2c_get_custom')) {
echo '<ul class="post-meta">';
echo c2c_get_custom('Date of Publication', '<li>', '</li>');
echo c2c_get_custom('Publication', '<li class="publication"><strong>', '</strong></li>');
echo c2c_get_custom('Publication Title', '<li class="pubtitle"><strong>', '</strong></li>');
echo c2c_get_custom('Publication Author', '<li>By ', '</li>');
echo c2c_get_custom('Publication URL', '<li><small>(<a href="', ' " title="offsite link">learn more by following this link</a>)</small></li>');
echo '</ul>';
}
else {echo '';}
?>
Unfortunately, this does not quite achieve my expected results – if there are no custom fields filled in, then the source code shows
<ul class="post-meta"></ul>
which means that the page does not validate.
After reading this thread, I tried the following:
if (is_array(c2c_get_custom($field))) {
echo '<ul class="post-meta">';
echo c2c_get_custom('Date of Publication', '<li>', '</li>');
echo c2c_get_custom('Publication', '<li class="publication"><strong>', '</strong></li>');
echo c2c_get_custom('Publication Title', '<li class="pubtitle"><strong>', '</strong></li>');
echo c2c_get_custom('Publication Author', '<li>By ', '</li>');
echo c2c_get_custom('Publication URL', '<li><small>(<a href="', ' " title="offsite link">learn more by following this link</a>)</small></li>');
echo '</ul>';
}
else {
echo '';
}
I’ve also tried opening with
if (!empty(c2c_get_custom)) {
and while these do not cause error messages, they also do not display any custom fields at all.
In the css for .post-meta, there is a border, so adding an empty set of <li></li>
is not a viable option either because there will be an empty bordered section whenever the custom fields are not filled in.
Any ideas on how I can fix this?
(I hope this made sense!)
-ejm
P.S. Here is a post that has the custom fields filled in: etherwork.net/blog/?p=447
and here is one that does not:
etherwork.net/blog/?p=446
(Please refrain from making those URLs into live links – I’m really getting tired of spammers…)