• Resolved FREEZhao

    (@freezhao)


    I have 3 items in 1 line. with a <br> in the end.

    I want this: if any 3 items exit data, then show it, else nothing show up.

    I know there is [if][/if] tag can make 1 item show or not, but with a <br> in the end for 3tems. I have no idea how to make it happen.

    Anyone can help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Jory Hogeveen

    (@keraweb)

    Hi @freezhao

    I’m not sure I follow the issue here. Can you elaborate with code examples?

    Cheers, Jory

    Plugin Support Paul Clark

    (@pdclark)

    @freezhao Here’s what you’ve described as a shortcode, [three-items], which outputs meta values for foo, bar, and baz separated by commas and followed by a <br/> if at least one of them is not empty:

    <?php
    
    add_shortcode(
    	'three-items',
    	function( $atts, $content, $shortcode_tag ){
    		ob_start();
    
    		$items = [
    			get_post_meta( get_the_ID(), 'foo', true ),
    			get_post_meta( get_the_ID(), 'bar', true ),
    			get_post_meta( get_the_ID(), 'baz', true ),
    		];
    
    		foreach( $items as $key => $item ) {
    			if ( empty( $item ) ) {
    				unset( $items[ $key ] );
    			}
    		}
    
    		if ( ! empty( $items ) ) {
    			printf(
    				'%s<br/>',
    				implode( ', ', $items )
    			);
    		}
    
    		return ob_get_clean();
    	}
    );
    Plugin Contributor Jory Hogeveen

    (@keraweb)

    Closing topic due to inactivity!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How Can I add [if] to match anyone of multi conditions?’ is closed to new replies.