Tagged: 

Viewing 14 reply threads
  • Author
    Posts
    • #6212

      What I am trying to do is create a list of sponsors by the type of sponsor the registered for. Having a hard time displaying each sponsor type by the level.

      Here is the select I am using.

      array(
          'type' => 'select',
          'field' => 'sponsor_level',
          'label' => 'Sponsor Level',
          'required' => true,
          'attributes' => array(
              'class' => 'text'
          ),
          'choices' => array(
              '' => '-- Select --',
              'Platinum' => 'Platinum',
              'Gold' => 'Gold',
              'Silver' => 'Silver',
          ),
          'columns' => 4
      ),

      What I would like to do is display the Platinum Sponsors, then the Gold Sponsors, and then the Silver Sponsors in simple HTML.

      <div class="col-xs-12 platinum">
          <div class="col-xs-12 col-sm-3">
              <?php $image_ids = $post['upload_basic']; ?>
      	 <?php foreach ($image_ids as $image): ?>
      	     <img class="img-responsive" src="<?php echo wp_get_attachment_url($image); ?>" width="200" height="200">
      	 <?php endforeach; ?>
          </div>
          <div class="col-xs-12 col-sm-9">
              <p><?php echo $post['sponsor_overview']; ?></p>
          </div>
          <div class="col-xs-2 pull-right platinum-link">
              <a href="http://www.tsico.com/" target="_blank"><?php echo $post['sponsor_name']; ?> <i class="fa fa-angle-right"></i></a>
          </div>
      </div>
    • #6213

      Here are a few examples of what I am trying accomplish. The output would have a title and then content for each sponsor. Including a header for each segment.

      Attachments:
      You must be logged in to view attached files.
    • #6224
      Steve
      Keymaster

      Displaying data is standard WordPress/PHP with Piklist. I would recommend looping through your meta_values and pull the info with get_posts(). Something like this (untested):

      $levels = array(
      	'Platinum'
      	,'Gold'
      	,'Silver'
      );
      
      foreach ($levels as $level) {
      
      	$args = array(
      		'meta_key' => 'sponsor_level'
      		,'meta_value' => $level
      	);
      
      	$posts_array = get_posts( $args );
      
      	// Display your details here.
      
      }
      
    • #6249

      Looping through and pulling the data is not the problem. What I’m trying to do is separate the data by level in different lists, which will be formatted differently.

      Hence, will pull all the data for Platinum, and just logo and name for Gold and Silver (with URL). Want to do a full width for Platinum, and then break up Gold and Silver side by side in two columns with a header above each. So looking to match by level for each select item.

    • #6250

      Here is what I have been playing with…

      			<?php
      			$sponsors = get_post_meta($post->ID, 'summit_sponsor_group', true);
      			if ($sponsors == "Platinum"): ?>
      	      		<div class="col-xs-12">
      	        		<h3><span>Platinum</span> Sponsors</h3>
      	      		</div>
      				<?php foreach($sponsors as $post): ?>
      	      		<div class="col-xs-12 platinum">
      	        		<div class="col-xs-12 col-sm-3">
      	          			<a href="http://www.tsico.com/" target="_blank">
      	          			<?php $image_ids = $post['upload_basic']; ?>
      						<?php foreach ($image_ids as $image): ?>
      							<img class="img-responsive" src="<?php echo wp_get_attachment_url($image); ?>" width="200" height="200">
      						<?php endforeach; ?>
      	          			</a>
      	        		</div>
      		        	<div class="col-xs-12 col-sm-9">
      		          		<p><?php echo $post['sponsor_overview']; ?></p>
      		          		<p><?php echo $post['sponsor_level']; ?></p>
      		        	</div>
      		        	<div class="col-xs-2 pull-right platinum-link">
      		          		<a href="http://www.tsico.com/" target="_blank"><?php echo $post['sponsor_name']; ?> <i class="fa fa-angle-right"></i></a>
      		        	</div>
      	      		</div>
      				<?php endforeach; ?>
      			<?php elseif($sponsors == "Gold"): ?>
      	      		<div class="col-xs-12">
      	        		<h3><span>Gold</span> Sponsors</h3>
      	      		</div>
      				<?php foreach($sponsors as $post): ?>
      	      		<div class="col-xs-12 gold">
      	        		<div class="col-xs-12 col-sm-3">
      	          			<a href="http://www.tsico.com/" target="_blank">
      	          			<?php $image_ids = $post['upload_basic']; ?>
      						<?php foreach ($image_ids as $image): ?>
      							<img class="img-responsive" src="<?php echo wp_get_attachment_url($image); ?>" width="200" height="200">
      						<?php endforeach; ?>
      	          			</a>
      	        		</div>
      		        	<div class="col-xs-12 col-sm-9">
      		          		<p><?php echo $post['sponsor_overview']; ?></p>
      		          		<p><?php echo $post['sponsor_level']; ?></p>
      		        	</div>
      		        	<div class="col-xs-2 pull-right platinum-link">
      		          		<a href="http://www.tsico.com/" target="_blank"><?php echo $post['sponsor_name']; ?> <i class="fa fa-angle-right"></i></a>
      		        	</div>
      	      		</div>
      				<?php endforeach; ?>
      			<?php else : ?>
      	      		<div class="col-xs-12">
      	        		<h3><span>Silver</span> Sponsors</h3>
      	      		</div>
      				<?php foreach($sponsors as $post): ?>
      	      		<div class="col-xs-12 silver">
      	        		<div class="col-xs-12 col-sm-3">
      	          			<a href="http://www.tsico.com/" target="_blank">
      	          			<?php $image_ids = $post['upload_basic']; ?>
      						<?php foreach ($image_ids as $image): ?>
      							<img class="img-responsive" src="<?php echo wp_get_attachment_url($image); ?>" width="200" height="200">
      						<?php endforeach; ?>
      	          			</a>
      	        		</div>
      		        	<div class="col-xs-12 col-sm-9">
      		          		<p><?php echo $post['sponsor_overview']; ?></p>
      		          		<p><?php echo $post['sponsor_level']; ?></p>
      		        	</div>
      		        	<div class="col-xs-2 pull-right platinum-link">
      		          		<a href="http://www.tsico.com/" target="_blank"><?php echo $post['sponsor_name']; ?> <i class="fa fa-angle-right"></i></a>
      		        	</div>
      	      		</div>
      				<?php endforeach; ?>
      			<?php wp_reset_query(); ?>
      			<?php endif; ?>
    • #6251
      Jason
      Keymaster

      You’re thinking in the right direction: grabbing the meta and then using it for your conditionals. To save on code you could do things like $gold_or_silver = in_array($sponsor, array('gold', 'silver')); and use that in a few places. It’s really all about how how you want to handle it from here. If the sections are distinctly different then what you’re doing is fine, otherwise you can try to reduce code where it makes sense.

      I’m also not entirely sure why you’re calling wp_reset_query at the end, but I assume you have a reason?

      Are you having a particular problem otherwise?

    • #6252

      With what I’m currently doing it is not giving me the results I’m looking for. All the listings are coming out at the end under of the loop under Silver Sponsors, with just that header.

    • #6253
      Jason
      Keymaster

      I just noticed something.. in the piklist field you have the 'field' => 'sponsor_level', but then in the template you’re doing $sponsors = get_post_meta($post->ID, 'summit_sponsor_group', true);, which is then what you’re using to compare against the value to determine which section to show. I assume you mean summmit_sponsor_group to be sponsor_level?

      When in doubt, dump the value of the variable having the issue and see what value you’re getting. 🙂

    • #6254

      @steve do I still keep this line in the php?
      $sponsors = get_post_meta($post->ID, 'summit_sponsor_group', true);

      For some reason when I try and add the example you provided

      $levels = array(
      	'Platinum'
      	,'Gold'
      	,'Silver'
      );

      It has a problem with ‘Gold’ and doesn’t go any further.

    • #6255

      @Jason That’s because I want to pull in all the data from the piklist group, and then display the listings by the sponsor_level for each type

    • #6256

      This is the complete piklist group.

      <?php
      /*
      Title: Sponsors
      Post Type: piklist_sikka_summit
      Order: 100
      */
      piklist('field', array(
          'type' => 'group',
          'field' => 'summit_sponsor_group',
          'add_more' => true,
          'description' => 'Add sponsors as needed',
          'fields' => array(
            array(
              'type' => 'text',
              'field' => 'sponsor_name',
              'label' => 'Sponsor Name',
              'required' => true,
              'columns' => 12
            ),
            array(
              'type' => 'textarea',
              'field' => 'sponsor_overview',
              'label' => 'Sponsor Overview',
              'required' => true,
              'attributes' => array(
                'rows' => 8,      
                'class' => 'large-text',
              ),
              'columns' => 12
            ),
            array(
              'type' => 'text',
              'field' => 'sponsor_url',
              'label' => 'Sponsor URL',
              'required' => true,
              'columns' => 12
            ),
            array(
              'type' => 'select',
              'field' => 'sponsor_level',
              'label' => 'Sponsor Level',
              'required' => true,
              'attributes' => array(
                'class' => 'text'
              ),
              'choices' => array(
                '' => '-- Select --',
                'Platinum' => 'Platinum',
                'Gold' => 'Gold',
                'Silver' => 'Silver',
              ),
              'columns' => 4
            ),
            array(
              'type' => 'file',
              'field' => 'upload_basic',
              'label' => __('Sponsor Logo', 'piklist'),
              'description' => __('Image Size: 00px X 00px','piklist'),
              'required' => true,
              'options' => array(
                'modal_title' => __('Add Logo', 'piklist'),
                'button' => __('Add Logo', 'piklist'),
              ),
              'columns' => 4
            ),
          ),
          'on_post_status' => array(
              'value' => 'lock'
          )
        ));
      ?>
    • #6258
      Jason
      Keymaster

      Ohhhhh… Got it. 🙂

      You would do something like this then:

      
      <?php
      $groups = get_post_meta($post->ID, 'summit_sponsor_group', true);
      foreach($groups as $group): ?>
      
      <?php if ( 'Platinum' === $group['sponsor_level'] ): ?>
        Platinum HTML here
      
      <?php elseif ( 'Gold' === $group['sponsor_level'] ): ?>
        Gold HTML here
      
      <?php else: ?>
        Silver HTML here
      
      <?php endif; ?>
      <?php endforeach; ?>
      

      Up above you’re checking against the whole group which is an array; you just want to see if the ‘sponsor_level’ index is Platinum, Gold, or Silver. Make sense?

    • #6259

      OK, This is starting to do what I want, but what was not happening is listing the sponsors under each level. So I added back the original loop through the groups and its just listing all them each time. How do I go about looping through each segment and only showing the sponsors for each.

      Current Code

      			<?php
      			$groups = get_post_meta($post->ID, 'summit_sponsor_group', true);
      			foreach($groups as $group): ?>
      			<?php if ( 'Platinum' === $group['sponsor_level'] ): ?>
      	      		<div class="col-xs-12">
      	        		<h3><span>Platinum</span> Sponsors</h3>
      	      		</div>
      				<?php foreach($groups as $post): ?>
      	      		<div class="col-xs-12 platinum">
      	        		<div class="col-xs-12 col-sm-3">
      	          			<a href="<?php echo $post['sponsor_url']; ?>" target="_blank">
      	          			<?php $image_ids = $post['upload_basic']; ?>
      						<?php foreach ($image_ids as $image): ?>
      							<img class="img-responsive" src="<?php echo wp_get_attachment_url($image); ?>" width="200" height="200">
      						<?php endforeach; ?>
      	          			</a>
      	        		</div>
      		        	<div class="col-xs-12 col-sm-9">
      		        		<h4><?php echo $post['sponsor_name']; ?></h4>
      		          		<p><?php echo $post['sponsor_overview']; ?></p>
      		          		<p><?php echo $post['sponsor_level']; ?></p>
      		        	</div>
      		        	<div class="col-xs-2 pull-right platinum-link">
      		          		<a href="<?php echo $post['sponsor_url']; ?>" target="_blank"><?php echo $post['sponsor_name']; ?> <i class="fa fa-angle-right"></i></a>
      		        	</div>
      	      		</div>
      				<?php endforeach; ?>
      			<?php elseif ( 'Gold' === $group['sponsor_level'] ): ?>
      	      		<div class="col-xs-12">
      	        		<h3><span>Gold</span> Sponsors</h3>
      	      		</div>
      				<?php foreach($groups as $post): ?>
      	      		<div class="col-xs-12 gold">
      	        		<div class="col-xs-12 col-sm-3">
      	          			<a href="<?php echo $post['sponsor_url']; ?>" target="_blank">
      	          			<?php $image_ids = $post['upload_basic']; ?>
      						<?php foreach ($image_ids as $image): ?>
      							<img class="img-responsive" src="<?php echo wp_get_attachment_url($image); ?>" width="200" height="200">
      						<?php endforeach; ?>
      	          			</a>
      	        		</div>
      		        	<div class="col-xs-12 col-sm-9">
      		        		<h4><?php echo $post['sponsor_name']; ?></h4>
      		          		<p><?php echo $post['sponsor_overview']; ?></p>
      		          		<p><?php echo $post['sponsor_level']; ?></p>
      		        	</div>
      		        	<div class="col-xs-2 pull-right platinum-link">
      		          		<a href="<?php echo $post['sponsor_url']; ?>" target="_blank"><?php echo $post['sponsor_name']; ?> <i class="fa fa-angle-right"></i></a>
      		        	</div>
      	      		</div>
      				<?php endforeach; ?>
      			<?php else : ?>
      	      		<div class="col-xs-12">
      	        		<h3><span>Silver</span> Sponsors</h3>
      	      		</div>
      				<?php foreach($groups as $post): ?>
      	      		<div class="col-xs-12 silver">
      	        		<div class="col-xs-12 col-sm-3">
      	          			<a href="<?php echo $post['sponsor_url']; ?>" target="_blank">
      	          			<?php $image_ids = $post['upload_basic']; ?>
      						<?php foreach ($image_ids as $image): ?>
      							<img class="img-responsive" src="<?php echo wp_get_attachment_url($image); ?>" width="200" height="200">
      						<?php endforeach; ?>
      	          			</a>
      	        		</div>
      		        	<div class="col-xs-12 col-sm-9">
      		        		<h4><?php echo $post['sponsor_name']; ?></h4>
      		          		<p><?php echo $post['sponsor_overview']; ?></p>
      		          		<p><?php echo $post['sponsor_level']; ?></p>
      		        	</div>
      		        	<div class="col-xs-2 pull-right platinum-link">
      		          		<a href="<?php echo $post['sponsor_url']; ?>" target="_blank"><?php echo $post['sponsor_name']; ?> <i class="fa fa-angle-right"></i></a>
      		        	</div>
      	      		</div>
      				<?php endforeach; ?>
      			<?php endif; ?>
      			<?php endforeach; ?>
    • #6260
      Jason
      Keymaster

      Ok, I see what you’re looking for. There’s two ways you could do this:

      1. Split your field into three add-more group fields: one for Platinum, one for Gold, one for Silver. Then you simply pull in the meta for each one and they’re grouped how you want them.

      2. Sort the group results yourself and then loop through them:

      
      <?php
      $groups = get_post_meta($post->ID, 'summit_sponsor_group', true);
      $sorted_groups = array();
      foreach($groups as $group) {
        if ( !isset($sorted_groups[$group['sponsor_level']] ) {
          $sorted_groups[$group['sponsor_level']] = array();
        }
      
        $sorted_groups[$group['sponsor_level']][] = $group;
      }
      ?>
      
      <?php if ( !empty($sorted_groups['Platinum']) ): ?>
        <?php foreach($sorted_groups['Platinum'] as $group): ?>
          Platinum groups here
        <?php endforeach; ?>
      <?php endif; ?>
      
      <?php if ( !empty($sorted_groups['Gold']) ): ?>
        <?php foreach($sorted_groups['Gold'] as $group): ?>
          Gold groups here
        <?php endforeach; ?>
      <?php endif; ?>
      
      <?php if ( !empty($sorted_groups['Silver']) ): ?>
        <?php foreach($sorted_groups['Silver'] as $group): ?>
          Silver groups here
        <?php endforeach; ?>
      <?php endif; ?>
      

      You have a few different ways you could accomplish this, but they’ll look somewhat similar like that. This is more efficient than looping through the array multiple times as well.

      Hope this helps!

    • #6261

      @Jason Went with option one. Simply because I wanted to customize the data points and modify the styles of the output. Will use option two for some other things that I am working on.

      Thanks

      Michael

Viewing 14 reply threads
  • You must be logged in to reply to this topic.