WordPress.org

Support

Support » Themes and Templates » Custom Field Display

Custom Field Display

  • liondedan

    @liondedan

    Hello,

    I’ve got a template for a website that I’m making, however not all the products that I sell have text for every single field. My php is not that great so I’m looking for a way to hide a fairly large div that contains an image and some custom field text.I know the basic structure but my knowledge of all the synax regarding the quotations and double quotations is really poor. This is the div that I need to hide if the custom field ‘answer_text’ is empty, but display if it contains any text:

    <!--MODUAL BOX-->
    <div class="modual_box">
    	<div class="modual_box_icon">
    		<img src="<?php bloginfo('template_directory'); ?>/images/faq_title_icon.gif" />
    	</div>
    	<h2>Frequently Asked Questions</h2>
    	<p>
    		<?php echo get_post_meta($post->ID, 'answer_text', true); ?>
    	</p>
    </div>
    	<!--END MODUAL CONTAINER-->
    	<div class="divider">
    		<div class="dark">
    		</div>
    		<div class="light">
    		</div>
    </div>
    	<!--FAQS END MODUAL BOX-->

    ———————————————

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael

    @alchymyth

    Forum Moderator

    try a conditional statement, for example:

    <?php if( get_post_meta($post->ID, 'answer_text', true) ) : ?> 
    
    <!--MODUAL BOX-->
    <div class="modual_box">
    	<div class="modual_box_icon">
    		<img src="<?php bloginfo('template_directory'); ?>/images/faq_title_icon.gif" />
    	</div>
    	<h2>Frequently Asked Questions</h2>
    	<p>
    		<?php echo get_post_meta($post->ID, 'answer_text', true); ?>
    	</p>
    </div>
    	<!--END MODUAL CONTAINER-->
    	<div class="divider">
    		<div class="dark">
    		</div>
    		<div class="light">
    		</div>
    </div>
    	<!--FAQS END MODUAL BOX-->
    
    <?php endif; ?>
    liondedan

    @liondedan

    AMAZING. <— didn’t mean to do that, its just karma for helping. Could you explain to me exactly how you did it with regards to the quotes and double quotes? I was along the right lines but couldn’t get my head around the correct syntax for the quotes.

    Michael

    @alchymyth

    Forum Moderator

    with regards to the quotes and double quotes?

    no quotes were harmed during the implementation of the code;

    only the first and last line are new, and those are just part of a standard conditional if statement.

    liondedan

    @liondedan

    mmm okay, I thought you had to escape single quotes within double quotes inside php?

    Michael

    @alchymyth

    Forum Moderator

    you had to escape single quotes within double quotes inside php?

    no; you would need to escape double quotes within double quotes.

    however, your exsisting code is not even within php; the php tag for the conditional statement was closed at the end of the first line, etc.

    there are online php tutorials available where you can check the proper php syntax.

    liondedan

    @liondedan

    Thank you very much for your time alchymth, I appreciate it!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Field Display’ is closed to new replies.
Skip to toolbar