Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-06-09 11:56:50

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,192
Website GitHub

link_to_next & prev within a category?

1) Is there a category-sensitive use or alternative for txp:link_to_next and txp:link_to_prev?

The context is: if_individual_article
The tag used in: an article form

The result: nice next and previous links but they disregard the current category.

I’ve got a workaround going using zem_nav and the modification suggested here:
<code>
replace: if ($usecat) $category = empty($c) ? ‘’ : $c;
with: if ($usecat) $category = empty($thisarticle[‘category1’]) ? $c : $thisarticle[‘category1’];
</code>
However, it is only then sensitive to category1.

  • * *

2) A related question:
If I assign an article 2 categories: “apples” and “green” it will appear in the category articles list for “apples” and the category list for “green”. That’s great.

When I click on the article in the “apple” category articles list and then want to link_to_next and link_to_prev I want to page back and forth between apples.
If I click on the article in the “green” category articles list, I want to page back and forth between all green fruits. At the moment this doesn’t happen.
How can I make the article form (for instance the breadcrumb) and link_to_prev and link_to_next know which of the two categories is currently relevant?


TXP Builders – finely-crafted code, design and txp

Offline

#2 2006-06-16 19:45:15

reptilerobots
Member
Registered: 2005-08-20
Posts: 72

Re: link_to_next & prev within a category?

Did you ever find a way to go to the next , or previous article within a category? I have one section “vault” and 3 categories – design, illustration, drawing – Id rather just have them all in one section, instead of 3. The regular txp tags, next/prev just return the next/prev articles within the section, not the category.

Offline

#3 2006-06-16 20:10:55

Elenita
Member
From: Falls Church, VA
Registered: 2004-05-16
Posts: 407
Website

Re: link_to_next & prev within a category?

<a href=“http://textpattern.org/plugins/154/lownav”>low_nav plugin</a> to the rescue!

Offline

#4 2006-06-16 20:40:16

reptilerobots
Member
Registered: 2005-08-20
Posts: 72

Re: link_to_next & prev within a category?

Its funny how long I search for these, and cant find them – thanks for coming to the rescue

Offline

#5 2006-06-16 20:45:52

reptilerobots
Member
Registered: 2005-08-20
Posts: 72

Re: link_to_next & prev within a category?

foiled again. Link is dead, and I think its for an earlier version of TXP!

Offline

#6 2006-06-16 20:56:14

Elenita
Member
From: Falls Church, VA
Registered: 2004-05-16
Posts: 407
Website

Re: link_to_next & prev within a category?

D’oh! I suggest contacting <a href=“http://justinlow.com/”>the developer</a> directly then.

Edited to add a request: if you receive an answer from Justin, please post to this thread again so that others may learn what’s going on with that plugin.

Last edited by Elenita (2006-06-16 21:01:29)

Offline

#7 2006-06-17 08:44:46

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,192
Website GitHub

Re: link_to_next & prev within a category?

I haven’t solved it yet. I also don’t have low_nav and I don’t know if he ever got it working with the current category rather than just category1 as he wrote in the thread.

This questions seems key to me:
How does the page which displays the article know what the ‘current’ category is, i.e., from which category list it has been linked? Can one write out an URL for that so I can understand it better?

  1. For the section I have an URL site/section and display a category list
  2. When I click on a category title I have an URL site/section&c=category and display a list of articles in that category
  3. When I click on one of these articles I have an URL site/section/article-name – there’s no indication of a category filter at all. For this you’d need an section/category/article-name URL, and is that possible?

How do other tags such as related_articles work if an articles has two categories applied (I’ve never used it myself). Does it display articles from both categories, only category1 or does it ‘know’ what the current article is. Or perhaps there’s another article-level tag or plug-in which is sensitive to the ‘current’ category, from which we could learn? Is there actually an equivalent for txp:category for individual articles?

(thinking aloud here: maybe if it’s not possible with textpattern alone, one could pass on the current category from the list-of-articles-in-category page as an URLvar using chs_if_urlvar, but that’s pretty dirty. I’d much prefer a txp way of doing things.)

Last edited by jakob (2006-06-17 09:27:18)


TXP Builders – finely-crafted code, design and txp

Offline

#8 2006-06-17 18:04:58

reptilerobots
Member
Registered: 2005-08-20
Posts: 72

Re: link_to_next & prev within a category?

I got an email back from Justin Low, and he said that his plugin isn’t currently available for the newest version of textpattern. He also said to try zem_nav, but when I have installed the plugin, I get this error:<br><br>
Fatal error: Call to undefined function: formathref() in /home/content/r/e/p/reptilerobots/html/pages/textpattern/lib/txplib_misc.php(459) : eval()’d code on line 36<br><br>

so, apparently it doesnt work… and I still havent found other ways to browse articles by category. It seem like such a simple feature… you’d think it would have been a default tag.

Offline

#9 2006-06-17 18:20:42

Elenita
Member
From: Falls Church, VA
Registered: 2004-05-16
Posts: 407
Website

Re: link_to_next & prev within a category?

Sorry to hear that, reptilerobots.

The only thing I can suggest is to <a href=“http://forum.textpattern.com/viewforum.php?id=2”>formally request</a> that this feature be included in a future release.

Offline

#10 2006-06-17 22:50:05

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,192
Website GitHub

Re: link_to_next & prev within a category?

reptilerobots, zem_nav works if you install zem_link too (as it contains the function formathref). The modification mentioned at the beginning of the thread works at least for category1. If you have articles which are allocated two categories, then at present next and previous work within category1 only.


TXP Builders – finely-crafted code, design and txp

Offline

#11 2006-06-17 23:42:55

reptilerobots
Member
Registered: 2005-08-20
Posts: 72

Re: link_to_next & prev within a category?

really? I wasnt aware that I had to install zem_link – thanks! I am using 2 categories, the first cat is either design, drawings, illustration – the 2nd is just “new”, in the form that I am using to list each article, it spits out each category, and if_category is ‘new’ it just says NEW next to it.
Strange, I can’t get it to work. I installed zem_link, I dont get the error, but now the links they return are, for example:
<br><br>http://www.wearetherobots.com/pages/vault/drawing-2drawing-2<br><br> when it should be just <br><br>http://www.wearetherobots.com/pages/vault/drawing-2<br><br>
it’s reading the title twice and adding it to the link. I modified the lines as you mentioned in the first post.

Last edited by reptilerobots (2006-06-18 00:07:50)

Offline

#12 2006-06-18 08:31:40

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,192
Website GitHub

Re: link_to_next & prev within a category?

I think the double URL is a problem with an earlier version of zem_link. I’m using zem_link 0.6 and zem_nav 0.6 (tho’ I think it’s actually 0.4). There’s a link to a nwere zem_nav in this thread and to a newer zem_link courtesy of wet here.

You might also be able to achieve what you want with the “new” flag by setting those articles to sticky instead of live and marking articles with status sticky with the flag. You might have to play around a bit with txp:article or txp:article_custom to get it list them how you want. You could also do that using a custom_field and then test for txp:if_custom_field name=“new” value=“yes” (or something like that) then show “new” flag.

Last edited by jakob (2006-06-18 08:34:24)


TXP Builders – finely-crafted code, design and txp

Offline

#13 2006-06-18 21:35:22

reptilerobots
Member
Registered: 2005-08-20
Posts: 72

Re: link_to_next & prev within a category?

eh, it kind of works now. Remember all of my portfolio pieces are in a section called vault, and then caegorized by design, illustration, drawing, other.

If you go to the the first article in design – a design 1, (these are just mock up articles so I can get a sense of layout) – it should show the link to next article which is “b design 2”, which it does, but it also shows the previous link to “b illustration 2”. Completely strange, it is partially keeping categories, but not quite. But then when you go to “b illustration 2” it shows the correct prev and next articles. It’s only when you get to the very first and the very last articles in a category that it incorrectly shows the next link , or prev link which are outside of the current categories.

I want to keep my articles in alphabetical order, that’s why I don’t have the “new” ones set as sticky. But if that is messing up my highly experimental and theoretical idea of category navigation, then Ill change it how you suggested.

if you want to get a sense of whats going on, just check out www.wearetherobots.com/pages – and click on any link under “vault”

Offline

#14 2006-06-19 11:51:39

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,192
Website GitHub

Re: link_to_next & prev within a category?

Well, I’ve achieved a kind of workaround that appears to work, at least for my setup: I’ve written the currently chosen category into a cookie on the category selection page, then read that out for the article page and used it for the breadcrumbs and adapted zem_nav to use it for the linktonext and linktoprev.

If no cookie is set then zem_nav uses category1, which means that links which come from outside the site (e.g. a search machine or link from another referring site) will use whatever the first category is. If the page has been reached through the category selection page, then it will use whatever was chosen most recently.

There is one somewhat-likely situation where it will provide the wrong results: If the visitor has visited the site already (and set the cookie), then decides to revisit an article later without navigating through the site, i.e. by entering it in the browser address field (or his/her browser history), the value from the cookie will be used (because still set) although it may bear no relation to the article. I suppose one could unset the cookie when switching to other sections to minimise this risk.

You’ll need the chs_cookie plug-in and need to change a few lines in the zem_nav source code to get it to work.

I’ve done it like this:

Page template: In the list of articles in category page (i.e. <txp:if_article_list><txp:if_category>) I’ve set two cookies, one for the category name and one for the title. I’ve set one for the title because I need it for the breadcrumbs trail on my article page. Because of the nesting tags problem I’ve used txp:php:

<code>
<txp:php>
$cat_titel=fetch_category_title($GLOBALS[‘pretext’][‘c’]);
chs_set_cookie(array(‘cookie’=>‘currcategory_title’,‘value’=>$cat_titel));
chs_set_cookie(array(‘cookie’=>‘currcategory_name’,‘value’=>$GLOBALS[‘pretext’][‘c’]));
</txp:php>
</code>

For the breadcrumbs on the article page itself I have used a form for the breadcrumbs which also has next/prev navigation as follows (the next/prev are in span for floating separately):

<code>
<txp:section title=“1” link=“1” /> &rsaquo;
<txp:chs_cookie_exists cookie=“currcategory_title”>
<a href=”/<txp:section />/<txp:chs_echo_cookie cookie=“currcategory_name” />/”><txp:chs_echo_cookie cookie=“currcategory_title” /></a>
</txp:chs_cookie_exists>
<txp:chs_cookie_default cookie=“currcategory_title”><a href=”/<txp:section />/<txp:category1 link=“0” />/”><txp:category1 link=“0” title=“1” /></a></txp:chs_cookie_default>
<span><txp:zem_link_to_prev>&laquo;</txp:zem_link_to_prev>&nbsp;<txp:zem_link_to_next>&raquo;</txp:zem_link_to_next></span>
</code>

This makes a trail with “section title(linked)” > “categoryfromcookie_title(linked)” and “<” “>”. Where no cookie exists, “category1 title(linked)” is used.

In zem_nav I’ve added the following line to the functions zem_link_to_next and zem_link_to_prev

<code>

unset($linkatts[‘usesect’], $linkatts[‘usecat’]); // existing line
$currcat = chs_echo_cookie(array(‘cookie’=>‘currcategory_name’)); //NEW
</code>

and changed the line, again in each of the above functions:

<code>if ($usecat) $category = empty($c) ? ‘’ : $c;</code>
to
<code>if ($usecat) $category = empty($currcat) ? $thisarticle[‘category1’] : $currcat;</code>


TXP Builders – finely-crafted code, design and txp

Offline

#15 2006-06-19 16:07:34

reptilerobots
Member
Registered: 2005-08-20
Posts: 72

Re: link_to_next & prev within a category?

That seems like just too much trouble. Granted I can do it, but it seems just simpler to make 3 sections instead. The whole part that sucks about this issue, is you’d just assume you could browse by category… Considering that categories are put in place to differentiate content.

Offline

Board footer

Powered by FluxBB