Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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: 4,897
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

#16 2006-06-19 16:56:31

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,897
Website GitHub

Re: link_to_next & prev within a category?

yes I agree, it is a shortcoming at the moment. If one were able to use section/category/title urls then I imagine it would work with the normal txp commands (as the category context is then always given). Unfortunately, this combination is not currently supported at the moment.

The other related area I’ve found difficult to achieve is being able to filter by two categories, i.e. look for items (articles) according to type and location. This kind of search combination is fairly common in a non-blog environment, but I’ve only got part of the way there using similarly complex trickery.


TXP Builders – finely-crafted code, design and txp

Offline

#17 2006-06-23 16:17:18

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

Re: link_to_next & prev within a category?

Jakob – I restructured some things on my site, I just have everything lumped together instead of separate. Anyways, instead of assigning “new” to category 2, I am using a custom field called “new”. If the value is “new” it shows a dagger next to the article!

Thanks for your advice.

<code>
<txp:if_custom_field name=“new”>
<div class=“article”><txp:permlink><h2><txp:title /></h2><txp:excerpt /><h4><txp:category1 /></h4></txp:permlink><h5>&dagger;</h5></div>
<txp:else />
<div class=“article”><txp:permlink><h2><txp:title /></h2><txp:excerpt /><h4><txp:category1 /></h4></txp:permlink></div>
</txp:if_custom_field>

</code>

Offline

#18 2006-06-23 21:33:09

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,897
Website GitHub

Re: link_to_next & prev within a category?

yes, in your case it’s essentially a flag rather than a category. Not really important, but you could shorten your code by starting your if_custom_field just before h5 as that seems to be the only bit that changes.


TXP Builders – finely-crafted code, design and txp

Offline

#19 2010-04-14 15:47:07

inkywillow
Member
From: France
Registered: 2009-12-22
Posts: 37

Re: link_to_next & prev within a category?

Hi all, did anybody ever find a simple solution to this problem?


The Design Works – Freelance website designer

Offline

#20 2010-04-14 17:22:16

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: link_to_next & prev within a category?

Would smd_horizon do what you want?

Offline

#21 2010-04-14 18:48:21

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: link_to_next & prev within a category?

You can try this tip


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#22 2010-04-14 18:51:10

inkywillow
Member
From: France
Registered: 2009-12-22
Posts: 37

Re: link_to_next & prev within a category?

Hi Els,

I’m not sure.

I basically have a section called shop and each item (article) in it can have two categories assigned to it. ie A chair could be in both “Handmade” and “Furniture”.
The problem is when viewing the individual article the next and previous buttons scroll through ALL items in the shop section, jumping categories as it where.
What I would like to do is restrict the next and previous buttons to scrolling through just the first category chosen (from the main navigation).

Here’s the website in question www.outoflove.co.uk

Any pointers would be appreciated!

Tom

@The_ghost I think we posted at the same time, I’ll take a look, thanks.

Last edited by inkywillow (2010-04-14 18:54:37)


The Design Works – Freelance website designer

Offline

#23 2010-04-14 21:24:06

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: link_to_next & prev within a category?

Did you look at the plugin? As far as I know that is what it can do.

Offline

#24 2010-04-15 18:15:14

inkywillow
Member
From: France
Registered: 2009-12-22
Posts: 37

Re: link_to_next & prev within a category?

Yeah, I tried the code below.

The problem seems to be with using two categories. When you view an item, the next and previous results are restricted (correctly) to the “Current” two categories and all works well until you hit an item using a third category, this then becomes one of the two current categories. For example if you have an item from “Furniture” and its second category is “Handmade” the next and previous buttons would (at this point) scroll through all items in “Furniture” and “Handmade” but when you got to an item in say “Handmade” and “Gifts” the “Current” sections would now become “Handmade” and “Gifts”.

I think that I am going to have to change this to use only category1 and have just one category per item.

	<txp:chh_if_data>
<div class="left"><p><txp:chh_if_data><txp:smd_prev category='<txp:category1 />,<txp:category2 />'><txp:smd_if_start><txp:else /><a href="<txp:permlink />">« Previous item</a></txp:smd_if_start></txp:smd_prev></txp:chh_if_data></p></div>

<div class="right"><p> <txp:chh_if_data><txp:smd_next category='<txp:category1 />,<txp:category2 />'><txp:smd_if_end><txp:else /><a href="<txp:permlink />">Next item »</a></txp:smd_if_end></txp:smd_next></txp:chh_if_data></p></div>
		</txp:chh_if_data>

The Design Works – Freelance website designer

Offline

Board footer

Powered by FluxBB