Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to use Next and Previous article links across different sections?
I’m using txp:link_to_next and txp:link_to_prev and notice that they will only link to the next/previous article in the same section as the one being viewed. How can I make the link to the actual next or previous article, regardless of section?
Offline
Re: How to use Next and Previous article links across different sections?
I’m not sure, but possibly if you output articles with <txp:article_custom />
(which can output from any section) rather than <txp:article />
(which outputs from the current section, you’ll get the result you’re looking for. Hmm. Not sure though.
Offline
Re: How to use Next and Previous article links across different sections?
The point about sections is that they are separate blocks of content within your site. Previous/next links are not intended to link between sections. If a visitor to your site selects a specific section to look at why would he/she want to see articles from another section except by specifically clicking on a link to that section? What I think you need to review is the way you are using both sections and categories. Your articles could all belong to a common section but be categorised according to content. With all articles within the same section, the prev/next links would do what you want but you could then give your visitors the option to view specific categories either by using the category1 and category2 tags as links within the articles or by creating a category list as part of your sidebar, or using category links as part of your main or top_nav, or a combination of any or all of the above.
Last edited by thebombsite (2008-10-10 17:37:06)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: How to use Next and Previous article links across different sections?
Thanks for your replies!
Stuart, I am using sections as ways to force different templates/layouts on different articles depending on the type of content they contain. Can you (or anyone) suggest a better way to do this with minimal customization?
Offline
Re: How to use Next and Previous article links across different sections?
I just knew it couldn’t be that simple. ;)
If that’s the reason for the different sections then it is probably better to look at whether someone can come up with a linking method for you. I suspect it could be done with a couple of PHP snippets but I’m afraid PHP is not my strong-point.
EDIT Just thinking about it for a few minutes, despite my lack of PHP expertise, I have the distinct impression that PHP may not be of use here as the articles can be in different sections which would require a major change to the URL for the prev/next article. It isn’t just a case of picking up the article id. Anyway let’s see if anyone comes up with anything.
Having said that there is the <txp:if_article_category> tag which you could use “within an article form” to create different layouts and also to give different class or id names to blocks so that different CSS selectors can be aimed at them. That would require some restructuring though as it assumes what I said in my previous post. (There is also the <txp:if_article_section> tag but I’m not sure that it is as useful here.)
Last edited by thebombsite (2008-10-10 18:17:19)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: How to use Next and Previous article links across different sections?
This is a tricky one for sure. From TXP’s (and therefore PHP’s) article perspective, each section is a different entity with a moat round it and and it’s not easily crossable from ground level. As nabrown78 pointed out, article_custom might well help. I’ve not tried it but you may be able to do something like this:
<txp:article_custom form="all_sections" />
Then in form all_sections
you can have a set of statements like this:
<txp:if_article_section name="sec1">
<txp:output_form form="layout_sec1" />
<txp:css format="link" n="css_sec1" />
</txp:if_article_section>
<txp:if_article_section name="sec2">
<txp:output_form form="layout_sec2" />
<txp:css format="link" n="css_sec2" />
</txp:if_article_section>
// and so on
Thus your forms take the place of your pages and you can put your HTML markup in them. Seems like a lot of work, though so I hope someone else can come up with something better than that! If it does happen to work and you go this route I would suggest consolidating / cascading stuff even further and putting other common things in forms as well, e.g. the DTD, a common masthead, perhaps your footer and so on to save yourself some typing.
Another alternative (getting tricky here) : you might be able to get hold of a list of sections via some tag, stash them on the page somewhere (perhaps in a <txp:variable />
if you are using a recent SVN copy of Textpattern) and through cunning use of <txp:if_last_article />
/ <txp:if_first_article />
find out what the ‘next’ section would be and grab the next set of articles when you ‘fall off the end’ of a section and make a custom link to the first article of the next section. Not pretty.
If all else fails, the smd_query plugin might help if you are a dab hand at SQL.
Last edited by Bloke (2008-10-10 19:45:53)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#7 2008-10-11 00:30:50
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: How to use Next and Previous article links across different sections?
Bloke wrote:
<txp:if_article_section name="sec1">
<txp:output_form form="layout_sec1" />
<txp:css format="link" n="css_sec1" />
</txp:if_article_section>
<txp:if_article_section name="sec2">
<txp:output_form form="layout_sec2" />
<txp:css format="link" n="css_sec2" />
</txp:if_article_section>
// and so on
asy_wondertag to the rescue :)
<txp:asy_wondertag>
<txp:output_form form="layout_<txp:section />" />
<txp:css format="link" n="css_<txp:section />" />
</txp:asy_wondertag>
I’m not sure if you can use two tags inside asy_wondertag, if not wrap both tags each in their own set.
If the layouts are not very different, it might be possible to do just something like this:
<txp:asy_wondertag>
<body id="<txp:section />">
</txp:asy_wondertag>
Last edited by els (2008-10-11 00:35:17)
Offline
Re: How to use Next and Previous article links across different sections?
And something else I thought of as I was trying to get to sleep last night (yes I know, sad isn’t it?), there is also the “Override form” option under the “Advanced Options” on the Write tab which would allow you to allocate specific article forms to the different articles.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: How to use Next and Previous article links across different sections?
Floodfish –
You could still use categories rather than sections, and then use CSS to control the layout. On an individual article page, you could do something like <body class="<txp:category1 />Body">
and then style accordingly. You can also use <txp:if_category>
to output specific items depending on what category the article is in. Of course, you could do the same with sections, but thebombsite’s explanation of sections vs. categories is good, and using categories instead would solve your prev/next nav issue.
Offline
Re: How to use Next and Previous article links across different sections?
Thanks, everyone! You’ve vastly improved my understanding of sections vs. categories.
I finally got around to fixing it up. I redid it using categories rather than sections.
Offline