View Full Version : How to get a widget to only display on home page? (ad related)
Mikhailtech
03-05-2012, 01:34 AM
I'm trying to get an ad/widget to only display on the home page of my site. The ad management system in VB won't let me do that and I can't figure out a way to get a widget to only display on the home page. I'm ok modifying a php file to custom include something in just the home page if that's necessary. Any thoughts?
Are you talking about widgets on the CMS, or ads/forum blocks on the forum?
Mikhailtech
03-09-2012, 02:16 AM
Widgets on the CMS. Really anything on just the front/home page of the CMS. If it requires modification of a php file to manually insert content that's ok, I just don't know which one.
Mikhailtech
03-11-2012, 03:19 PM
bump
Lynne
03-11-2012, 06:24 PM
Copy the template for the widget (shown in the Configure box) and then put a condition around the new widget template code to only show it on the first page. Make sure you edit the widget's template name (again, shown in the Configure box) to the new template name.
Mikhailtech
03-19-2012, 01:56 AM
What's the code for the condition? This is a "static HTML" type widget.
dano9258
03-19-2012, 02:18 AM
Lynne answered this on another forum numerous times already...I wish i could find it right now but I can't. Just keep doing a search on Google or here and you will find it.
Mikhailtech
04-17-2012, 04:10 PM
bump ... couldn't find the answer to this. Lynne can you give an example on how to put a condition around this widget? I am not a coder so this is pretty confusing to me. TIA
kkinsey
04-17-2012, 04:24 PM
Well, I'm a little confused - CMS widgets only show up on the content.php page anyway --- which is "home" on most sites.
That out of the way, a PHP widget to do this could probably look something like this:if ($_SERVER['REQUEST_URI']=="/" || $_SERVER['REQUEST_URI']=="/index.php") {
echo "<tags>my Html code here</tag>";
echo "more HTML\n";
} // end 'if'"/index.php" would be the actual page portion of the main site's URL, and it's placed there in case people come to it from a link other than "/". Be certain that if you use the double quote for your echo() statement, you only use single quotes for html tag properties, and HTML entities for any quotes in the text itself.
I hope I've not confused you in return ;)
Mikhailtech
04-17-2012, 04:34 PM
Ok I sort of found it in this thread: https://vborg.vbsupport.ru/showthread.php?t=254551&highlight=show+widget+home+page+only
So based on what was said here, I made a new template called: vbcms_widget_static_page_home
Here's the code for it:
<vb:if condition="$_GET[r] == "">
<div class="cms_widget">
<div class="block">
<div class="cms_widget_header">
<h3><img src="{vb:stylevar imgdir_siteicons}/html.png" alt="" /> {vb:raw widget_title}</h3>
</div>
<div class="cms_widget_content widget_content">
{vb:raw static_html}
</div>
</div>
</div>
</vb:if>
Then for my static HTML widget I put this as the template under the "configure" option like you said. However, when I go to save this template I get the following error:
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
And the when I reload my home page I get this at the top:
Parse error: syntax error, unexpected ')' in /home/xxxx/public_html/includes/class_core.php(4596) : eval()'d code on line 1
And the widget doesn't show up at all. So what am I doing wrong here?
Well, I'm a little confused - CMS widgets only show up on the content.php page anyway --- which is "home" on most sites.
Yes, but a lot of the CMS pages will be accessed though content.php, so I think the question is how do you know if you're on the "home" page.
I found this thread where Lynne menstion using nodeid: www.vbulletin.org/forum/showthread.php?t=240063 but if it's a static html widget then I think the only way to do it would be to provide you're own "wrapper" template (which is in the text box at the bottom if you press "Configure" for your widget). You could copy the existing vbcms_widget_static_page template to a new one such as vbcms_widget_static_page_home_only or whatever, then put a conditional around it. I'll try it out and if I can figure out the exact condition I'll post it here.
And the when I reload my home page I get this at the top:
ETA: oh, I see you beat me to it. In the condition you posted, is that 3 double quote characters? It should be double quote at the beginning and end, and 2 single quotes right after the ==, like:
<vb:if condition="$_GET[r] == ''">
Mikhailtech
04-17-2012, 04:38 PM
... but if it's a static html widget then I think the only way to do it would be to provide you're own "wrapper" template (which is in the text box at the bottom if you press "Configure" for your widget). You could copy the existing vbcms_widget_static_page template to a new one such as vbcms_widget_static_page_home_only or whatever, then put a conditional around it.
See the reply I just made, I just attempted this and it's not working for some reason.
--------------- Added 1334685953 at 1334685953 ---------------
Ok I figured out the error, it was here: <vb:if condition="$_GET[r] == "">
Should be: <vb:if condition=$_GET[r] == "">
So no errors now, but still not showing up on the main page. I'm wondering if I need to change the nodeid? Because my site (pcshoptalk.com/index.php and pcshoptalk.com/content.php) are the same pages.
In the top left it also says "Home > Home".
So do I need to specify some sort of nodeid?
--------------- Added 1334686481 at 1334686481 ---------------
ETA: oh, I see you beat me to it. In the condition you posted, is that 3 double quote characters? It should be double quote at the beginning and end, and 2 single quotes right after the ==, like:
<vb:if condition="$_GET[r] == ''">
Can't quite code it that way with single quotes or you get this error:
vBulletin Message
The following error occurred when attempting to evaluate this template:
An empty or invalid 'if' condition was found.
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
And it still does nothing. I'm thoroughly confused on how to make this work. I never thought it would be this complicated to add a piece of content only to the home page...
--------------- Added 1334688258 at 1334688258 ---------------
FINALLY got this...
Need to use this statement instead:
<vb:if condition="$vbulletin->nodeid == 1">........</vb:if>
Nodeid can't be index page apparently if your content management home page is "1-Index".
icona
06-09-2012, 08:44 AM
I use this script:
<vb:if condition="$_SERVER['REQUEST_URI'] == '/content/'">
and it's good for me...
you can see it on my forum.
ico
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.