[Solved] CGBlog : current article id in articles'list ?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
Trangsene
Forum Members
Forum Members
Posts: 19
Joined: Thu Aug 28, 2008 9:43 am

[Solved] CGBlog : current article id in articles'list ?

Post by Trangsene »

Hello,

I have a site template displaying an article of the CGBlog and the list of the articles in a sidebar :

Code: Select all

     <div id="sidebar">      
        {CGBlog summarytemplate='list'}        
     </div>

    <div id="main">  
    {content} 
    </div>
In my list I have the following code just listing the articles :

Code: Select all

 {foreach from=$items item=entry}
<ul>
       <li><a href="{$entry->detail_url}">{$entry->title}</a></li>
 </ul>
{/foreach} 
How can I get the current article id in the template list in order to highlight his link with something like :

Code: Select all

{if $current_id eq $entry->id}
?? ???

Thanks in advance for your help
Last edited by Trangsene on Wed Nov 23, 2011 10:31 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CGBlog : current article id in articles'list ?

Post by calguy1000 »

1. Your {content} block will have to be called before the 'list view' so that you can assign the variable and have it available for the list view.

Code: Select all

{content assign='mycontent'}
<div id="sidebar">      
 {CGBlog summarytemplate='list'}        
</div>
<div id="main">  
  {$mycontent} 
</div>
2. In your detail template you will need to assign a variable with the article id.

Code: Select all

{assign var='myarticleid' value=$entry->id}
3. In your summary template. You can use logic like:

Code: Select all

{if $myarticleid == $entry->id}...{/if}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Trangsene
Forum Members
Forum Members
Posts: 19
Joined: Thu Aug 28, 2008 9:43 am

Re: CGBlog : current article id in articles'list ?

Post by Trangsene »

Thanks a lot for your help, it works fine.

But...

Now I lose my previous/next article navigation from my detail template, it disappears and I really don't understand why !

Code: Select all

{assign var='entryID' value=$entry->id}
{if isset($entryID) && $items|@count > 1}

    {foreach from=$items item=entry2 name=idx}
        {if $entryID eq $entry2->id}
            {assign var=curpos value=$smarty.foreach.idx.index}
        {/if}
    {/foreach}
    {assign var=next value=$curpos-1}
    {assign var=prev value=$curpos+1}
    
     <ul class="pagination">
        {if $items[$next]}
            <li class="next"><a href="{$items[$next]->detail_url}" title="{$items[$next]->title|strip_tags:false}">Next article ></a></li>
        {/if}
        {if $items[$prev]}
            <li class="prev"><a href="{$items[$prev]->detail_url}" title="{$items[$prev]->title|strip_tags:false}">< Previous article</a></li>
        {/if}
    </ul>
{/if}
Do you have an idea where the problem is coming from ? :(
User avatar
Trangsene
Forum Members
Forum Members
Posts: 19
Joined: Thu Aug 28, 2008 9:43 am

Re: CGBlog : current article id in articles'list ?

Post by Trangsene »

I've put my previous/next article navigation in a summary template and now the problem is solved.

Again thanks a lot calguy1000 for your quick and very clear answer !
Post Reply

Return to “Modules/Add-Ons”