Answer the question
In order to leave comments, you need to log in
How to add a new tab with taxonomy output for a specific meta field?
Hello! There is a wordpress ad board with classipress theme installed
On the main page with ads, I want to add a tab with new ads instead of random and popular ones which has a meta field (a custom field in the ad) 'cp_new'
Main page tab code
<div class="tabcontrol">
<?php $ad_tabs = cp_get_ads_listing_my_tabs(); ?>
<ul class="tabnavig">
<?php $tab_cnt = 1; ?>
<?php foreach ( $ad_tabs as $ad_tab => $ad_tab_args ) { ?>
<li>
<a href="#block<?php echo $tab_cnt++; ?>" id="<?php echo esc_attr( $ad_tab ); ?>" <?php if ( 2 < $tab_cnt ) { echo ' class="dynamic-content"'; } ?>>
<span class="big"><?php echo esc_html( $ad_tab_args['title'] ); ?></span>
</a>
</li>
<?php } ?>
</ul>
<?php $tab_cnt = 1; ?>
<?php foreach ( $ad_tabs as $ad_tab => $ad_tab_args ) { ?>
<!-- tab block -->
<div id="block<?php echo $tab_cnt; ?>">
<div class="clr"></div>
<?php if ( 1 === $tab_cnt && function_exists( $ad_tab_args['callback'] ) ) {
call_user_func( $ad_tab_args['callback'] );
} else { ?>
<div class="post-block-out post-block <?php echo esc_attr( $ad_tab ); ?>-placeholder">
<!-- dynamically loaded content -->
</div>
<?php } ?>
<?php $tab_cnt++; ?>
</div>
<!-- /tab block -->
<?php } ?>
</div>
<!-- /tabcontrol -->
function cp_get_ads_listing_my_tabs() {
$defaults = array(
'latest' => array(
'title' => 'Б/у запчасти',
'callback' => 'cp_output_latest_ads_listing',
),
'popular' => array(
'title' => 'Новые запчасти',
'callback' => 'cp_output_new_parts_listing',
)
);
$tabs = apply_filters( 'cp_ads_listing_tabs', $defaults );
return $tabs;
}
/**
* Outputs a listing of new parts.
*
*
*/
function cp_output_new_parts_listing() {
global $wp_query;
remove_action( 'appthemes_after_endwhile', 'cp_do_pagination' );
$post_type_url = add_query_arg( array( 'paged' => 2 ), get_post_type_archive_link( APP_POST_TYPE ) );
// show all parts but make sure the sticky featured parts don't show up first
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
query_posts( array( 'post_type' => APP_POST_TYPE, 'post_meta' => 'cp_new', 'ignore_sticky_posts' => 1, 'paged' => $paged ) );
$total_pages = max( 1, absint( $wp_query->max_num_pages ) );
get_template_part( 'loop', 'ad_listing' );
if ( $total_pages > 1 ) {
cp_the_view_more_ads_link( $post_type_url );
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question