GrooveOnBeat Posted July 12, 2015 Posted July 12, 2015 1. Let's say I want to display content only on the forum index, what condition do I use? I tried (below), but content is also displayed in the topic and post pages.{{if $location["module"] == "forums"}}I also tried (below), but content displayed on every page.{{if \IPS\forums\Forum::roots()}}2. If I want to show content on a specific page (e.g., profile, gallery, forum ID, page ID, etc), what conditional format do I use?
newbie LAC Posted July 16, 2015 Posted July 16, 2015 Hello,1. Let's say I want to display content only on the forum index, what condition do I use? I tried (below), but content is also displayed in the topic and post pages.var $location from template globalTemplate return array$location = array( 'app' => '%current_app%', 'module' => '%current_module%', 'controller' => '%current_controller%', );Example for index page $location = array( 'app' => 'forums', 'module' => 'forums', 'controller' => 'index' , );Your condition must be {{if $location['app'] == 'forums' and $location['module'] == 'forums' and $location['controller'] == 'index'}}2. If I want to show content on a specific page (e.g., profile, gallery, forum ID, page ID, etc), what conditional format do I use?Use also \IPS\Request::i() to get other data
GrooveOnBeat Posted July 17, 2015 Author Posted July 17, 2015 Hello, var $location from template globalTemplate return array $location = array( 'app' => '%current_app%', 'module' => '%current_module%', 'controller' => '%current_controller%', ); Example for index page $location = array( 'app' => 'forums', 'module' => 'forums', 'controller' => 'index' , ); Your condition must be {{if $location['app'] == 'forums' and $location['module'] == 'forums' and $location['controller'] == 'index'}} Use also \IPS\Request::i() to get other data Thank you for the break down! It worked perfectly. I'll play around with "\IPS\Request::i()". So I use this to get a specific forum or Page ID, right?
newbie LAC Posted July 17, 2015 Posted July 17, 2015 Thank you for the break down! It worked perfectly. I'll play around with "\IPS\Request::i()". So I use this to get a specific forum or Page ID, right? First you have to determine where you are. Topic view \IPS\Request::i()->id contain topic ID Forum view \IPS\Request::i()->id contain forum ID
GrooveOnBeat Posted August 2, 2015 Author Posted August 2, 2015 First you have to determine where you are. Topic view \IPS\Request::i()->id contain topic ID Forum view \IPS\Request::i()->id contain forum ID Thanks again! I've gotten around displaying codes in different areas of the forums by using the true URL paths, which show the app, module, and controller. I'm stuck on Pages. I tried this and some variations of it but that didn't work. {{if $location['app'] == 'cms' and $location['module'] == 'pages' and $location['controller'] == 'records' and \IPS\Request::i()->id(4)}} I'm not sure what the module or controller are, and I'm not sure if I did the request by ID correctly. I am learning though thanks to you.
newbie LAC Posted August 2, 2015 Posted August 2, 2015 \IPS\Request::i()->id(4) \IPS\Request::i()->id == 4
GrooveOnBeat Posted August 2, 2015 Author Posted August 2, 2015 \IPS\Request::i()->id(4) \IPS\Request::i()->id == 4 I have tried that too but it didn't work (see why below). At least I know the correct syntax thanks to you. I think the problem is that the module and/or the controller is not correct. I have database templates, and the template I use is "records". I want to display something custom on the record pages, but I think the controller "records" is wrong. App = cms, module = pages, controller = ?
GrooveOnBeat Posted August 2, 2015 Author Posted August 2, 2015 Have you edit template globalTemplate? Yes. I tried in both globalTemplate and records template and the code below didn't work {{if $location['app'] == 'cms' and $location['module'] == 'pages' and $location['controller'] == 'records' and \IPS\Request::i()->id == 4}} I changed controller to "record" and "pages". They didn't work either.
newbie LAC Posted August 2, 2015 Posted August 2, 2015 Add into globalTemplate (or use var_dump/print_r) {{foreach $location as $k => $loc}} {$k} = {$loc}<br> {{endforeach}}And see data
GrooveOnBeat Posted August 2, 2015 Author Posted August 2, 2015 Add into globalTemplate (or use var_dump/print_r) {{foreach $location as $k => $loc}} {$k} = {$loc}<br> {{endforeach}} And see data Wow, that did t! You are a genius! I've tried everything but the singular "page". Thank you, thank you! In case anyone is reading, it's: app = cmsmodule = pagescontroller = page {{if $location['app'] == 'cms' and $location['module'] == 'pages' and $location['controller'] == 'page' and \IPS\Request::i()->id == x}} x = page ID
-FP Posted September 9, 2015 Posted September 9, 2015 Very informative, I start to understand how to work with this...IPS should really put togheter a nice list of "real-world" examples of this for the less avid users, not just this. Honestly I wodun't ever get to the \IPS\Request::i()->id stuff on my own, and there are a lot of these like \Member or \Settings...
GrooveOnBeat Posted September 9, 2015 Author Posted September 9, 2015 Very true. I've expressed an interest of having such a listing, even by member contributions like a wiki or something similar. Just a little help in code can go a long way.
Ken Johnson Posted September 10, 2015 Posted September 10, 2015 Thanks a ton for this thread! It'll definitely help me in the future with various projects.
thompsone Posted February 19, 2016 Posted February 19, 2016 Hello, Along the same lines I need some assistance in removing ads from specific locations throughout the IPS Suite. I tried wrapping this around the ad hook but it's not working like intended. {{if ( \IPS\Request::i()->controller == 'forums' AND isset( \IPS\Request::i()->id ) AND ! in_array( \IPS\Request::i()->id, array( 35, 90, 102, 107, 108, 109, 142, 166, 214, 217, 218, 244, 266, 277, 289, 290, 291, 294, 296, 302, 303, 304, 308 ) ) ) AND ! in_array( \IPS\Request::i()->controller, array( 'login', 'register', 'lostpass' ) ) AND ! in_array( \IPS\Request::i()->app, array( 'chat', 'membermap') )}} {advertisement="ad_global_header"} {{endif}} SIMPLIFIED: remove the ad_global_header from forum_id 35, 90, ... AND in login, register, lostpass AND in app_chat, app_membermap The result is the ad only appears in forumDisplay. *bangs head on desk* Can anyone help me with a solution to make this display in all areas except the ones I'm trying to remove? Thank you.
thompsone Posted February 21, 2016 Posted February 21, 2016 With the help of Ryan Ashbrook and newbie LAC this solution for removing ads in locations you don't want them was possible. For myself I use this wrapped around the {advertisement="ad_tag_here"} hooks to keep my site compliant with Google Adsense. This eliminates the need to provide Google crawler access to otherwise private forums on your boards and in places Adsense complains about not being able to index like some apps and some features on the stock suite. This was used on IPS 4.1.8.1 but should be compatible with IPS 4.x. {{if ( \IPS\Request::i()->controller == 'forums' AND isset( \IPS\Request::i()->id ) AND ! in_array( \IPS\Request::i()->id, array( forum_id1, forum_id2, forum_id3, forum_id4 ) ) ) OR !( in_array( \IPS\Request::i()->controller, array( 'system_app', 'system_app', 'system_app', 'forums' ) ) OR in_array( \IPS\Request::i()->app, array( 'external_app', 'external_app') ) )}} {advertisement="ad_tag_here"} {{endif}} The above is the example to be modified to your configuration and needs. {{if ( \IPS\Request::i()->controller == 'forums' AND isset( \IPS\Request::i()->id ) AND ! in_array( \IPS\Request::i()->id, array( 35, 90, 102, 107, 108, 109, 142, 166, 214, 217, 218, 244, 266, 277, 289, 290, 291, 294, 296, 302, 303, 304, 308 ) ) ) OR !( in_array( \IPS\Request::i()->controller, array( 'login', 'register', 'lostpass', 'forums' ) ) OR in_array( \IPS\Request::i()->app, array( 'chat', 'membermap') ) )}} {advertisement="ad_global_header"} {{endif}} The above example was my board specific need but this shows you how to apply the example. I hope this can help someone else and keep them out of hot water with Adsense as they are very demanding and particular on which pages they will allow their ads shown. Good luck out there. Special shout to Ryan and LAC for the support, these guys are awesome!
Day_ Posted February 28, 2016 Posted February 28, 2016 On 21 February 2016 at 6:15 PM, thompsone said: With the help of Ryan Ashbrook and newbie LAC this solution for removing ads in locations you don't want them was possible. For myself I use this wrapped around the {advertisement="ad_tag_here"} hooks to keep my site compliant with Google Adsense. This eliminates the need to provide Google crawler access to otherwise private forums on your boards and in places Adsense complains about not being able to index like some apps and some features on the stock suite. This was used on IPS 4.1.8.1 but should be compatible with IPS 4.x. {{if ( \IPS\Request::i()->controller == 'forums' AND isset( \IPS\Request::i()->id ) AND ! in_array( \IPS\Request::i()->id, array( forum_id1, forum_id2, forum_id3, forum_id4 ) ) ) OR !( in_array( \IPS\Request::i()->controller, array( 'system_app', 'system_app', 'system_app', 'forums' ) ) OR in_array( \IPS\Request::i()->app, array( 'external_app', 'external_app') ) )}} {advertisement="ad_tag_here"} {{endif}} The above is the example to be modified to your configuration and needs. {{if ( \IPS\Request::i()->controller == 'forums' AND isset( \IPS\Request::i()->id ) AND ! in_array( \IPS\Request::i()->id, array( 35, 90, 102, 107, 108, 109, 142, 166, 214, 217, 218, 244, 266, 277, 289, 290, 291, 294, 296, 302, 303, 304, 308 ) ) ) OR !( in_array( \IPS\Request::i()->controller, array( 'login', 'register', 'lostpass', 'forums' ) ) OR in_array( \IPS\Request::i()->app, array( 'chat', 'membermap') ) )}} {advertisement="ad_global_header"} {{endif}} The above example was my board specific need but this shows you how to apply the example. I hope this can help someone else and keep them out of hot water with Adsense as they are very demanding and particular on which pages they will allow their ads shown. Good luck out there. Special shout to Ryan and LAC for the support, these guys are awesome! I can get this code to work if I add it into the template, however it won't work if I add it into the advertisement box itself, it shows all the code on the front end. Anyway around this? Just I use a plug to show the ads after 5 and 10th post using a plugin and don't include any ad keys in the templates for this
thompsone Posted February 28, 2016 Posted February 28, 2016 That edit is meant for the template only where the template calls for an ad with the hook {advertisement="tag"}. It would need modifications to go in the advertisement tag field.
newbie LAC Posted February 29, 2016 Posted February 29, 2016 9 hours ago, thompsone said: Sharing is caring.
thompsone Posted February 29, 2016 Posted February 29, 2016 newbie LAC is amazing! Here's his latest change to what Ryan Ashbrook started me off with. This latest change now strips ads in topics which are in forum_ids you don't want ads in, this keeps Adsense happy and us compliant. With this latest change all the ads are stripped from locations I don't want them (private and non indexable areas) yet shows them in all the areas that I do want (the public facing areas googlebot can get to without special permission just like a guest or member can). This resolves the Adsense crawler notifications that you're showing ads in areas the crawler can't get to. This is now finally resolved for 4.1.x {{$forumId = 0;}} {{if \IPS\Request::i()->app == 'forums' and \IPS\Request::i()->module == 'forums' and \IPS\Request::i()->controller == 'forums'}} {{$forumId = \IPS\Request::i()->id;}} {{endif}} {{if \IPS\Request::i()->app == 'forums' and \IPS\Request::i()->module == 'forums' and \IPS\Request::i()->controller == 'topic'}} {{try { $topic = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id ); $forumId = $topic->forum_id; } catch( \Exception $e ) {};}} {{endif}} {{if ( \IPS\Request::i()->module == 'forums' AND ! in_array( $forumId, array( forum_id_1, forum_id_2, forum_id_3, forum_id_4, and_so_on ) ) ) OR !( in_array( \IPS\Request::i()->controller, array( 'login', 'register', 'lostpass', 'forums', 'topic', 'modcp' ) ) OR in_array( \IPS\Request::i()->app, array( 'chat', 'membermap') ) )}} {advertisement="ad_tag_here"} {{endif}} The above is a template modification that wraps around the advertisement=tags. Change "forum_id_x" to your forum_ids you don't want ads separated by a comma. Then modify any core apps like the register page or lostpass page to remove. Finally modify any external app like chat or membermaps that you want removed. Save your changes to the template and test. Thanks and hope this helps someone else.
waccoe.com Posted March 3, 2016 Posted March 3, 2016 This looks promising. Will have to play around and try to make work. Of course what the IPS suite needs is the ability to target specific ads by forum. Wonder if that will ever be delivered? Anyone fancy building something for the marketplace? Would pay a few hundred dollars for much more advanced and manageable ad functionality. Thought I was getting it with the Commerce module
thompsone Posted March 4, 2016 Posted March 4, 2016 MattLx - I imagine your request is a good one though it may have limited patronage. The snippet above will work perfectly if it's set up correctly. IPS may elect to support Adsense more completely but for now they've left that up to us. I do agree it would be a nice addition to commerce since that's it's purpose. It really should do a better job at serving ad-space whether you use Adsense or some other means of monitizing your boards. Give the above a try, it'll take just a few minutes to gather the forums you don't want ads in and just a few moments more to throw it into the templates. Remember you can use the built search feature and search something like advertisement= and it'll show you all the templates that have the ad hook in them. One other thing, if you like the divider below the pinned topics buy Newbie LAC's divider hook and you can then edit the language template for that and throw an ad in the middle of it. Wrap it with the above code and viola you got ads in your divider and they'll only be displayed in the places you want them. Good luck, let us know how it turns out for you.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.