0

I have a restaurant menu theme and there are some menu items the owner has, with no pricing (all menu items have the option for a price and an alternate price)

In the taxonomy-menutype.php file [ shows the menu items ] there is this:

<div class="pricebox">
                        <?php if ( get_post_meta($post->ID,'atp_price',TRUE) ) {
                            echo'<span class="price">'.get_post_meta($post->ID,'atp_price',TRUE).'</span>';
                        } ?>

                        <?php 
                        $moreprices = get_post_meta(get_the_id(),'atp_moreprice',true);
                        if( is_array( $moreprices ) ){ ?>
                            <?php foreach( $moreprices as $itemprice ) {?>
                                <span class="price"><?php echo $itemprice; ?></span>
                            <?php } ?>
                        <?php } ?>
                        </div>

What I need to do is hide the (either) field if there is no input (empty) otherwise if there is, then show the field...

Edited by idaryl

4
Contributors
6
Replies
43
Views
5 Months
Discussion Span
Last Post by diafol
0

Oh my... had no idea about the CSS empty attribute, worked great..... Added it to the arsenal, thank you! :0 :)

0

:empty is indeed an useful trick. Be aware that it does have one issue:

IE9-IE11 supports :empty but will not repaint/relayout the page if content is added/removed from an :empty selected element

Taken from http://caniuse.com/#feat=css-sel3

If you're not using javascript to dynamically add / remove items, then I doubt this should matter.

I must admit, I'm not a big fan of hiding stuff if they're not supposed to be on the page at all - hiding/showing as a toggle, fair enough, but adding the kitchen sink from the server and then getting css to clear up the mess is a bit worrying. Personally, I'd go with a server-side solution.

0

What is happenening is, the area for the price has a background color and padding set to it - but... when there is no price applied the field still shows on the page as a small rectangle of the background color.

All I desired to to do was hide it if there is no input (PRICE) entered by the admin, thats all. I tried some functions I found but they didnt work.

Edited by idaryl

0

Ah I see. I thought you wanted to hide the entire item. OK css should be good for that. :)

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.