Created
August 27, 2014 00:18
-
-
Save ernilambar/ad31b89b459e954fc950 to your computer and use it in GitHub Desktop.
Example Page Template for showing featured posts [NS Featured Posts]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: Featured | |
*/ | |
?> | |
<?php | |
$custom_query_args = array( | |
'post_type' => 'post', | |
'meta_key' => '_is_ns_featured_post', | |
'meta_value' => 'yes', | |
); | |
// Get current page and append to custom query parameters array | |
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; | |
$custom_query = new WP_Query( $custom_query_args ); ?> | |
<?php | |
// Pagination fix | |
global $wp_query; | |
$temp_query = $wp_query; | |
$wp_query = NULL; | |
$wp_query = $custom_query; | |
?> | |
<?php if ( $custom_query->have_posts() ) : ?> | |
<!-- the loop --> | |
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?> | |
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> | |
<?php the_excerpt(); ?> | |
<?php endwhile; ?> | |
<!-- end of the loop --> | |
<!-- pagination here --> | |
<?php | |
// Custom query loop pagination | |
previous_posts_link( 'Older Posts' ); | |
next_posts_link( 'Newer Posts', $custom_query->max_num_pages ); | |
?> | |
<?php else: ?> | |
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> | |
<?php endif; ?> | |
<?php | |
// Reset postdata | |
wp_reset_postdata(); | |
?> | |
<?php | |
// Reset main query object | |
$wp_query = NULL; | |
$wp_query = $temp_query; | |
?> |
how to show featured but per category? Not list all featured post, then just featured per post category? Suggestion of code pls? Tnx.
Hi I am a newbie to this plugin. Can someone teach me how to make this as a schortcode? So that I can apply any page etc. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@amitsarker89 Try changing the args so that
'meta_value' => 'no'