View Full Version : Conditional to check whether we're inside a blog
Michelle
Sat 1st Sep '07, 12:42pm
Which conditional can I add to the template BLOG or in headinclude to determine whether we're inside a specific blog or in other, general places?
"Inside a blog" includes: in the blog's home page, while viewing a blog entry or when editing/posting a comment/blog entry.
I have been searching the php files for hours now with no luck... :(
Thanks in advance!
Slacker
Mon 3rd Sep '07, 4:18pm
I came here to ask this same question. On my install, I'm using the blog system for my new main blog for the site, redirecting the main url to it:
http://www.slackercentral.com redirects to:
http://boards.slackercentral.com/blog.php?u=3968
To customize the look of the main blog I went through and tacked in a bunch of conditionals checking the userid number like so:
<if condition="$userinfo[userid]==3968">(content for the main blog)<else />(default layout for any other blog)</if>
As you can see by clicking the link above, this works fine for the main page. I removed the default header and navbar, and added a few blocks in the sidebar specific to the front page of the site (what is this, the messageboard, slackercentral.com). However, if you click on a particular blog entry, it gets weird:
http://boards.slackercentral.com/blog.php?b=10
For some reason, the conditional that changes the header and kills the navbar on the main page isn't working here. However, the blocks I added in the sidebar using the same conditional are still working fine. EDIT: I fixed this one - see below.
I double-checked to ensure that the page was getting the $header and $navbar from the "BLOG" template by commenting them out, and indeed they are.
Really long question short - is there a conditional that works on every page to check if you're looking at a particular blog?
Slacker
Mon 3rd Sep '07, 4:28pm
I just found at least part of the answer, it looks like there are different variables that work in each template:
Main blog page (?u=XXXX): $userinfo[userid]
Individual entry page (?b=XX): $blog[userid]
Comment editing page (?do=comment&b=XX): I can't find this one yet.
Both of the above return my userid (3968). I was able to fix what I was talking about above by making the conditional that replaces the navbar and header an OR with the first two conditionals.
<body $onload>
<!-- modified by slacker for custom main blog -->
<if condition="$userinfo[userid]==3968 OR $blog[userid]==3968">
<div style="width:100%" align="center">
<div style="width:900px" align="left">
<a href="http://boards.slackercentral.com/blog.php?u=3968"><img border="0" src="images/temptitle.jpg" style="margin-bottom:5px"></a>
<else />
$header
$navbar
</if>
<!-- END modified by slacker for custom main blog -->
I think the only thing left that needs correcting is the comment page.
Michelle
Mon 3rd Sep '07, 5:53pm
Its $bloginfo[userid]
Slacker
Mon 3rd Sep '07, 6:18pm
Its $bloginfo[userid]
Nice work! Yep that's it, but that one doesn't work on the main blog page, just on the entry page and the comment editing page. That helps me out though, now I can just do an OR conditional with $userinfo[userid] and $bloginfo[userid]. Thanks!
Slacker
Mon 3rd Sep '07, 6:53pm
FYI for anyone else doing what I'm doing, I also had to set up a conditional to check for the random featured blog entry thing, otherwise it changed the header to my custom version on the normal blog.php page whenever one of the posts from the main blog popped up. Here's what it looks like now:
<body $onload>
<!-- modified by slacker for custom main blog -->
<if condition="$show['randomfeatured']">
$header
$navbar
<else />
<if condition="$userinfo[userid]==3968 OR $bloginfo[userid]==3968">
<div style="width:100%" align="center">
<div style="width:900px" align="left">
<a href="http://boards.slackercentral.com/blog.php?u=3968"><img border="0" src="images/temptitle.jpg" style="margin-bottom:5px"></a>
<else />
$header
$navbar
</if>
</if>
<!-- END modified by slacker for custom main blog -->
I'm sure there's a way to add that $show['randomfeatured'] conditional to the one where it checks for the userinfo, but I'm too tired to figure it out at the moment. :D
Michelle
Tue 4th Sep '07, 6:07am
Sorry, I didn't have much time before.
The conditional I used (and seems to work fine) was:
<if condition="($_REQUEST['do'] == 'blog' OR $userinfo['userid'] OR THIS_SCRIPT=='blog_post')">$bloginfo[userid] is not of much help, as its set in the homepage as well...
However if you want to check whether you are inside a specific blog, you would have to check $userinfo[userid] and $bloginfo[userid], inside the above conditional, as in some pages its the $userinfo one and in some others the $bloginfo one.
Btw, if you also remove the footer from the blogs (as I did) you will have to copy some <script> tags from the footer template and paste them in the BLOG template, otherwise the ajax and js functions such as "rate this entry" wont work (this one had me stumbled for a while).
Hope this helps
Freddie Bingham
Tue 4th Sep '07, 9:19pm
You can use if (defined('BLOG_SCRIPT')) to tell if you are on a blog page. For specific pages then you have to use THIS_SCRIPT. $userinfo is defined for any page within a user's blog. $bloginfo is defined if you are inside an entry. You should check BLOG_SCRIPT as well since you can have $userinfo defined in other places in vBulletin.
Shon
Thu 6th Sep '07, 10:26pm
What would be the template conditional for if (defined('BLOG_SCRIPT')) to use in the header template?
I've tried both:
<if condition="defined('BLOG_SCRIPT')">and
<if condition="(defined('BLOG_SCRIPT'))">But neither seem to work.
I'm currently using this:
<if condition="THIS_SCRIPT == "blog" OR THIS_SCRIPT == "blog_attachment" OR THIS_SCRIPT == "blog_callback" OR THIS_SCRIPT == "blog_newattachment" OR THIS_SCRIPT == "blog_post" OR THIS_SCRIPT == "blog_report" OR THIS_SCRIPT == "blog_search" OR THIS_SCRIPT == "blog_subscription" OR THIS_SCRIPT == "blog_usercp"">I would rather use something... well shorter, if I can.
Thanks :)
Freddie Bingham
Fri 7th Sep '07, 1:06pm
<if condition="BLOG_SCRIPT == true">
that should work
Shon
Fri 7th Sep '07, 7:39pm
That works, but it's also set to true on the forums...
I have a conditional setup for each part of the site and for the forums, they're listed at the end of the last <else />. When I was viewing the forums page, it showed what I had showing for the blogs too.
Is that supposed to only be true when you're viewing one of the blog pages?
Edit: Something like this
<if condition="THIS_SCRIPT == "adv_index"">
This is a CMPS page
<else />
<if condition="PP_SCRIPT == "vBGallery"">
This is a vBGallery page
<else />
<if condition="BLOG_SCRIPT == true">
This is a Blog page
<else />
This is another page, part of the forum
</if>
</if>
</if>If I was using that code in the header template, while viewing something other than all of those (This is another page, part of the forum) it would still display This is a Blog page.
Shon
Thu 13th Sep '07, 5:46am
I'm in no hurry or anything because what I'm currently using works. But I'm still wondering if I can use something shorter for the same result. I don't like so many ORs! :p
rob30UK
Tue 18th Sep '07, 1:21pm
This is a pain isnt it..... grrrr
Wayne Luke
Tue 18th Sep '07, 2:32pm
<if condition="VBBLOG_SCRIPT == true">
That should work. It is not active in the header or navbar templates according to the code though. It should also not be active on regular forum pages since it is only defined in blog_init.php.
Michelle
Fri 21st Sep '07, 10:39am
Has anything changed in v1.0.1 that makes this easier?
@Wayne: I think most members (and I) are more interested in a condition that checks whether we're inside a user's blog, not the blog system in general...
rob30UK
Fri 21st Sep '07, 6:08pm
I could really use something thats active in the header so I can set a navigation tab to active (or not)... any chance of support for this in a future build?
Powered by vBulletin™ Version 4.0.0 Beta 4 Copyright © 2009 vBulletin Solutions, Inc. All rights