Skip to content

Instantly share code, notes, and snippets.

@jjeaton
Forked from wesbos/is_blog.php
Last active December 18, 2015 15:59
Show Gist options
  • Select an option

  • Save jjeaton/5808697 to your computer and use it in GitHub Desktop.

Select an option

Save jjeaton/5808697 to your computer and use it in GitHub Desktop.

Revisions

  1. jjeaton revised this gist Jun 18, 2013. 1 changed file with 22 additions and 7 deletions.
    29 changes: 22 additions & 7 deletions is_blog.php
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,25 @@
    function is_blog () {
    global $post;
    $posttype = get_post_type($post );
    return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
    }
    /**
    * WordPress' missing is_blog() function. Determines if the currently viewed page is
    * one of the blog pages, including the blog home page, archive, category/tag, author, or single
    * post pages.
    *
    * Doesn't include is_search(), if you only use search for the blog, then add that in or test separately
    *
    * @props grantnorwood
    * @return bool
    */
    function is_blog() {

    global $post;

    Usage:
    //Post type must be 'post'.
    $post_type = get_post_type( $post );

    <?php if (is_blog()) { echo 'You are on a blog page'; } ?>
    //Check all blog-related conditional tags, as well as the current post type,
    //to determine if we're viewing a blog page.
    return (
    ( is_home() || is_archive() || is_single() )
    && ($post_type == 'post')
    );

    }
  2. @wesbos wesbos revised this gist Sep 6, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion is_blog.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    function is_blog () {
    return ( (is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag()) ) ? true : false ;
    global $post;
    $posttype = get_post_type($post );
    return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
    }


  3. @wesbos wesbos revised this gist Sep 2, 2011. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions is_blog.php
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,5 @@
    function is_blog () {
    if ( (is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag()) ) {
    return true;
    }
    else {
    return false;
    }
    return ( (is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag()) ) ? true : false ;
    }


  4. @wesbos wesbos revised this gist Sep 2, 2011. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion is_blog.php
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,9 @@ function is_blog () {
    else {
    return false;
    }
    }
    }


    Usage:

    <?php if (is_blog()) { echo 'You are on a blog page'; } ?>
  5. @wesbos wesbos created this gist Sep 2, 2011.
    8 changes: 8 additions & 0 deletions is_blog.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    function is_blog () {
    if ( (is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag()) ) {
    return true;
    }
    else {
    return false;
    }
    }