Forums

If conditional for a directory or when on /blog (4 posts)

  1. mattmikulla
    Member
    Posted 2 years ago #

    I have a static front home page. My blog is located at mysite.com/blog/.

    Is there a conditional that says the following:

    If on /blog/
    Then show this
    Else
    Something else
    End if

    I basically have a different navigation I want to show when only on the blog.

  2. Darrell Schauss
    Member
    Posted 2 years ago #

    This will check for /blog/ anywhere in URL, but chances are you will only have /blog/ in URL when at the blog.

    / defines start and end of the pattern to match so the / in blog are escaped \/

    <?php
    if(preg_match("/\/blog\//",$_SERVER['REQUEST_URI'])){
       //if /blog/ is anywhere in the URL..
    }else{
       //if /blog/ is not in URL
    }
    ?>
  3. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Far better to use WP conditionals:

    <?php if( is_home() ) :?>
    [ show this]
    <?php else:?>
    [ something else]
    <?php endif;>
  4. mattmikulla
    Member
    Posted 2 years ago #

    Esmi, I don't think that will work since my home page is not my blog but static content for the front of the site.

Topic Closed

This topic has been closed to new replies.

About this Topic