Jump to content

PHP how to get forum id?


SenGuy

Recommended Posts

Posted

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.

Posted

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. :)

Posted
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();
}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...