Get weblog_id as a global
Posted: 30 November 2006 03:00 AM   [ Ignore ]  
Summer Student
Total Posts:  8
Joined  11-22-2006

Hi all,

Sorry if this has been answered before, but I am not able to find it neither here or the documentation.

Is there a way to get the “weblog_id” variable outside an “exp:weblog:entries” call? Like a global?

I have multiple weblogs and I use the same templates for all of them. I need to know the id of the weblog I am, so I can use conditionals to modify the presentation.

For example, to highlight the weblog I am in the menu:

<ul>
<
li>weblog 1</li>
<
li {if weblog_id == '2'}class="selected"{/if}>weblog 2</li>
<
li>weblog 3</li>
</
ul>

Thanks for your help.

Profile
 
 
Posted: 30 November 2006 08:46 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  16399
Joined  06-03-2002

Is there nothing unique about the URL that allows you to know which weblog you are “in”?  Generally you would handle something like this with URL segments, or many will even use separate template groups for each weblog, so they have a firm and definite structure to the site.

 Signature 
Profile
MSG
 
 
Posted: 30 November 2006 10:27 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  8
Joined  11-22-2006

Thanks for your reply Derek.

If we use different template groups for each weblog, the URL would contain the template group name in it. In this case, which global would tell me the template group am I “in”? Or is there another method to achieve the same goal?

Profile
 
 
Posted: 30 November 2006 10:31 AM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23754
Joined  05-20-2002

There’s no need to use different templates if you don’t want to.  I generally pass the weblog shortname in the second segment of the url- pull that out to specify my weblog parameter- and you could use it for active state as well.

If you ARE using different templates for each- you could just use a global at the top and hard code it, which is what I’d do.

Make sense?

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 30 November 2006 10:32 AM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  16399
Joined  06-03-2002

You could then use {segment_1}.  Or if you are clever and name your template groups identically to your weblog short name, all manner of nifty things can be done.  I know this is the approach that Lisa uses.  There’s not really a right or wrong way to do things—though some may be simpler or afford greater possibilities.

 Signature 
Profile
MSG
 
 
Posted: 30 November 2006 03:34 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  8
Joined  11-22-2006

Robin,

If you ARE using different templates for each- you could just use a global at the top and hard code it, which is what I’d do.

That sounds interesting. You mean hard code it with PHP code? I’ve been using EE for a week and I am still understanding how it works. Could you please give me an example?

Derek, thanks! That did the trick. Indeed, with the “segment” global variable (why isn’t it in the quick reference?) we can do all the presentation tricks we need.

I will also try Robin’s suggestion, it is always nice to have more than one option to do things.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66505 Total Logged-in Users: 70
Total Topics: 84942 Total Anonymous Users: 48
Total Replies: 455761 Total Guests: 286
Total Posts: 540703    
Members ( View Memberlist )
Newest Members:  michael.miao5TEadesHaigiedigital1ChuckRBuckskinhagsspmckeeTandemodusgeorgefromohio