• Resolved ejm

    (@llizard)


    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.

Viewing 1 replies (of 1 total)
  • Thread Starter ejm

    (@llizard)

    Excuse me for replying to myself. I have blundered onto the solution and am posting it here, just in case someone else has similar difficulty understanding the codex. (I have no idea if the solution is the most efficient but it is working…) Here is the coding I have used:

    <?php // with regards to the_meta(); add custom fields
    if (function_exists('c2c_get_custom')) { ?>
    
    <ul class="post-meta">
    
    <?php echo c2c_get_custom('date', '<li>', '</li>');
    echo c2c_get_custom('Publication', '<li class="publication">', '</li>');
    echo c2c_get_custom('Title', '<li class="publication_title">', '</li>');
    echo c2c_get_custom('Author', '<li>By ', '</li>');
    echo c2c_get_custom('URL', '<li class="publication_URL">(<a href="', '">Read the complete article</a>)</li>'); ?>
    
    </ul>
    
    <?php } ?>

    with the following CSS

    ul.post-meta {border:1px solid #000;}
    ul.post-meta li {padding:2px 10px; display:block;}
    ul.post-meta li.publication {font-weight:bold;}
    ul.post-meta li.publication_title {font-weight:bold; font-size:large;}
    ul.post-meta li.publication_URL {font-size:small;}
    ul.post-meta span.post-meta-key {display:none;}

    Of course, this will do nothing about styling any extra custom fields added on the fly but I do not anticipate adding any others.

Viewing 1 replies (of 1 total)
  • The topic ‘custom fields in the loop’ is closed to new replies.