Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Using sp_is_forumpage() to detect forum pages in Wordpress template files.
Avatar
JB
Member
Free Members
sp_UserOfflineSmall Offline
Feb 13, 2013 - 12:17 pm

The function from the API "sp_is_forumpage" does not seem to be available in regular Wordpress template files. 

The Codex indicates that there is an option in the admin that will need able be enabled in order to use these in the "Optimization Panel" area. However, that area does not seem to exist in this version of SimplePress.

Any ideas how I can get this function working within standard Wordpress template files? I need to change the header/footer depending on whether the visitor is on a forum page or not.

Thanks. 

 

 

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 13, 2013 - 2:18 pm

I have no problem using it in any of a WP theme's files - including the header file. So - where are you trying to use it exactly. And can you give me a link to this Codex article you are referring to please as that has be somewhat confused as well!

andy-signature.png
YELLOW
SWORDFISH
Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Feb 13, 2013 - 7:34 pm

nor do I have any issue using it in wp themes...

if in a strange place, I guess you could try adding:

    sp_forum_api_support();

before you make the check... shouldnt need it and if having problems finding the other function, may not find this one either...

like Andy was asking, sounds like you are referring to the wiki (v4) instead of the codex (v5)...

Avatar
JB
Member
Free Members
sp_UserOfflineSmall Offline
Feb 14, 2013 - 9:57 am

Yes, I did see that on the Wiki and thought it might be outdated, but wasn't sure. 

Tried to use if(!sp_forum_api_support()) but it just made the forum not work at all, no errors but nothing displayed outside the header/footer of the Wordpress theme. :)

I am using it within a custom function in functions.php. To make a long story short, the site itself uses functions from an old version of jQuery (I am working with the frontend developer to update those calls which are incompatible with newer versions), therefore necessitating a load of a specific jQuery version, like so.

if (!function_exists('my_scripts_method')) {
 function my_scripts_method() {
   if (!is_admin()) {
     wp_deregister_script( 'jquery' );
     wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
     wp_enqueue_script( 'jquery' );
   }
 }
}
add_action('init', 'my_scripts_method');

The is_admin part works to fix the backend (this jQuery version is also incompatible with the backend portion of SimplePress) but I want to fix the frontend as well since certain portions of the forum are broken with this outdated version of jQuery. 

I tried changing the if statement to

if (!is_admin() && !sp_is_forumpage()) {
But like I said it says the function doesn't exist at this point in Wordpress. I have perhaps a problem that may be related to this, which is when an Admin is logged into the Forum the "Add Topic" or "Reply" buttons are broken. I'm attempting to troubleshoot this but it appears the js is obfuscated somewhat which is making it hard to determine the exact error. I can see the hidden divs there (in fact, make them visible manually and submit a post), just the button does not work - no errors. Moderators and regular users can use this button fine. 

Thanks for your help.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 14, 2013 - 11:09 am

Most odd. Always available on all of my tests.
It would be worth while trying for this a little later in the process. Instead of using 'init' why not try it with 'wp_enqueue_scripts' action instead...?

andy-signature.png
YELLOW
SWORDFISH
Avatar
JB
Member
Free Members
sp_UserOfflineSmall Offline
Feb 14, 2013 - 12:22 pm

Switching

add_action('init', 'my_scripts_method');

to

add_action('wp_enqueue_scripts', 'my_scripts_method');

Did fix this issue. So apparently sp_is_forumpage is available at the wp_enqueue_scripts hook, but not the init hook!

Thanks for the assistance. I still have the other issue, but I will open a new thread for that since it appears to be a separate issue. 

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 14, 2013 - 1:15 pm

It is curious as I am sure I can use it at init. But - you shouldn't really be enqueuing javascript at init anyway so this is better.

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17361
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625