SenGuy Posted February 4, 2016 Posted February 4, 2016 Hi, In Php, what do you need to include need to know the current forum value that the member is in. If my forum is setup like this Main Forum > Cars > Text text text? I want to get Cars forum id. Looking for a Php example code, with the includes that needed to added to the Php script. Thank you.
SenGuy Posted February 5, 2016 Author Posted February 5, 2016 anyone? Need this for a custom ad script, so that if user is in Car forum , Car ads will be displayed. Thanks
MDPP Posted February 5, 2016 Posted February 5, 2016 This may help. There may be a quicker way to accomplish this, but this way does work. If the current page is a topic: $topic_id = \IPS\Request::i()->id; //This gets the current page's topic ID $topic = \IPS\forums\Topic::loadAndCheckPerms($topic_id); $forum_id = $topic->forum_id; //Viola - here's your forum id If the current page is a forum: $forum_id = \IPS\Request::i()->id; You can put the two together to accomplish the same thing, if you're looking a "universal" code that will work on both a forum page and a topic page: if (\IPS\Request::i()->controller == "forums") { $forum_id = \IPS\Request::i()->id; } if (\IPS\Request::i()->controller == "topic") { $topic_id = \IPS\Request::i()->id; $topic = \IPS\forums\Topic::loadAndCheckPerms($topic_id); $forum_id = $topic->forum_id; } Of course, that is a dirty example, but it's just to demonstrate what you can do with it.
SenGuy Posted February 6, 2016 Author Posted February 6, 2016 Hi MDPP, On top of the Php page what files do I have to include? I think i have to include IPB init.php?
Kevin 7 Posted February 6, 2016 Posted February 6, 2016 Hey @SenGuy, This is how I get my forum ID's. Simple, sweet, swift...https://community.invisionpower.com/topic/426196-php-how-to-get-forum-id/ Regards
MDPP Posted February 9, 2016 Posted February 9, 2016 On February 6, 2016 at 9:16 AM, SenGuy said: Hi MDPP, On top of the Php page what files do I have to include? I think i have to include IPB init.php? It depends on how you're doing this. If you're using this on a template or inside of the IPS suite, then you shouldn't have to include init.php, it should just work. You can always do this at the beginning of the code, however, and it'll include init.php if it's needed. Make sure you adjust "/forums/init.php" to whatever your url is. For example, "/forums/init.php" works for "website.com/forums/init.php". <?php if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) ) { require_once( $_SERVER["DOCUMENT_ROOT"].'/forums/init.php' ); \IPS\Session\Front::i(); }
Recommended Posts
Archived
This topic is now archived and is closed to further replies.