Created
May 12, 2014 11:09
-
-
Save pommiegranit/f1df7afae016a8b6e191 to your computer and use it in GitHub Desktop.
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 | |
/* | |
Plugin Name: Post Front Page | |
Plugin URI: http://premium.wpmudev.org | |
Description: Allows a post (not page) to become the front page of a WordPress site | |
Author: Chris Knowles | |
Version: 1.0 | |
Author URI: http://twitter.com/ChrisKnowles | |
*/ | |
// intercept the main query | |
function pfp_pre_get_posts ( $query ) { | |
// only interested in home page and the main query | |
if ( !$query->is_home() || !$query->is_main_query() ) return; | |
// default args - most recent post | |
$args = 'posts_per_page=1&order=DESC&orderby=date&ignore_sticky_posts=true'; | |
// check for sticky posts | |
$sticky = get_option( 'sticky_posts' ); | |
// have sticky posts so use them | |
if ( $sticky != '' ) { | |
$args = 'p=' . $sticky[0]; | |
} | |
// clear the current query | |
$query->init(); | |
// parse in the new arguments | |
$query->parse_query( $args ); | |
} | |
add_action( 'pre_get_posts' , 'pfp_pre_get_posts' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @pommiegranit !
I tried this plugin on my site. Doesn't work. I guess because I am 4 years late!
I am using the twentysixeen theme. Is there anything I can do to make this work?
I have been looking for this functionality for a few months now.