How to apply a condition for homepage, discussion?
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
-
jspautsch ✭✭✭
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.
1 -
jspautsch ✭✭✭
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() )
0 -
jspautsch ✭✭✭
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.
0 -
jspautsch ✭✭✭
Easiest way to do that is probably to check permissions...
if ( $Session->CheckPermission('Garden.Settings.Manage') )
0
Answers
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?
Blank? They don't seem blank to me.
To check if the user is logged in, check for a valid session...
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" ?>
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.
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.
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.
Easiest way to do that is probably to check permissions...
if ( $Session->CheckPermission('Garden.Settings.Manage') )