custom fields in the loop
-
I am not a programmer and only know enough about coding to get myself in trouble. I have searched as best I can through this forum and stared at https://codex.www.ads-software.com/The_Loop but am having difficulty wrapping what’s left of my mind around multiple loops (which is what I’m guessing is required).
I am using “Get Custom Field Values” plugin and have styled them with a border.
This is what I have on index.php
<?php // the_meta(); add custom fields _e('<ul class="post-meta"><li></li>'); echo c2c_get_custom('date', '<li>', '</li>'); echo c2c_get_custom('Publication', '<li><strong>', '</strong></li>'); echo c2c_get_custom('Title', '<li><strong><big>', '</big></strong></li>'); echo c2c_get_custom('Author', '<li>By ', '</li>'); echo c2c_get_custom('URL', '<li><small>(<a href="', '">Read the complete article</a>)</small></li>'); _e('</ul>'); ?>
and the following CSS
ul.post-meta {border:1px solid #000;} ul.post-meta li {padding: 2px 10px; display:block ; } ul.post-meta span.post-meta-key {font-weight:bold;}
At present, this is what appears in the coding if none of the custom fields are filled out.
<ul class="post-meta"><li></li></ul>
which means that the border appears even though none of the fields have been filled out – making the page somewhat unsightly, not to mention adding extraneous coding….
How do I go about encoding this so that nothing at all appears unless one of the custom fields are filled out?
I know that it must be an “if” “else” but that’s as far as I’ve managed to grasp. Something like
if custom field(s) filled out
echo custom fields list coding
else
echo ”;
I hope my questions make sense. I’d very much appreciate any help that can be offered. Thank you.
- The topic ‘custom fields in the loop’ is closed to new replies.