Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-03-29 20:42:21

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

Article display question

Hi all,

I’m working on a website and have run into a knowledge gap! I have a news page and the way I’ve done it means that when I show more than one article it also repeats the side panel. I understand why it’s happening but can’t figure out a workaround, I tried moving the side panel out of the form and into the page but that didn’t work. I’ve been going around in circles trying to figure it out.

My code is below and would really appreciate some help/guidance:

My form is:

<div class="sidepanelLeft">
   <div class="sidepanelLeft">
      <h4>Older <txp:section /> articles</h4>
         <txp:variable name="has_articles" value='<txp:article_custom section=''<txp:section />'' limit="1" />' />
         <txp:if_variable name="has_articles" value="">
      <txp:else />
      <div class="">
         <txp:article_custom section='<txp:section />' wraptag="ul" class="articleListing" break="li" offset="2" >
         <txp:permlink><txp:title /></txp:permlink>
         </txp:article_custom>
      </div>
     </txp:if_variable>
   </div><!-- end sidepanelLeft -->
</div><!-- end sidepanelLeft -->
<!--///////////// article /////////////-->
<div id="main_content">
        <div class="fullWidthArticle">
            <h3 class="article"><txp:title /></h3>
            <p class="sub_heading">Posted on
            <txp:posted format="%e" wraptag="span" class="day" />
            <txp:posted format="%B" wraptag="span" class="month" />
            <txp:posted format="%Y" wraptag="span" class="year" />
            </p>
            <txp:body />
        </div><!-- end fullWidthArticle -->
</div><!-- end #main_content -->

And my page call is:

<txp:if_individual_article>
            <txp:article allowoverride="0" form="article_news" limit="1" section="news" pgonly="0" searchall="0" searchsticky="0" sort="Posted desc" status="4" />
           </txp:if_individual_article>
           <txp:if_article_list>
                   <txp:article_custom allowoverride="0" form="article_news" limit="2" pgonly="0" section="news" sort="Posted desc" status="4" />
           </txp:if_article_list>

Thanks.

Offline

#2 2011-03-29 20:48:52

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 590
Website

Re: Article display question

Why not do this in your page?

<txp:if_individual_article>
    <!-- article tag goes here -->
    <!-- output_form tag to display sidebar goes here -->
</txp:if_individual_article>

You’re already using article_custom with an offset in the sidebar, so I don’t see why it couldn’t be done.

Offline

#3 2011-03-29 22:06:07

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

Re: Article display question

Hi Marc,

Thanks for that, it makes for a lot of forms but it’s beginning to work although the repeated article divs are not being pushed over by the sidebar float. Not sure CSS can solve that problem efficiently as the height will change dynamically depending on the number of posts.

Offline

#4 2011-03-29 22:09:33

woof
Member
Registered: 2004-08-01
Posts: 128

Re: Article display question

There may be a more elegant solution, but you could use the if_first_article tag to only output the sidebar content (ie the news index) once for the article list.

<txp:if_first_article >
<div class="sidepanelLeft">
   <div class="sidepanelLeft">
      <h4>Older <txp:section /> articles</h4>
         <txp:variable name="has_articles" value='<txp:article_custom section=''<txp:section />'' limit="1" />' />
         <txp:if_variable name="has_articles" value="">
      <txp:else />
      <div class="">
         <txp:article_custom section='<txp:section />' wraptag="ul" class="articleListing" break="li" offset="2" >
         <txp:permlink><txp:title /></txp:permlink>
         </txp:article_custom>
      </div>
     </txp:if_variable>
   </div><!-- end sidepanelLeft -->
</div><!-- end sidepanelLeft -->
<!--///////////// article /////////////-->
<div id="main_content">
        <div class="fullWidthArticle">
            <h3 class="article"><txp:title /></h3>
            <p class="sub_heading">Posted on
            <txp:posted format="%e%B" wraptag="span" class="day" />
            <txp:posted format="%B" wraptag="span" class="month" />
            <txp:posted format="%Y" wraptag="span" class="year" />
            </p>
            <txp:body />
        </div><!-- end fullWidthArticle -->
</div><!-- end #main_content -->

<txp:else/>

<div class="sidepanelLeft">
   <div class="sidepanelLeft">

   </div><!-- end sidepanelLeft -->
</div><!-- end sidepanelLeft -->
<!--///////////// article /////////////-->
<div id="main_content">
        <div class="fullWidthArticle">
            <h3 class="article"><txp:title /></h3>
            <p class="sub_heading">Posted on
            <txp:posted format="%e%B" wraptag="span" class="day" />
            <txp:posted format="%B" wraptag="span" class="month" />
            <txp:posted format="%Y" wraptag="span" class="year" />
            </p>
            <txp:body />
        </div><!-- end fullWidthArticle -->
</div><!-- end #main_content -->

</txp:if_first_article >

Offline

#5 2011-03-29 22:27:21

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 590
Website

Re: Article display question

.main_content {
float:right; 
margin-right:50px /* or whatever */
}

Give that a try. Also if the sidebar div is just going to be empty, I would make its appearance conditional; i.e. not as part of the sidebar form, but as part of the form used to display the article tag inside that form.

Offline

#6 2011-03-29 22:29:45

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

Re: Article display question

Hi John,

Thanks, that’s a really nice, elegant solution – I didn’t think of using the <txp:if_first_article >. It’s always great if one form can cover everything.

There’s just a couple of things that I need to get around. One is that the posted month is appearing twice for some reason. The other is the offset, when it’s the news articles+index it currently works fine but when it’s an individual article the offset should only be one – do I need to add in another condition?

Thanks Marc for the CSS tip, I’ll give that a try.

Last edited by decoderltd (2011-03-29 22:32:01)

Offline

#7 2011-03-29 22:31:49

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 590
Website

Re: Article display question

Look here in John’s code:

    <txp:posted format="%e%B" wraptag="span" class="day" /> <!-- should just be %e, not %e%B -->

Offline

#8 2011-03-29 22:33:30

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

Re: Article display question

Thanks Marc, I should have spotted that.

Last edited by decoderltd (2011-03-29 22:33:45)

Offline

#9 2011-03-29 23:03:09

woof
Member
Registered: 2004-08-01
Posts: 128

Re: Article display question

decoderltd wrote:

the posted month is appearing twice for some reason.

ouch – really sorry for doing that to you and thanks Marc for spotting it

The other is the offset, when it’s the news articles+index it currently works fine but when it’s an individual article the offset should only be one – do I need to add in another condition?

I would either use if_individual_article in the existing form or create a separate form for individual articles and use form="x" and listform="y" in my page call article_custom tags

Offline

#10 2011-03-30 10:12:01

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

Re: Article display question

Thanks for all your help John, it’s good to get back to TXP after a brief spell wrestling with Wordpress.

Thanks too to Marc for the CSS tip.

Offline

Board footer

Powered by FluxBB