Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-04-24 00:30:05

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Change class inside article_custom loop

Hi

I couldn’t make my head around. I feeling so dump right now please help

<txp:article_custom section="<txp:section/>" custom1="index" limit="999">
<h1><txp:title/></h1>
<txp:article_custom section="test" cateogory="<txp:category1/>" wraptag="ul" class="collapse">
<txp:if_custom_field name="custom1" value="index"><txp:else/>
<li><txp:permlink><txp:title/></txp:permlink></li>
</txp:if_custom_field>
</txp:article_custom>
</txp:article_custom>

My Question how can i make class “collapse” change based on category. For example Section_name1>Category1>Title1,Section_name2>Category2>Title2

<ul><li>
h1. category1_title
<ul class="collapse">
<li>article_under_cat1</li>
<li>article_under_cat1</li>
</ul>
</li>
<li>
h1. category2_title
<ul class="collapse">
<li>article_under_cat2</li>
<li>article_under_cat2</li>
</ul>
</li>
</ul>

When article_under_cat2 is active i want to remove class collapse from its parent ul tag. I dont want to use javascript to alter the class.

Thanks

Last edited by piyashrija (2014-04-24 01:28:31)

Offline

#2 2014-04-24 01:27:56

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Change class inside article_custom loop

You will have to loop through the articles in each category and see if the active article is in it. You can achieve this with few variable and if_variable tags, that are used to store the rendered article list, its status and then check the results and return the results accordingly. Like so:

<txp:article_custom section='<txp:section/>' is_index="1">

    <h1><txp:category1 title="1" /></h1>

    <!-- Store rendered article list in an variable -->
    <txp:variable name="article:list">

        <!-- Set 'article:active'  variable to '0'.
        By default expect that there is no active article in this category. -->
        <txp:variable name="article:active" value="0" />

        <txp:article_custom category='<txp:category1 />'>

            <!-- Whether this article is active, if it is, set 'article:active' to '1' -->
            <txp:if_article_id>
                <txp:variable name="article:active" value="1" />
            </txp:if_article_id>

            <li><txp:permlink><txp:title/></txp:permlink></li>
        </txp:article_custom>
    </txp:variable>

    <!-- Return the rendered article list that is stored in the 'article:list' variable -->
    <txp:if_variable name="article:active" value="1">
        <ul class="expand">
            <txp:variable name="article:list" />
        </ul>
    <txp:else />
        <ul class="collapse">
            <txp:variable name="article:list" />
        </ul>
    </txp:if_variable>

</txp:article_custom>

Last edited by Gocom (2014-04-24 18:29:02)

Offline

#3 2014-04-24 02:37:48

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Re: Change class inside article_custom loop

Thank you so much :)

Last edited by piyashrija (2014-04-24 04:05:28)

Offline

#4 2014-04-24 11:01:52

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: Change class inside article_custom loop

@Gocom

is_index="1". Never see this attribut. I don’t found in documentation
What it does ?

Edit: Sorry for this question… It’s probably a custom_field. I go drink a cafe.

Last edited by sacripant (2014-04-24 11:05:02)

Offline

Board footer

Powered by FluxBB