Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-04-13 12:34:42

griffin
New Member
Registered: 2011-04-13
Posts: 2

How to Create a Date Based Breadcumb Trail?

hello all,

so i’ll get right to it, other than to say, i am new to texpattern, so maybe talk slow for the baby.

what i’d like to achieve is a persistent, hyperlinked, and page conditional, breadcumb style navigation path. something like this: Home>2011>April>13>[current location]. a loose example in the wild might be dave winer’s site.

i’ve kinda hacked and slashed something together with lots of conditionals, but the hyperlinks did not work as i intended them to.

for example if the trail looked like so: Home>2011>April>13 and one clicked on the 13, with a fair assumption this behavior would result in a new page with articles from April 13th, 2011, then one would be disappointed. as they would instead get a page that looked exactly like the homepage, but with what i assume is the correct url of http://example.com/2011/04/13/.

i don’t want to debug a flawed method here so suppose my question is can anyone spoon feed me a working example of a persistent, hyperlinked, and page conditional, breadcumb style navigation like i am trying to get at here.

i’ll add the caveots that i have poked around the greater internets and sifted through documentation and forum postings but either my ignorance or the paucity of an obvious and suitable answer halted my progress. oh, and this forum has been very helpful in other matters thus far. big thanks for folks taking the time out to lend a hand. so very much appreciated.

Offline

#2 2011-04-13 12:49:57

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: How to Create a Date Based Breadcumb Trail?

Txp doesn’t support such a URL scheme out of the box. Best bet is the gbp_permanent_links plugin. (I’m not very familiar with actually using the plugin, and unfortunately the only documentation is the very long forum thread, but I’m pretty sure it will do what you need.)

FYI, the only Txp-native URL for, say, all articles published on 2011-04-13 is http://example.com/?month=2011-04-13. (For all articles published in April 2011, it would be http://example.com/?month=2011-04.)


Code is topiary

Offline

#3 2011-04-13 13:30:08

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: How to Create a Date Based Breadcumb Trail?

Jeff I didn’t know that the ?month= URL exist & work (Not, that I would need it).
Are those ‘messy’ URL parameters documented/listed somewhere?


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#4 2011-04-13 14:28:52

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: How to Create a Date Based Breadcumb Trail?

merz1 wrote:

Are those ‘messy’ URL parameters documented/listed somewhere?

The “month” URL param is not well documented for such a basic feature. I included some discussion in my Txp context demo.


Code is topiary

Offline

#5 2011-04-13 15:43:30

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: How to Create a Date Based Breadcumb Trail?

merz1 wrote:

Jeff I didn’t know that the ?month= URL exist

As one of the early participants in the Archive lists by month (section, category, etc) with 4.0.2 thread, I didn’t know you could do that either. I assume it got added later.

That has some very interesting potential. I was working on some data-based archives last week for a project and going through all sorts of convolutions and was a little bit worried about the overhead cost. I am really looking forward to experimenting with this.

Offline

#6 2011-04-14 11:23:52

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: How to Create a Date Based Breadcumb Trail?

[OT] Jeff Kudos for your Textpattern date context article code example:

<div class="archive-menu">
<txp:article_custom limit="9999" sort="Posted" break="">
    <txp:if_different>
        <a href="<txp:site_url />context_demo/?month=<txp:posted format="%Y" />">
            <txp:posted format="%Y" />
        </a>
    </txp:if_different>
</txp:article_custom>
</div>

Thinking about putting that neat archive menu into my standard footer :)


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#7 2011-04-15 02:06:44

griffin
New Member
Registered: 2011-04-13
Posts: 2

Re: How to Create a Date Based Breadcumb Trail?

appreciate the response jeff. i’ll check out that plugin you mentioned, and if i can’t get it all wrapped up and working, worse case would be just letting it go and moving on. no worries.

again, much thanks for the help.

Offline

#8 2011-05-18 19:36:08

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

Re: How to Create a Date Based Breadcumb Trail?

I’ve got something that almost works, using the txp:posted and the rah_get_date plugin.

Here’s my code:

<txp:if_individual_article>
	&#187; <a href="<txp:site_url/><txp:section/>/?month=<txp:posted format="%Y"/>" rel="tag"><txp:posted format="%Y"/></a>
	&#187; <a href="<txp:site_url/><txp:section/>/?month=<txp:posted format="%Y"/>-<txp:posted format="%m"/>" rel="tag"><txp:posted format="%b"/></a>
	&#187; <a href="<txp:site_url/><txp:section/>/?month=<txp:posted format="%Y"/>-<txp:posted format="%m"/>-<txp:posted format="%d"/>" rel="tag"><txp:posted format="%d"/></a>
	<txp:else/>
	<txp:variable name="has_year"><txp:rah_get_date format="%Y"/></txp:variable>
	<txp:variable name="has_month"><txp:rah_get_date format="%m"/></txp:variable>
	<txp:variable name="has_day"><txp:rah_get_date format="%d"/></txp:variable>
	<txp:if_variable name="has_year" value="">
		<txp:else/>
		&#187; <a href="<txp:site_url/><txp:section/>/?month=<txp:rah_get_date format="%Y"/>" rel="tag"><txp:rah_get_date format="%Y"/></a>
		<txp:if_variable name="has_month" value="">
			<txp:else/>
			&#187; <a href="<txp:site_url/><txp:section/>/?month=<txp:rah_get_date format="%Y"/>-<txp:rah_get_date format="%m"/>" rel="tag"><txp:rah_get_date format="%b"/></a>
			<txp:if_variable name="has_day" value="">
				<txp:else/>
				&#187; <a href="<txp:site_url/><txp:section/>/?month=<txp:rah_get_date format="%Y"/>-<txp:rah_get_date format="%m"/>-<txp:rah_get_date format="%d"/>" rel="tag"><txp:rah_get_date format="%d"/></a>
			</txp:if_variable>
		</txp:if_variable>
	</txp:if_variable>
</txp:if_individual_article>

In individual article view the posted tag pulls in the relevant date information and constructs the ?month= URLs perfectly. And each month URL displays the relevant articles without a hitch.

The only trouble I have is when looking at the article list. If no ?month= is specified in the URL, everything works perfectly. However, if there is a ?month= string with missing parameters, all of my if_variable conditionals evaluate as true anyway, even when the month and/or day are unset, like they would be in URLs such as ?month=2011 or ?month=2011-05.

What I’ve found is that rah_get_date outputs today’s date information when parameters are unset. So if the URL is ?month=2009 and I access it today, it will output “2009” for the year, along with “May” for the month, and “18” for the day. If the URL were ?month=2009-07, it would output the specified year and month, but output today’s date in lieu of leaving that parameter blank.

Not sure what to do from here— Jukka provides excellent support for his plugins, but I can’t find a thread for this one. Any insight or suggestions would be very helpful!

Offline

#9 2011-05-19 03:59:11

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: How to Create a Date Based Breadcumb Trail?

I wrote the solution I have been working on for Date-Based Archives. I decided to pass the individual variables for year, month, and day in separately and then figure out how to call article_custom from there. My thought was that if someone were to type in the address bar to create a specific archive of their own, it would be a little simpler. It is a very different approach, but seems to arrive close to what you are looking for.

Offline

#10 2011-05-19 18:55:52

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

Re: How to Create a Date Based Breadcumb Trail?

Okay, I’ve almost cracked it!

Because rah_get_date was outputting the current date to my has_year, has_month, and has_day variables, I used a different method to set the variables.

In the code above, I took out these three lines:

<txp:variable name="has_year"><txp:rah_get_date format="%Y"/></txp:variable>
<txp:variable name="has_month"><txp:rah_get_date format="%m"/></txp:variable>
<txp:variable name="has_day"><txp:rah_get_date format="%d"/></txp:variable>

And I replaced them with this:

<txp:php>
	global $variable;
	$pax_get_date = gps("month");
	list($variable['has_year'], $variable['has_month'], $variable['has_day']) = explode('-', "$pax_get_date-");
</txp:php>

The entire breadcrumb now works as expected in individual_article context, day-based article_lists, and month-based article_lists. The only trouble is that when I view it in year-based article_list (a URL like ?month=YYYY, where the month and day are unset), I get the following PHP error:

Tag error: <txp:php> -> Notice: Undefined offset: 2 on line 4
textpattern/publish/taghandlers.php:3741 eval()textpattern/publish.php:1188 php()textpattern/publish.php:1113 processTags()textpattern/publish/taghandlers.php:3219 parse()textpattern/publish.php:1188 if_individual_article()textpattern/publish.php:1113 processTags()textpattern/publish/taghandlers.php:3694 parse()textpattern/publish.php:1188 if_section()textpattern/publish.php:1113 processTags()textpattern/lib/txplib_misc.php(653) : eval()’d code:22 parse()

Since I was only following a pattern posted here by Stef, and I don’t know PHP, I don’t know how to correct this error. Any advice?

Thanks again!

Edit: Fix textile.

Last edited by johnstephens (2011-05-19 18:56:19)

Offline

#11 2011-05-19 19:19:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,944
Website GitHub

Re: How to Create a Date Based Breadcumb Trail?

johnstephens wrote:

when I view it in year-based article_list (a URL like ?month=YYYY, where the month and day are unset), I get the following PHP error: Tag error: <txp:php> -> Notice: Undefined offset: 2 on line 4

Ah, yes, an unfortunate side-effect of using list() to load variables up is that if there aren’t enough to fill all your list variables then PHP complains. A few ways round it, none of them pretty. Probably the best is to explode the $pax_get_date first into a single array variable, then count how many you have. Once you know that, you can assign them to the relevant $variable(s).

You can either do a few if statements or a switch-case. For example (untested):

<txp:php>
	global $variable;
	$pax_get_date = gps("month");
	$items = explode('-', "$pax_get_date-");
	$num_items = count($items);

	if ($num_items > 2) {
		$variable['has_day'] = $items['2'];
	}
	if ($num_items > 1) {
		$variable['has_month'] = $items['1'];
	}
	if ($num_items > 0) {
		$variable['has_year'] = $items['0'];
	}
</txp:php>

There might be a sexier way to accomplish it, but that’s probably the most robust, if wordy, method. EDIT: not sure if you need the additional hyphen on the end of your 2nd explode() argument. Try it with and without to see how it works out.

EDIT2: alternatively, just stick with your original code, put your site in live mode and ignore the warnings, then use txp:if_variable later to check which ones are set :-D

Last edited by Bloke (2011-05-19 19:23:43)


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

#12 2011-05-19 19:29:38

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

Re: How to Create a Date Based Breadcumb Trail?

Bloke wrote:

Ah, yes, an unfortunate side-effect of using list() to load variables up is that if there aren’t enough to fill all your list variables then PHP complains. A few ways round it, none of them pretty. Probably the best is to explode the $pax_get_date first into a single array variable, then count how many you have. Once you know that, you can assign them to the relevant $variable(s).

You can either do a few if statements or a switch-case. For example (untested):

[…]

There might be a sexier way to accomplish it, but that’s probably the most robust, if wordy, method.

Awesome, Stef— in my quick test, this code block worked like a charm!

EDIT2: alternatively, just stick with your original code, put your site in live mode and ignore the warnings, then use txp:if_variable later to check which ones are set :-D

I thought that might work too. Are there any notable drawbacks or benefits either way?

Thanks again!

Offline

Board footer

Powered by FluxBB