Skip to content

Instantly share code, notes, and snippets.

@k4zuki02h4t4
Created September 10, 2014 02:02
Show Gist options
  • Save k4zuki02h4t4/dcfb5f045fa8264e5f7d to your computer and use it in GitHub Desktop.
Save k4zuki02h4t4/dcfb5f045fa8264e5f7d to your computer and use it in GitHub Desktop.
[ WordPress ] フロントページの設定で、フロントページと投稿ページを設定していて is_home() && ! is_front_page() な情報を取得した時に役にたつかも?なコード
<?php
/**
* Alternative get_post function.
* @return object|false
*/
public static function my_get_post() {
$result = get_post();
$page_for_posts = get_option( 'page_for_posts' );
if ( is_home() && $page_for_posts && ( ! is_object( $result ) || ( $page_for_posts != $result->ID ) ) ) {
$result = get_post( $page_for_posts );
}
if ( ! is_object( $result ) ) {
$result = false;
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment