Skip to content

Instantly share code, notes, and snippets.

@pommiegranit
Created May 12, 2014 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pommiegranit/f1df7afae016a8b6e191 to your computer and use it in GitHub Desktop.
Save pommiegranit/f1df7afae016a8b6e191 to your computer and use it in GitHub Desktop.
<?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' );
?>
@CosgoodCreeps
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment