Forums

using php in template to determine what page i'm on (2 posts)

  1. bxfl
    Member
    Posted 3 years ago #

    So I'm trying to develop a sidebar for a page template, and I'd like to inject different content depending on which page I am on.
    For that reason, I'd like to know what command and what identifier I use to write the if/then statement for WordPress.

    I.e:

    <?php
    if ((thispageis == 'pageidentifier') {
    ?> iinclude_page(4); <?
    }else{
    if ((thispageis2 == 'pageidentifier2') {
    ?> iinclude_page(5);
    }
    ?>

    I am using the Improved Include page plugin that outlines the function of iinclude_page();

    Does anyone know how I'd go about this? Is there a page identifier already defined by WordPress that I can just determine those values and put them in after I've created said pages?

    Thanks

  2. stvwlf
    Member
    Posted 3 years ago #

    hi

    I'm not familiar with that plugin. Here is the usual way it is done in WP. Where I've indicated page-slug, substitute the name of the page's slug.

    <?php
    if ((is_page('about')) {
      iinclude_page(4);
    } elseif ((is_page'events')) {
      iinclude_page(5);
    }
    ?>

    for your blog page, instead of is_page('blog') use is_home()
    and for the top page (home page) use is_front_page(). ( That assumes you have set a static front page and a posts page in the Settings / Reading settings in the admin area. )

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags