What I want to do on the front page where I have recent posts, is to add a small upper corner badge or ribbon that says "NEW" to the thumbnails of posts that were published on today's date. Below is my index.php which controls the front page layout:
<?php
/**
* The main template file.
*
* Used to display the homepage when home.php doesn't exist.
*/
?>
<?php
// Get options
$mts_options = get_option(MTS_THEME_NAME);
// Featured Section 1 settings ( slider is here) --------------------------------
$slider_enabled = ( $mts_options['mts_featured_slider'] === '1' ) ? true : false;
if ( empty($mts_options['mts_featured_slider_cat']) || !is_array($mts_options['mts_featured_slider_cat']) ) {
$mts_options['mts_featured_slider_cat'] = array('0');
}
$slider_cat = implode(",", $mts_options['mts_featured_slider_cat']);
// Featured Section settings --------------------------------------------------
$f2_title = $mts_options['mts_featured_section_2_title'];
if ( empty($mts_options['mts_featured_section_2_cat']) || !is_array($mts_options['mts_featured_section_2_cat']) ) {
$mts_options['mts_featured_section_2_cat'] = array('0');
}
$f2_cat= implode(",", $mts_options['mts_featured_section_2_cat']);
// Featured Section 3 settings --------------------------------------------------
get_header(); ?>
<div id="page">
<div class="article">
<?php if ( $slider_enabled && is_home() && !is_paged() ) { ?>
<section id="featured-section-1" class="featured-section featured-section-1-1 clearfix">
<div class="slider-container">
<div class="primary-slider-container clearfix loading">
<div id="slider" class="primary-slider">
<?php
$slider_full = 'best-featuredfull';
if ( empty( $mts_options['mts_custom_slider'] ) ) {
$my_query = new WP_Query('cat='.$slider_cat.'&posts_per_page='.$mts_options['mts_featured_slider_num']);
while ( $my_query->have_posts() ) : $my_query->the_post();
?>
<div>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail($slider_full,array('title' => '')); ?>
<div class="slider-caption">
<?php if(isset($mts_options['mts_home_headline_meta_info']['enabled']) && $mts_options['mts_home_headline_meta_info']['enabled']){ ?>
<div class="sliderdate">
<?php if(isset($mts_options['mts_home_headline_meta_info']['enabled']['date']) == '1') { ?>
<span class="thetime updated"><?php the_time( get_option( 'date_format' ) ); ?></span>
<?php } ?>
</div>
<?php } ?>
<h2 class="slide-title"><?php the_title(); ?></h2>
</div>
<div class="post-day"><?php if (function_exists('wp_review_show_total')) wp_review_show_total(true, 'review-total-only'); ?></div>
</a>
</div>
<?php endwhile; wp_reset_postdata();
} else { ?>
<?php foreach( $mts_options['mts_custom_slider'] as $slide ) : ?>
<div>
<a href="<?php echo esc_url( $slide['mts_custom_slider_link'] ); ?>">
<?php echo wp_get_attachment_image( $slide['mts_custom_slider_image'], $slider_full, false, array('title' => '') ); ?>
<div class="slider-caption">
<div class="sliderdate"><?php echo esc_html( $slide['mts_custom_slider_title'] ); ?></div>
<h2 class="slide-title"><?php echo esc_html( $slide['mts_custom_slider_text'] ); ?></h2>
</div>
</a>
</div>
<?php endforeach; ?>
<?php } ?>
</div>
</div>
</div><!-- slider-container -->
</section>
<?php } ?>
<?php if( $mts_options['mts_featured_section_2'] === '1' && is_home() && !is_paged() ) {// featured section 2 ?>
<section id="featured-section-3" class="featured-section clearfix">
<?php if (!empty($f2_title)) { ?><h4 class="featured-section-title"><?php echo $f2_title;?></h4><?php } ?>
<?php
$f2_query = new WP_Query('cat='.$f2_cat.'&posts_per_page=4');
$f2_count = 1; if ($f2_query->have_posts()) : while ($f2_query->have_posts()) : $f2_query->the_post();
$f2_loop_params = best_mixed_layout_params( 1, 2, $f2_count );// see functions.php
$f2_clear_class = $f2_loop_params['clear_class'];
$f2_type_class = $f2_loop_params['box_class'];
$f2_loop_thumb = $f2_loop_params['thumb'];
$f2_show_excerpt = $f2_loop_params['show_excerpt'];
$f2_show_author = $f2_loop_params['show_author'];
$begin_f2_extra_wrappers = $f2_loop_params['open_wrappers'];
$end_f2_extra_wrappers = $f2_loop_params['close_wrappers'];
?>
<article class="post-box latestPost mixed <?php echo $f2_type_class;?> <?php echo $f2_clear_class;?>">
<?php echo $begin_f2_extra_wrappers; ?>
<div class="post-img">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="nofollow">
<?php the_post_thumbnail($f2_loop_thumb,array('title' => '')); ?>
</a>
</div>
<div class="post-data">
<div class="post-data-container">
<header>
<h2 class="title post-title"><?php the_title(); ?></h2>
<?php mts_the_postinfo(); ?>
</header>
<?php if ($f2_show_excerpt) : ?>
<div class="post-excerpt">
<?php echo mts_excerpt(40); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php echo $end_f2_extra_wrappers; ?>
</article><!--.post-box-->
<?php $f2_count++; endwhile;
endif; wp_reset_postdata();
?>
</section><!--#featured-section-3-->
<?php } ?>
<div id="content_box">
<?php $latest_posts_used = false;
if ( !empty( $mts_options['mts_featured_categories'] ) ) {
foreach ( $mts_options['mts_featured_categories'] as $section ) {
$category_id = $section['mts_featured_category'];
$featured_category_layout = $section['mts_featured_category_layout'];
$posts_num = $section['mts_featured_category_postsnum'];
if ( $category_id === 'latest' && ! $latest_posts_used ) {
$latest_posts_used = true;
$fc_section_class = ( in_array( $featured_category_layout, array( 'vertical', 'mixed' ) ) ) ? '' : ' '.$featured_category_layout;
?>
<section id="latest-posts" class="clearfix<?php echo $fc_section_class ?><?php //echo $fc_section_no_gap ?>">
<h4 class="featured-section-title"><?php _e( "Latest", "best" ); ?></h4>
<?php $j = 1; if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php best_the_homepage_article( $featured_category_layout, $j, true );?>
<?php $j++; endwhile; endif; ?>
<!--Start Pagination-->
<?php if (isset($mts_options['mts_pagenavigation_type']) && $mts_options['mts_pagenavigation_type'] == '1' ) { ?>
<?php $additional_loop = 0; mts_pagination($additional_loop['max_num_pages']); ?>
<?php } else { ?>
<div class="pagination pagination-previous-next">
<ul>
<li class="nav-previous"><?php next_posts_link( '<i class="fa fa-chevron-left"></i> '. __( 'Previous', 'best' ) ); ?></li>
<li class="nav-next"><?php previous_posts_link( __( 'Next', 'best' ).' <i class="fa fa-chevron-right"></i>' ); ?></li>
</ul>
</div>
<?php } ?>
<!--End Pagination-->
</section><!--#latest-posts-->
<?php } elseif ( $category_id !== 'latest' && !is_paged() ) {
$fc_section_class = ( in_array( $featured_category_layout, array( 'vertical', 'mixed' ) ) ) ? '' : ' '.$featured_category_layout;
?>
<section class="featured-section clearfix<?php echo $fc_section_class ?>">
<h4 class="featured-section-title"><?php echo get_cat_name($category_id); ?></h4>
<?php $cat_query = new WP_Query('cat='.$category_id.'&posts_per_page='.$posts_num); ?>
<?php $j = 1; if ($cat_query->have_posts()) : while ($cat_query->have_posts()) : $cat_query->the_post(); ?>
<?php best_the_homepage_article( $featured_category_layout, $j );?>
<?php $j++; endwhile; endif; wp_reset_postdata();?>
</section>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
What I have is this: to check the date and display the badge (not including css) but not sure where to input it exactly:
<?php
$days_old = (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset') *3600 ) ) / (60*60*24);
if ($days_old <=1) {
echo <div class="post-badge">NEW</div>;
}
?>
I want to insert it into The Latest Post Section. Any help would be greatly appreciated:)
Related
In the Buddyboss Group Loop are all groups displayed.
I want to add a filter that only groups with a specific categrorie are displayed in the first grid.
I added the comment to the first grid and found out that i can display another grid when
i duplicate the code a second time, but i have the filter problem.
Then i want to add another grid with also a filter to another group categorie.
How can i achieve this?
I dont get it how to add a filter.
<?php
/**
* BuddyBoss - Groups Loop
*
* #since BuddyPress 3.0.0
* #version 3.1.0
*/
bp_nouveau_before_loop(); ?>
<?php if ( bp_get_current_group_directory_type() ) : ?>
<div class="bp-feedback info">
<span class="bp-icon" aria-hidden="true"></span>
<p class="current-group-type"><?php bp_current_group_directory_type_message(); ?></p>
</div>
<?php endif; ?>
<?php $cover_class = bp_disable_group_cover_image_uploads() ? 'bb-cover-disabled' : 'bb-cover-enabled'; ?>
<?php if ( bp_has_groups( bp_ajax_querystring( 'groups' ) ) ) : ?>
<?php bp_nouveau_pagination( 'top' ); ?>
//FIRST GRID ONLY FOR "KOMMISIONEN"
<ul id="groups-list-kommissionen" class="<?php bp_nouveau_loop_classes(); ?> <?php echo $cover_class; ?>">
<?php
while ( bp_groups() ) :
bp_the_group();
?>
<li <?php bp_group_class( array( 'item-entry' ) ); ?> data-bp-item-id="<?php bp_group_id(); ?>" data-bp-item-component="groups">
<div class="list-wrap">
<?php if( !bp_disable_group_cover_image_uploads() ) { ?>
<?php
$group_cover_image_url = bp_attachments_get_attachment( 'url', array(
'object_dir' => 'groups',
'item_id' => bp_get_group_id(),
) );
$default_group_cover = buddyboss_theme_get_option( 'buddyboss_group_cover_default', 'url' );
$group_cover_image_url = $group_cover_image_url ?: $default_group_cover;
?>
<div class="bs-group-cover only-grid-view"><img src="<?php echo $group_cover_image_url; ?>"></div>
<?php } ?>
<?php if ( ! bp_disable_group_avatar_uploads() ) : ?>
<div class="item-avatar">
<?php bp_group_avatar( bp_nouveau_avatar_args() ); ?>
<div class="groups-loop-buttons only-grid-view">
<?php bp_nouveau_groups_loop_buttons(); ?>
</div>
</div>
<?php endif; ?>
<div class="item">
<div class="item-block">
<h2 class="list-title groups-title"><?php bp_group_link(); ?></h2>
<?php if ( bp_nouveau_group_has_meta() ) : ?>
<p class="item-meta group-details only-list-view"><?php bp_nouveau_group_meta(); ?></p>
<p class="item-meta group-details only-grid-view"><?php
$meta = bp_nouveau_get_group_meta();
echo $meta['status']; ?>
</p>
<?php endif; ?>
<p class="last-activity item-meta">
<?php
printf(
/* translators: %s = last activity timestamp (e.g. "active 1 hour ago") */
__( 'active %s', 'buddyboss-theme' ),
bp_get_group_last_active()
);
?>
</p>
</div>
<div class="item-desc group-item-desc only-list-view"><?php bp_group_description_excerpt( false , 150 ) ?></div>
<?php bp_nouveau_groups_loop_item(); ?>
<div class="groups-loop-buttons footer-button-wrap"><?php bp_nouveau_groups_loop_buttons(); ?></div>
<div class="group-members-wrap only-grid-view">
<?php echo buddyboss_theme()->buddypress_helper()->group_members( bp_get_group_id(), array( 'member', 'mod', 'admin' ) ); ?>
</div>
</div>
</div>
</li>
<?php endwhile; ?>
<?php bp_nouveau_pagination( 'bottom' ); ?>
<?php else : ?>
<?php bp_nouveau_user_feedback( 'groups-loop-none' ); ?>
<?php endif; ?>
<?php
bp_nouveau_after_loop();
Okay i found the answer by trying all possible ways.
Here is the solution code.
<?php
/**
* BuddyBoss - Groups Loop
*
* #since BuddyPress 3.0.0
* #version 3.1.0
*/
bp_nouveau_before_loop(); ?>
<?php if ( bp_get_current_group_directory_type() ) : ?>
<div class="bp-feedback info">
<span class="bp-icon" aria-hidden="true"></span>
<p class="current-group-type"><?php bp_current_group_directory_type_message(); ?></p>
</div>
<?php endif; ?>
<?php $cover_class = bp_disable_group_cover_image_uploads() ? 'bb-cover-disabled' : 'bb-cover-enabled'; ?>
<?php if ( bp_has_groups( 'group_type=kommission' ) ) : ?>
<?php bp_nouveau_pagination( 'top' ); ?>
<ul id="groups-list-kommissionen" class="<?php bp_nouveau_loop_classes(); ?> <?php echo $cover_class; ?>">
<?php
while ( bp_groups() ) :
bp_the_group();
?>
<li <?php bp_group_class( array( 'item-entry' ) ); ?> data-bp-item-id="<?php bp_group_id(); ?>" data-bp-item-component="groups">
<div class="list-wrap">
<?php if( !bp_disable_group_cover_image_uploads() ) { ?>
<?php
$group_cover_image_url = bp_attachments_get_attachment( 'url', array(
'object_dir' => 'groups',
'item_id' => bp_get_group_id(),
) );
$default_group_cover = buddyboss_theme_get_option( 'buddyboss_group_cover_default', 'url' );
$group_cover_image_url = $group_cover_image_url ?: $default_group_cover;
?>
<div class="bs-group-cover only-grid-view"><img src="<?php echo $group_cover_image_url; ?>"></div>
<?php } ?>
<?php if ( ! bp_disable_group_avatar_uploads() ) : ?>
<div class="item-avatar">
<?php bp_group_avatar( bp_nouveau_avatar_args() ); ?>
<div class="groups-loop-buttons only-grid-view">
<?php bp_nouveau_groups_loop_buttons(); ?>
</div>
</div>
<?php endif; ?>
<div class="item">
<div class="item-block">
<h2 class="list-title groups-title"><?php bp_group_link(); ?></h2>
<?php if ( bp_nouveau_group_has_meta() ) : ?>
<p class="item-meta group-details only-list-view"><?php bp_nouveau_group_meta(); ?></p>
<p class="item-meta group-details only-grid-view"><?php
$meta = bp_nouveau_get_group_meta();
echo $meta['status']; ?>
</p>
<?php endif; ?>
<p class="last-activity item-meta">
<?php
printf(
/* translators: %s = last activity timestamp (e.g. "active 1 hour ago") */
__( 'active %s', 'buddyboss-theme' ),
bp_get_group_last_active()
);
?>
</p>
</div>
<div class="item-desc group-item-desc only-list-view"><?php bp_group_description_excerpt( false , 150 ) ?></div>
<?php bp_nouveau_groups_loop_item(); ?>
<div class="groups-loop-buttons footer-button-wrap"><?php bp_nouveau_groups_loop_buttons(); ?></div>
<div class="group-members-wrap only-grid-view">
<?php echo buddyboss_theme()->buddypress_helper()->group_members( bp_get_group_id(), array( 'member', 'mod', 'admin' ) ); ?>
</div>
</div>
</div>
</li>
<?php endwhile; ?>
</ul>
<?php bp_nouveau_pagination( 'bottom' ); ?>
<?php else : ?>
<?php bp_nouveau_user_feedback( 'groups-loop-none' ); ?>
<?php endif; ?>
<?php if ( bp_has_groups( 'group_type=task-force' ) ) : ?>
<?php bp_nouveau_pagination( 'top' ); ?>
<ul id="groups-list-taskForces" class="<?php bp_nouveau_loop_classes(); ?> <?php echo $cover_class; ?>">
<?php
while ( bp_groups() ) :
bp_the_group();
?>
<li <?php bp_group_class( array( 'item-entry' ) ); ?> data-bp-item-id="<?php bp_group_id(); ?>" data-bp-item-component="groups">
<div class="list-wrap">
<?php if( !bp_disable_group_cover_image_uploads() ) { ?>
<?php
$group_cover_image_url = bp_attachments_get_attachment( 'url', array(
'object_dir' => 'groups',
'item_id' => bp_get_group_id(),
) );
$default_group_cover = buddyboss_theme_get_option( 'buddyboss_group_cover_default', 'url' );
$group_cover_image_url = $group_cover_image_url ?: $default_group_cover;
?>
<div class="bs-group-cover only-grid-view"><img src="<?php echo $group_cover_image_url; ?>"></div>
<?php } ?>
<?php if ( ! bp_disable_group_avatar_uploads() ) : ?>
<div class="item-avatar">
<?php bp_group_avatar( bp_nouveau_avatar_args() ); ?>
<div class="groups-loop-buttons only-grid-view">
<?php bp_nouveau_groups_loop_buttons(); ?>
</div>
</div>
<?php endif; ?>
<div class="item">
<div class="item-block">
<h2 class="list-title groups-title"><?php bp_group_link(); ?></h2>
<?php if ( bp_nouveau_group_has_meta() ) : ?>
<p class="item-meta group-details only-list-view"><?php bp_nouveau_group_meta(); ?></p>
<p class="item-meta group-details only-grid-view"><?php
$meta = bp_nouveau_get_group_meta();
echo $meta['status']; ?>
</p>
<?php endif; ?>
<p class="last-activity item-meta">
<?php
printf(
/* translators: %s = last activity timestamp (e.g. "active 1 hour ago") */
__( 'active %s', 'buddyboss-theme' ),
bp_get_group_last_active()
);
?>
</p>
</div>
<div class="item-desc group-item-desc only-list-view"><?php bp_group_description_excerpt( false , 150 ) ?></div>
<?php bp_nouveau_groups_loop_item(); ?>
<div class="groups-loop-buttons footer-button-wrap"><?php bp_nouveau_groups_loop_buttons(); ?></div>
<div class="group-members-wrap only-grid-view">
<?php echo buddyboss_theme()->buddypress_helper()->group_members( bp_get_group_id(), array( 'member', 'mod', 'admin' ) ); ?>
</div>
</div>
</div>
</li>
<?php endwhile; ?>
</ul>
<?php bp_nouveau_pagination( 'bottom' ); ?>
<?php else : ?>
<?php bp_nouveau_user_feedback( 'groups-loop-none' ); ?>
<?php endif; ?>
<?php
bp_nouveau_after_loop();
I'm struggling to add new categories in search.php. But I failed. Actually the php file is beyond me. I need help :( I have 4 categories, location, sub-location, city and municipality. But these search codes use only titles. How can I add these categories in search.php file? Anybody can say the resolve please?
if( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'noo_property' ) :
?>
<?php
global $wp_query;
$show_map = noo_get_option('noo_property_listing_map',1);
$show_search = noo_get_option('noo_property_listing_search',1);
$disable_map = ( ! $show_map && $show_search ) ? ' disable_map="true"' : '';
$disable_search_form = ( $show_map && ! $show_search ) ? ' disable_search_form="true"' : '';
$search_layout = noo_get_option('noo_property_listing_map_layout','horizontal');
$advanced_search = ($show_search && noo_get_option('noo_property_listing_advanced_search',0)) ? ' advanced_search="true"' : '';
$title = __('Properties matching your search', 'noo');
?>
<?php get_header();
?>
<div class="container-wrap">
<?php if(!empty($show_map) || !empty($show_search)):?>
<?php echo do_shortcode('[noo_advanced_search_property style="'.$search_layout.'"' . $disable_map . $disable_search_form . $advanced_search . ']');?>
<?php endif;?>
<div class="main-content container-boxed max offset">
<div class="row">
<div class="<?php noo_main_class(); ?>" role="main">
<?php if ( have_posts() ) : ?>
<?php
$args = array(
'query' => $wp_query,
'title' => $title,
'display_mode' => true,
'default_mode' => '',
'show_pagination' => true,
'ajax_pagination' => false,
'show_orderby' => noo_get_option('noo_property_listing_orderby', 1)
);
re_property_loop( $args ); ?>
<?php else : ?>
<?php noo_get_layout( 'no-content' ); ?>
<?php endif; ?>
<?php
wp_reset_query();
wp_reset_postdata();
?>
</div> <!-- /.main -->
<?php get_sidebar(); ?>
</div><!--/.row-->
</div><!--/.container-boxed-->
</div><!--/.container-wrap-->
<?php get_footer(); ?>
<?php else :
?>
<?php get_header(); ?>
<div class="container-wrap">
<div class="main-content container-boxed max offset">
<div class="row">
<div class="<?php noo_main_class(); ?> <?php noo_page_class(); ?>" role="main">
<h1><?php _e('Results For', 'noo'); ?><span>"<?php the_search_query(); ?>"</span></h1>
<div id="search-results">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php if( get_post_type($post->ID) == 'post' ){ ?>
<article class="result">
<div class="content-featured">
<?php noo_featured_content( $post->ID ); ?>
</div>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Blog Post', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php }
else if( get_post_type($post->ID) == 'page' ){ ?>
<article class="result">
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Page', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php }
else if( get_post_type($post->ID) == 'product' ){ ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''. get_the_post_thumbnail($post->ID, 'full', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Product', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } else if( get_post_type($post->ID) == 'noo_property' ){ ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''. get_the_post_thumbnail($post->ID, 'property-image', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Property', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } else { ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''.get_the_post_thumbnail($post->ID, 'full', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } ?>
<?php endwhile;
else: echo "<p>" . __('No results found', 'noo') . "</p>"; endif;?>
</div><!--/search-results-->
<?php noo_pagination(); ?>
</div> <!-- /.main -->
<?php get_sidebar(); ?>
</div><!--/.row-->
</div><!--/.container-boxed-->
</div><!--/.container-wrap-->
<?php get_footer(); ?>
<?php endif; ?>
Am I looking wrong php file? Or true
My page is http://prowrestlingnews.co. I am looking to remove the excerpts from the homepage, as this is a news headline website. I prefer for the main content (middle section) to display headlines like it does on the right sidebar with the "Latest Wrestling News" widget.
I have been playing around with the index and functions file, but can't seem to remove the excerpts. Any help would be greatly appreciated!
Here's the index.php file:
<?php
/**
* The main template file.
*
* Used to display the homepage when home.php doesn't exist.
*/
?>
<?php $mts_options = get_option(MTS_THEME_NAME); ?>
<?php get_header(); ?>
<div id="page">
<div class="article">
<div id="content_box">
<?php if ( !is_paged() ) { ?>
<?php if ( is_home() && $mts_options['mts_featured_slider'] == '1' ) { ?>
<div class="primary-slider-container clearfix loading">
<div id="slider" class="primary-slider">
<?php if ( empty( $mts_options['mts_custom_slider'] ) ) { ?>
<?php
// prevent implode error
if ( empty( $mts_options['mts_featured_slider_cat'] ) || !is_array( $mts_options['mts_featured_slider_cat'] ) ) {
$mts_options['mts_featured_slider_cat'] = array('0');
}
$slider_cat = implode( ",", $mts_options['mts_featured_slider_cat'] );
$slider_query = new WP_Query('cat='.$slider_cat.'&posts_per_page='.$mts_options['mts_featured_slider_num']);
while ( $slider_query->have_posts() ) : $slider_query->the_post();
?>
<div>
<a href="<?php echo esc_url( get_the_permalink() ); ?>">
<?php the_post_thumbnail('schema-slider',array('title' => '')); ?>
<div class="slide-caption">
<h2 class="slide-title"><?php the_title(); ?></h2>
</div>
</a>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php } else { ?>
<?php foreach( $mts_options['mts_custom_slider'] as $slide ) : ?>
<div>
<a href="<?php echo esc_url( $slide['mts_custom_slider_link'] ); ?>">
<?php echo wp_get_attachment_image( $slide['mts_custom_slider_image'], 'schema-slider', false, array('title' => '') ); ?>
<div class="slide-caption">
<h2 class="slide-title"><?php echo esc_html( $slide['mts_custom_slider_title'] ); ?></h2>
</div>
</a>
</div>
<?php endforeach; ?>
<?php } ?>
</div><!-- .primary-slider -->
</div><!-- .primary-slider-container -->
<?php } ?>
<?php
$featured_categories = array();
if ( !empty( $mts_options['mts_featured_categories'] ) ) {
foreach ( $mts_options['mts_featured_categories'] as $section ) {
$category_id = $section['mts_featured_category'];
$featured_categories[] = $category_id;
$posts_num = $section['mts_featured_category_postsnum'];
if ( 'latest' == $category_id ) { ?>
<?php $j = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article class="latestPost excerpt <?php echo (++$j % 3 == 0) ? 'last' : ''; ?>">
<?php mts_archive_post(); ?>
</article>
<?php endwhile; endif; ?>
<?php if ( $j !== 0 ) { // No pagination if there is no posts ?>
<?php mts_pagination(); ?>
<?php } ?>
<?php } else { // if $category_id != 'latest': ?>
<h3 class="featured-category-title"><?php echo esc_html( get_cat_name( $category_id ) ); ?></h3>
<?php
$j = 0;
$cat_query = new WP_Query('cat='.$category_id.'&posts_per_page='.$posts_num);
if ( $cat_query->have_posts() ) : while ( $cat_query->have_posts() ) : $cat_query->the_post(); ?>
<article class="latestPost excerpt <?php echo (++$j % 3 == 0) ? 'last' : ''; ?>">
<?php mts_archive_post(); ?>
</article>
<?php
endwhile; endif; wp_reset_postdata();
}
}
}
?>
<?php } else { //Paged ?>
<?php $j = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article class="latestPost excerpt <?php echo (++$j % 3 == 0) ? 'last' : ''; ?>">
<?php mts_archive_post(); ?>
</article>
<?php endwhile; endif; ?>
<?php if ( $j !== 0 ) { // No pagination if there is no posts ?>
<?php mts_pagination(); ?>
<?php } ?>
<?php } ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Functions.php file viewed at https://gist.github.com/pwz2k/16a8aa858ee3d739276c67d56fbccca9
I have a small problem. And I am not sure why am I getting this problem. See what I did was I limited a page to "Public Member" and I want this page to be access Library members too because library members would have access to all pages. So what I did was I added a simple condition like this:
if ( $user_role == "library-Member" && $pageLevel == "public-member" ) {
$displayPost = "true";
}
And in my post I added this condition
if ( $displayPost == "true" ) {
.. execute html stuff ..
}
else {
wp_redirect( 'http://sample.org/restricted-area' );
exit;
}
But somehow the condition is not working. I have also checking var_dump($displayPost) the output is true
Can someone help me please? Thanks.
EDIT
Image Samples:
1. Sample 1
2. Sample 2
CODE:
<?php
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if ( !is_user_logged_in() ) { $user_role = array( 'public-member' ); }
$pageLevel = get_post_meta( $post->ID, 'user_type', true );
if ( $user_role == "library-Member" && $pageLevel == "public-member" ) {
$displayPost = "true";
}
if ( $displayPost == "true" ) {
?>
<div class="main wrap cf">
<div class="row">
<div class="col-8 main-content">
<?php if (have_posts()): the_post(); endif; // load the page ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('page-content'); ?>>
<?php if (Bunyad::posts()->meta('page_title') != 'no'): ?>
<header class="post-header">
<?php if (has_post_thumbnail()): ?>
<div class="featured">
<a href="<?php $url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); echo $url[0]; ?>" title="<?php the_title_attribute(); ?>">
<?php if ((!in_the_loop() && Bunyad::posts()->meta('layout_style') == 'full') OR Bunyad::core()->get_sidebar() == 'none'): // largest images - no sidebar? ?>
<?php the_post_thumbnail('main-full', array('title' => strip_tags(get_the_title()))); ?>
<?php else: ?>
<?php the_post_thumbnail('main-slider', array('title' => strip_tags(get_the_title()))); ?>
<?php endif; ?>
</a>
</div>
<?php endif; ?>
<h1 class="main-heading">
<?php the_title(); ?>
</h1>
</header><!-- .post-header -->
<?php endif; ?>
<?php Bunyad::posts()->the_content(); ?>
</div>
</div>
<?php Bunyad::core()->theme_sidebar(); ?>
</div> <!-- .row -->
</div> <!-- .main -->
<?php
} else {
wp_redirect( 'http://sample.org/restricted-area' );
exit;
}
?>
I have written a neat responsive slider for my Wordpress featured articles (feel free to use it):
<?php
$responsive = 'on' != get_option('henrik_responsive_layout') ? false : true;
$featured_auto_class = '';
if ( 'on' == get_option('henrik_slider_auto') ) $featured_auto_class .= ' et_slider_auto et_slider_speed_' . get_option('henrik_slider_autospeed');
?>
<div id="featured" class="<?php if ( $responsive ) echo 'flexslider' . $featured_auto_class; else echo 'et_cycle'; ?>">
<a id="left-arrow" href="#"><?php esc_html_e('Previous','henrik'); ?></a>
<a id="right-arrow" href="#"><?php esc_html_e('Next','henrik'); ?></a>
<?php if ( $responsive ) { ?>
<ul class="slides">
<?php } else { ?>
<div id="slides">
<?php } ?>
<?php global $ids;
$ids = array();
$arr = array();
$i=0;
$featured_cat = get_option('henrik_feat_cat');
$featured_num = (int) get_option('henrik_featured_num');
if (get_option('henrik_use_pages') == 'false') query_posts("showposts=$featured_num&cat=".get_cat_ID($featured_cat));
else {
global $pages_number;
if (get_option('henrik_feat_pages') <> '') $featured_num = count(get_option('henrik_feat_pages'));
else $featured_num = $pages_number;
query_posts(array
('post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC',
'post__in' => (array) get_option('henrik_feat_pages'),
'showposts' => (int) $featured_num
));
} ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
global $post; ?>
<?php if ( $responsive ) { ?>
<li class="slide">
<?php } else { ?>
<div class="slide">
<?php } ?>
<?php
$width = $responsive ? 960 : 958;
$height = 340;
$small_width = 95;
$small_height = 54;
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Featured');
$arr[$i]['thumbnail'] = get_thumbnail($small_width,$small_height,'',$titletext,$titletext,false,'Small');
$arr[$i]['titletext'] = $titletext;
$thumb = $thumbnail["thumb"];
print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, ''); ?>
<div class="featured-top-shadow"></div>
<div class="featured-bottom-shadow"></div>
<div class="featured-description">
<div class="feat_desc">
<p class="meta-info"><?php esc_html_e('Posted','henrik'); ?> <?php esc_html_e('by','henrik'); ?> <?php the_author_posts_link(); ?> <?php esc_html_e('on','henrik'); ?> <?php the_time(esc_attr(get_option('henrik_date_format'))) ?></p>
<h2 class="featured-title"><?php the_title(); ?></h2>
<p><?php truncate_post(410); ?></p>
</div>
<?php esc_html_e('Read More', 'henrik'); ?>
</div> <!-- end .description -->
<?php if ( $responsive ) { ?>
</li> <!-- end .slide -->
<?php } else { ?>
</div> <!-- end .slide -->
<?php } ?>
<?php $ids[] = $post->ID; $i++; endwhile; endif; wp_reset_query(); ?>
<?php if ( $responsive ) { ?>
</ul> <!-- end .slides -->
<?php } else { ?>
</div> <!-- end #slides -->
<?php } ?>
</div> <!-- end #featured -->
<div id="controllers" class="clearfix">
<ul>
<?php for ($i = 0; $i < $featured_num; $i++) { ?>
<li>
<div class="controller">
<a href="#"<?php if ( $i == 0 ) echo ' class="active"'; ?>>
<?php print_thumbnail( $arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height ); ?>
<span class="overlay"></span>
</a>
</div>
</li>
<?php } ?>
</ul>
<div id="active_item"></div>
</div> <!-- end #controllers -->
It selects a custom category and returns a custom amount of posts. The problem is that it will display the posts in the order of which they were created. I want to choose my own order, so that I can select which posts displays first and so on.
So, is it possible to select which order the returned posts are displayed? Maybe by targeting specific IDs?
It looks like you're already doing this by using 'orderby' => 'menu_order'. All you need to do now is set the menu order in the WordPress interface -- all new posts default to 0. Or you change the orderby argument to something else.