• Resolved tatof

    (@tatof)


    hello,

    First of all awesome plugin!
    I’m stuck at something and can’t find out how to fix it.

    Building an custom page function with 2 simple fields.
    These simpel fields are going to be “a href=””>” but they have to be hidden when the fields are not filled.

    hope my brokan function wil explain my problem:

    <?php if ( $photos_query->have_posts() ) :
    		$photos_featch_data =
    		'<div class="partner-box">';
    			while ( $photos_query->have_posts() ) : $photos_query->the_post();
    			$photos_featch_data .= '<div class="item">
    			<div class="partnerfoto-holder">
    				'.get_the_post_thumbnail($page->ID, "partnerfoto").'
    			</div>
    
    			'.$facebook = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0", true);
    			if ( $facebook ) {
    				echo '<a href="'$facebook'">facebook</a>';
    			}.'
    
    			<div class="partnertext-holder">
    				<h3>'.get_the_title().'</h3>
    				<p>'.get_the_content().'</p>
    			</div>
    		</div>';
    
    		endwhile;
    		$photos_featch_data .= '</div>';
    
    	wp_reset_postdata(); ?>
    
    <?php else:  ?>
    
    <?php endif;
    
    //return shortcode data
    return "{$photos_featch_data}";

    The $facebook function doesn’t work. tryed many ways but I think i’m to noob in php :S

    https://wordpress.org/plugins/simple-fields/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Pär Thernström

    (@eskapism)

    I think something like this should work better. Not tested, but perhaps.. 🙂

    <?php
    if ( $photos_query->have_posts() ) :
    		$photos_featch_data =
    		'<div class="partner-box">';
    			while ( $photos_query->have_posts() ) : $photos_query->the_post();
    			$photos_featch_data .= '<div class="item">
    			<div class="partnerfoto-holder">
    				'.get_the_post_thumbnail($page->ID, "partnerfoto").'
    			</div>
    			';
    
    			$facebook = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0", true);
    
    			if ( trim($facebook) ) {
    				$photos_featch_data .= "<a href='$facebook'>facebook</a>";
    			};
    
    			$photos_featch_data .= '
    			<div class="partnertext-holder">
    				<h3>'.get_the_title().'</h3>
    				<p>'.get_the_content().'</p>
    			</div>
    		</div>';
    
    		endwhile;
    		$photos_featch_data .= '</div>';
    
    	wp_reset_postdata(); ?>
    
    <?php else:  ?>
    
    <?php endif;
    
    //return shortcode data
    return "{$photos_featch_data}";
    Thread Starter tatof

    (@tatof)

    looks good! 🙂 going to try that now thank you 🙂

    edit:

    Works perfectly! thank you for helping me understand this terrible hard to learn code:P haha
    Here my final solution:

    <?php
    if ( $photos_query->have_posts() ) :
    		$photos_featch_data =
    		'<div class="partner-box">';
    			while ( $photos_query->have_posts() ) : $photos_query->the_post();
    			$photos_featch_data .= '<div class="item">
    			<div class="partnerfoto-holder">
    				'.get_the_post_thumbnail($page->ID, "partnerfoto").'
    				<div class="partnerfooter-holder">
    				';
    
    				$facebook = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0", true);
    				if ( trim($facebook) ) {
    					$photos_featch_data .= "<a href='$facebook' class='facebook'></a>";
    				};
    				$twitter = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0", true);
    				if ( trim($twitter) ) {
    					$photos_featch_data .= "<a href='$twitter' class='twitter'></a>";
    				};
    				$google = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_3_numInSet_0", true);
    				if ( trim($google) ) {
    					$photos_featch_data .= "<a href='$google' class='google'></a>";
    				};
    				$youtube = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_4_numInSet_0", true);
    				if ( trim($youtube) ) {
    					$photos_featch_data .= "<a href='$youtube' class='youtube'></a>";
    				};
    				$website = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_5_numInSet_0", true);
    				if ( trim($website) ) {
    					$photos_featch_data .= "<a href='$website' class='site'></a>";
    				};
    
    			$photos_featch_data .= '
    			</div>
    			</div>
    			<div class="partnertext-holder">
    				<h3>'.get_the_title().'</h3>
    				<p>'.get_the_content().'</p>
    			</div>
    		</div>';
    
    		endwhile;
    		$photos_featch_data .= '</div>';
    
    	wp_reset_postdata(); ?>
    
    <?php else:  ?>
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘If empty in "custom page" $featch_data’ is closed to new replies.