Conditional to check whether we're inside a blog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michelle
    Senior Member
    • Jul 2005
    • 408
    • 3.7.x

    Conditional to check whether we're inside a blog

    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
    Senior Member
    • Dec 2001
    • 207
    • 3.0.0 Release Candidate 2

    #2
    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:


    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:



    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?
    Last edited by Slacker; Mon 3 Sep '07, 11:29am.
    slackercentral messageboard - Running vBulletin 3.7.0
    Check out my reformatted vBulletin blog here: http://www.slackercentral.com

    Comment

    • Slacker
      Senior Member
      • Dec 2001
      • 207
      • 3.0.0 Release Candidate 2

      #3
      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.
      slackercentral messageboard - Running vBulletin 3.7.0
      Check out my reformatted vBulletin blog here: http://www.slackercentral.com

      Comment

      • Michelle
        Senior Member
        • Jul 2005
        • 408
        • 3.7.x

        #4
        Its $bloginfo[userid]

        Comment

        • Slacker
          Senior Member
          • Dec 2001
          • 207
          • 3.0.0 Release Candidate 2

          #5
          Originally posted by Loukrhtia
          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!
          slackercentral messageboard - Running vBulletin 3.7.0
          Check out my reformatted vBulletin blog here: http://www.slackercentral.com

          Comment

          • Slacker
            Senior Member
            • Dec 2001
            • 207
            • 3.0.0 Release Candidate 2

            #6
            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.
            slackercentral messageboard - Running vBulletin 3.7.0
            Check out my reformatted vBulletin blog here: http://www.slackercentral.com

            Comment

            • Michelle
              Senior Member
              • Jul 2005
              • 408
              • 3.7.x

              #7
              Sorry, I didn't have much time before.
              The conditional I used (and seems to work fine) was:
              HTML Code:
              <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

              Comment

              • Freddie Bingham
                Former vBulletin Developer
                • May 2000
                • 14057
                • 1.1.x

                #8
                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.

                Comment

                • Shon
                  Member
                  • Nov 2002
                  • 98
                  • 3.8.x

                  #9
                  (defined('BLOG_SCRIPT'))

                  What would be the template conditional for if (defined('BLOG_SCRIPT')) to use in the header template?

                  I've tried both:
                  Code:
                  <if condition="defined('BLOG_SCRIPT')">
                  and
                  Code:
                  <if condition="(defined('BLOG_SCRIPT'))">
                  But neither seem to work.

                  I'm currently using this:
                  Code:
                  <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
                  It is fatal to enter any war without the will to win it.
                  --General Douglas MacArthur

                  Comment

                  • Freddie Bingham
                    Former vBulletin Developer
                    • May 2000
                    • 14057
                    • 1.1.x

                    #10
                    <if condition="BLOG_SCRIPT == true">

                    that should work

                    Comment

                    • Shon
                      Member
                      • Nov 2002
                      • 98
                      • 3.8.x

                      #11
                      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
                      Code:
                      <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.
                      Last edited by Shon; Wed 12 Sep '07, 10:55pm.
                      It is fatal to enter any war without the will to win it.
                      --General Douglas MacArthur

                      Comment

                      • Shon
                        Member
                        • Nov 2002
                        • 98
                        • 3.8.x

                        #12
                        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!
                        It is fatal to enter any war without the will to win it.
                        --General Douglas MacArthur

                        Comment

                        • smnet
                          Senior Member
                          • Oct 2005
                          • 319
                          • 3.8.x

                          #13
                          This is a pain isnt it..... grrrr

                          Comment

                          • Wayne Luke
                            vBulletin Technical Support Lead
                            • Aug 2000
                            • 74135

                            #14
                            <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.
                            Translations provided by Google.

                            Wayne Luke
                            The Rabid Badger - a vBulletin Cloud demonstration site.
                            vBulletin 5 API

                            Comment

                            • Michelle
                              Senior Member
                              • Jul 2005
                              • 408
                              • 3.7.x

                              #15
                              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...

                              Comment

                              Related Topics

                              Collapse

                              Working...