Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-04-13 19:25:44
- manastojones
- Member
- Registered: 2009-04-13
- Posts: 14
How do you display the first article in a different spot?
Hi. I am new to Textpattern. Right now I am just messing around with it, but there is something I would like to be able to do that I just can’t figure out.
On my home page, I have a list of articles displayed like so:
<header></header>
<content>
<sidebar></sidebar>
<txp:article limit="10" offset="1" />
</content>
<footer></footer>
Anyway, I have it offset by one because I would like to display the first article in a different spot, preferably below the <header>
and above the <footer>
like so:
<header></header>
<txp:article allowoverride="0" form="article_head" limit="1" />
<content>
This way the first post could always be something like a sticky post, but the problem is it doesn’t render on the article_list
page, and when it renders on the individual_article
page (which I don’t want it to at all), Textpattern treats it as if there are two seperate articles on one page and places comments bellow each instance.
I’m sure I am doing this wrong, but there has to be a way to display the first article differently in a separate spot on the site on the index page, and have it not show up at all when browsing individual articles. Just for measure, here is the form I am trying to use:
<txp:if_article_list>
<p class="category">In <txp:category1 title="1" link="1" /><txp:category2> and <txp:category2 title="1" link="1" /></txp:category2></p>
<txp:article_image wraptag="div" class="image" />
<div class="post-info">
<h3><txp:permlink><txp:title /></txp:permlink></h3>
<txp:posted format="%B %e, %Y" wraptag="p" class="date">
</div>
<div id="clearfix"></div>
</txp:if_article_list>
I am just not sure what I am doing wrong. Can anybody help me figure this out?
Last edited by manastojones (2009-04-13 19:44:12)
Offline
Re: How do you display the first article in a different spot?
A few ways:
A)
<txp:if_article_list>
<!-- we are on an article list context -->
<txp:article limit="1" />
<txp:article limit="10" offset="1" />
<txp:else />
<!-- we are on an individual article context -->
<txp:article />
</txp:if_article_list>
B)
<txp:article limit="10" form="myArticleForm" />
Then, on your “myArticleForm”:
<txp:if_article_list>
<txp:if_first_article>
...some article tags and super cool and clever HTML for first article...
<txp:else />
...some article tags and common HTML for following posts...
</txp:if_first_article>
<txp:else />
... we are on individual article....
</txp:if_article_list>
There are other possible ways.
Last edited by maniqui (2009-04-13 19:50:23)
Offline
#3 2009-04-14 14:31:08
- manastojones
- Member
- Registered: 2009-04-13
- Posts: 14
Re: How do you display the first article in a different spot?
Thanks. I looked it over and decided to do something different.
I set up the default page to be the one that handles the article_list
, and a new page to handle individual articles that basically puts almost all of the html (txp tag or not) inside the <txp:if_individual_article>
tag.
This is the only way I could find that did what I wanted it to do.
I appreciate your help.
Last edited by manastojones (2009-04-14 14:31:57)
Offline
Re: How do you display the first article in a different spot?
Wonder how you did it…
Pages (“Presentation -> Pages”) are attached to sections, not to individual/list context. In other words, you can’t tell TXP to use a particular page when in individual article context and another one when in article list context.
In other words, if you are looking at www.example.com/section/
(article list) or at www.example.com/section/article
(individual article), the same page template is used to render both of them.
Of course, there is an “exception”, and that’s probably what you did. Your “home page” section (aka “default”, www.example.com
) is an special section and it acts like an article list.
You can tell TXP (on “Presentation -> Sections”) to use a particular page template for the “home“ (“default”) section, and another template for a section (/section/).
So it seems that what you are doing, in the background, is to use one page template to render the “home page” and another page template to render the “section” (both if you are looking an article list or an individual article for that section).
So, if you go to www.example.com/section/
, you probably won’t see nothing (if, as you said, you’ve wrapped the whole page template in if_individual_article
tags).
It’s a “awkward” approach, imho, but if it worked for you… no need to fix it then :)
Offline
#5 2009-04-14 15:17:26
- manastojones
- Member
- Registered: 2009-04-13
- Posts: 14
Re: How do you display the first article in a different spot?
I’ll go ahead and post the code for both pages and you’ll see it’s really nothing special. You can see how it works here, but, again, I am just testing out text pattern with this stuff. I am not really that used to how it organizes data, nor do I know the best way to go about it. Anyway, the whole point was to have the first article appear in a div above the <sidebar>
and <content>
divs so that it could span the entire page. I also wanted to be able to use an entirely different form to style it. Here’s what I did.
For the default section, which I pointed to a page titled “default”, where all my articles are displayed in a list, I used this code:
<txp:php> include 'textpattern/php_include/header.php' ; </txp:php>
<txp:if_article_list>
<txp:article allowoverride="0" form="article_head" limit="1" pgonly="0"/>
</txp:if_article_list>
<txp:php> include 'textpattern/php_include/sidebarone.php' ; </txp:php>
<div id="content">
<txp:article limit="10" offset="1" />
</div>
<txp:php> include 'textpattern/php_include/footer.php' ; </txp:php>
I’m sure there’s nothing groundbreaking here.
For the my articles section, which I point to a page titled “articles”, where I just want to display my individual articles (for now, anyway, while I’m learning the system), I used this code:
<txp:php> include 'textpattern/php_include/header.php' ; </txp:php>
<txp:if_individual_article>
<txp:article allowoverride="0" form="individual_article" />
</txp:if_individual_article>
<txp:php> include 'textpattern/php_include/footer.php' ; </txp:php>
The individaul_article
form looks like this:
<div id="article-head">
<txp:article_image wraptag="div" class="image" />
<h2><txp:title /></h2>
<txp:if_article_category name="reviews">
<txp:if_custom_field name="Work Title"><li>A review of <txp:custom_field name="Work Title" /></li></txp:if_custom_field>
<txp:if_custom_field name="Work Artist"><li><txp:custom_field name="Work Artist" /></li></txp:if_custom_field>
<txp:if_custom_field name="Work Country"><li><txp:custom_field name="Work Country" /></li></txp:if_custom_field>
<txp:if_custom_field name="Work Year"><li><txp:custom_field name="Work Year" /></li></txp:if_custom_field>
<txp:else />
<span class="excerpt"><txp:excerpt /></span>
</txp:if_article_category>
<div id="clearfix"></div>
</div>
<txp:php> include 'textpattern/php_include/sidebar-single.php' ; </txp:php>
<div id="content">
<txp:body />
</div>
Again, I am bound to run into some problems once I fully realize how people are going to navigate a Textpattern site (or how I want them to be able to), but for now this works fine for me.
Actually, as I type this, I realize I could do this all on the same page with <txp:if_article_list>
and <txp:if_individual_article>
tags and form overrides. I think the only reason I did it this way is because I felt I had to include basically an entire pages worth of code inside the individual_article
tag like I did above.
Hitting myself right now!! But there you go, nothing but me being an idiot.
But yeah, that’s what I did.
Last edited by manastojones (2009-04-14 17:21:33)
Offline