Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted February 4, 20169 yr 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.
February 5, 20169 yr Author anyone? Need this for a custom ad script, so that if user is in Car forum , Car ads will be displayed. Thanks
February 5, 20169 yr 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.
February 6, 20169 yr Author Hi MDPP, On top of the Php page what files do I have to include? I think i have to include IPB init.php?
February 6, 20169 yr 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
February 9, 20169 yr On 2/6/2016 at 2:16 PM, 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(); }
Archived
This topic is now archived and is closed to further replies.