This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Tagged: , ,

Tabs in Post Type

  • Creator
    Topic
  • #13237
    iphoenix
    Participant

    I tried to make a post type to use different post meta values to separate tabs, but I think I’m making a mistake with how I structure the interaction with the while.

    <code>
    <?php
    /* Template Name: books List */
    get_header(); 
    $posttype = 'books';
    $prefix = $posttype . '_';
    $postobj = get_post_type_object( $posttype );
    $postsingular = $postobj->labels->singular_name;
    $postplural = $postobj->labels->name;
    $option_name = themeblvd_get_option_name();
    $options = get_option( $option_name );
    ?>
    
    <div id="<?php echo $posttype ?>" class="em_tables"> 
    <div class="tab-content">	
    		<h2><?php echo $postplural ?></h2>
    		    <div class="tab-pane active" id="<?php echo $posttype ?>_records">
    		    	<table class="table"><tr><td>
    				      <p>
    				        Search: <input id="filter" type="text"/>
    				        <a href="#clear" class="clear-filter" title="clear filter"><strong>clear</strong></a>
    				      </p>
    		  		</td><td style="text-align: right">
    		    	<?php echo do_shortcode('[button link="/ticket/add/" color="warning" icon_before="plus-sign"]Add ' . $postsingular .'[/button]'); ?>
    				</td></tr></table>
    				
    
    <div class="element element-tabs">
    	<div class="tabbable fixed-height tb-tabs-framed">
    	<ul class="nav nav-pills">
    		<li class="active"><a href="#tabs_<?php echo $posttype; ?>-tab_1" data-toggle="pill" title="Draft">Draft</a></li>
    		<li class=""><a href="#tabs_<?php echo $posttype; ?>-tab_2" data-toggle="pill" title="Reviewed">Reviewed</a></li>
    		<li class=""><a href="#tabs_<?php echo $posttype; ?>-tab_4" data-toggle="pill" title="Approved">Approved</a></li>	</ul>
    
    
    				<?php query_posts('post_type='. $posttype .'&posts_per_page=' . $options["page_posts"]); 
    
    				if (have_posts()) : while (have_posts()) : the_post(); 
    
    				$title= str_ireplace('"', '', trim(get_the_title()));
    				$desc= str_ireplace('"', '', trim(get_the_content()));
    				$createdby = get_post_meta( $post->ID, $prefix . 'createdby', true );
    				$status = get_post_meta( $post->ID, $prefix . 'status', true );
    				$importance = get_post_meta( $post->ID, $prefix . 'importance', true );
    				$responsible = get_post_meta( $post->ID, $prefix . 'responsble', true );
    
    echo '<div class="tab-content">';
    	if ($status = 'draft') {
    	echo '<div id="tabs_'. $posttype .'-tab_1" class="tab-pane fade active in clearfix">
    					<table class="'. $options["table_class"].'>
    						<thead>
    							<tr>
    								<th>'. $postsingular .'</th>
    								<th data-hide="phone">Status</th>
    								<th data-hide="phone, tablet">Created By</th>
    							</tr>
    						</thead>
    						<tbody>
    							
    							<tr>';
    					echo		'<td><a title="'. $title .'" href="'. the_permalink() .'"><strong>'. $title .'</strong></a></td>';
    					echo		'<td>'. $status .'</td>';
    					echo		'<td>'. $createdby .'</td>';
    					echo	'</tr>
    					
    					</tbody>
    					<tfoot class="hide-if-no-paging">
    			        <tr>
    			          <td colspan="5">
    			            <div class="pagination pagination-centered"></div>
    			          </td>
    			        </tr>
    			        </tfoot>
    					</table>
    		</div><!-- #tabs_1 (end) -->';
    	}
    
    if ($status = 'reviewed') {
    	echo '<div id="tabs_'. $posttype .'-tab_2" class="tab-pane fade active in clearfix">
    					<table class="'. $options["table_class"].'>
    						<thead>
    							<tr>
    								<th>'. $postsingular .'</th>
    								<th data-hide="phone">Status</th>
    								<th data-hide="phone, tablet">Created By</th>
    							</tr>
    						</thead>
    						<tbody>
    							
    							<tr>';
    					echo		'<td><a title="'. $title .'" href="'. the_permalink() .'"><strong>'. $title .'</strong></a></td>';
    					echo		'<td>'. $status .'</td>';
    					echo		'<td>'. $createdby .'</td>';
    					echo	'</tr>
    					
    					</tbody>
    					<tfoot class="hide-if-no-paging">
    			        <tr>
    			          <td colspan="5">
    			            <div class="pagination pagination-centered"></div>
    			          </td>
    			        </tr>
    			        </tfoot>
    					</table>
    		</div><!-- #tabs_2 (end) -->';
    }
    
    if ($status = 'approved') {
    	echo '<div id="tabs_'. $posttype .'-tab_3" class="tab-pane fade active in clearfix">
    					<table class="'. $options["table_class"].'>
    						<thead>
    							<tr>
    								<th>'. $postsingular .'</th>
    								<th data-hide="phone">Status</th>
    								<th data-hide="phone, tablet">Created By</th>
    							</tr>
    						</thead>
    						<tbody>
    							
    							<tr>';
    					echo		'<td><a title="'. $title .'" href="'. the_permalink() .'"><strong>'. $title .'</strong></a></td>';
    					echo		'<td>'. $status .'</td>';
    					echo		'<td>'. $createdby .'</td>';
    					echo	'</tr>
    					
    					</tbody>
    					<tfoot class="hide-if-no-paging">
    			        <tr>
    			          <td colspan="5">
    			            <div class="pagination pagination-centered"></div>
    			          </td>
    			        </tr>
    			        </tfoot>
    					</table>
    		</div><!-- #tabs_3 (end) -->';
    }
    
    echo '</div><!-- .tabbable (end) -->';
    
     endwhile; endif; ?>
    </div><!-- .element (end) -->
    			</div>
    	</div>
    </div>
    <?php get_footer(); ?>
    </code>

    Any suggestions on how to do something like this properly?

  • You must be logged in to reply to this topic.