Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to apply a condition for homepage, discussion?

rornvirornvi New
edited February 2012 in Vanilla 2.0 - 2.8

I want to do something in homepage and something else in discussion page. In wordpress I do the same using conditional tag "is_home()".

Example from WP codex:
if ( is_page() && $post->post_parent ) {
// This is a subpage
} else {
// This is not a subpage
}

Best Answers

  • jspautschjspautsch Themester ✭✭✭
    edited February 2012 Answer ✓

    So basically you want to tell if you're on the All Discussions page? (Or whatever homepage you have it set to)

    The only way I would know how to do this is something like if ($Sender->SelfUrl == 'discussions')
    That would tell you if you're on the discussions page, for example.

    You might be able to find out more in the Vanilla Wiki.

  • jspautschjspautsch Themester ✭✭✭
    Answer ✓

    Blank? They don't seem blank to me.

    To check if the user is logged in, check for a valid session...

    if ( Gdn::Session()->IsValid() )
  • jspautschjspautsch Themester ✭✭✭
    Answer ✓

    That won't work, that doesn't have $Sender. You can try $this, but you probably shouldn't be editing the default.master.php anyway, make a plugin instead.

  • jspautschjspautsch Themester ✭✭✭
    Answer ✓

    Easiest way to do that is probably to check permissions...

    if ( $Session->CheckPermission('Garden.Settings.Manage') )

Answers

  • jspautschjspautsch Themester ✭✭✭
    edited February 2012 Answer ✓

    So basically you want to tell if you're on the All Discussions page? (Or whatever homepage you have it set to)

    The only way I would know how to do this is something like if ($Sender->SelfUrl == 'discussions')
    That would tell you if you're on the discussions page, for example.

    You might be able to find out more in the Vanilla Wiki.

  • All pages of the wiki are blank. Where can i get other conditional tags like if user logged in, etc?

  • jspautschjspautsch Themester ✭✭✭
    Answer ✓

    Blank? They don't seem blank to me.

    To check if the user is logged in, check for a valid session...

    if ( Gdn::Session()->IsValid() )
  • Thanks for the session code, but dunno why if ($Sender->SelfUrl == 'discussions')doesn't work for me. I tried:
    <?php if ($Sender->SelfUrl == 'discussions') echo "This is Home" ?>

  • jspautschjspautsch Themester ✭✭✭

    Where did you put that code?

    Also it's missing a semicolon at the end of the echo.

  • I put in default.master.php before content, I tried with semicolon as well.

  • jspautschjspautsch Themester ✭✭✭
    Answer ✓

    That won't work, that doesn't have $Sender. You can try $this, but you probably shouldn't be editing the default.master.php anyway, make a plugin instead.

  • rornvirornvi New
    edited February 2012

    Thanks, $this thing worked. Currently I'm just want to get started any how and would create a plugin for all my mods during polishing the site. I started learning PHP/MYSQL few days ago only. I'll be using CI to learn MVC.

    At last, would also like to know the condition if the user logged in is admin.

  • jspautschjspautsch Themester ✭✭✭
    Answer ✓

    Easiest way to do that is probably to check permissions...

    if ( $Session->CheckPermission('Garden.Settings.Manage') )

Sign In or Register to comment.