Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-04-05 23:07:57

joel
Member
Registered: 2004-11-26
Posts: 162

Creating prev/next anchor links for navigation

Hi,

I would like to be able to navigate through my article list with an anchor link for each article with prev/next anchor-links below each article. I’m only gonna display the the articles in article_list mode – not individually.
This is basically what I wanna achieve: (my default article form)

<a name="#<txp:title />">asd</a>
<h2><txp:title /></h2>
<txp:body />
<p><a href="#<txp:prev_title />">Previuos</a> | <a href="#<txp:next_title />">Next</a></p>
<txp:prev_title />

This doesn’t work though!

If this isn’t possible with txp-tags, is it then possible to achieve this by using some php-code with the variables for prev_title and next_title?

Any help is highly appreciated! :)

Thanks!

Last edited by joel (2007-04-07 07:57:34)

Offline

#2 2007-04-06 21:22:02

joel
Member
Registered: 2004-11-26
Posts: 162

Re: Creating prev/next anchor links for navigation

In taghandlers.php I’ve found something interesting (from line 1065):

// -------------------------------------------------------------
// link to next article, if it exists
	function link_to_next($atts, $thing)
	{
		global $id, $next_id, $next_title;
 	extract(lAtts(array(
			'showalways' => 0,
		), $atts));
		if (intval($id) == 0)
		{
			global $thisarticle, $s;
			extract(getNextPrev(
				@$thisarticle['thisid'],
				@strftime('%Y-%m-%d %H:%M:%S', $thisarticle['posted']),
				@$s
			));
		}
		if ($next_id)
		{
			$url = permlinkurl_id($next_id);
			if ($thing)
			{
				$thing = parse($thing);
				return '<a rel="next" href="'.$url.'"'.
					($next_title != $thing ? ' title="'.$next_title.'"' : '').
					'>'.$thing.'</a>';
			}
			return $url;
		}
		return ($showalways) ? parse($thing) : '';
	}

I tried to change the return '<a rel="next" href="'.$url.'"'. to return '<a rel="next" href="#'.$next_id.'"'. to output to an “anchored #id” but nothing happend. Can anybody please point me in the right direction here? I dont know much about php… :)

Last edited by joel (2007-04-06 21:25:04)

Offline

#3 2007-04-07 12:20:34

joel
Member
Registered: 2004-11-26
Posts: 162

Re: Creating prev/next anchor links for navigation

Sorry for the bump – I know it’s easter and all but I’m quite desperat over here… I could really use some help :)

Thanx in advance!

Last edited by joel (2007-04-07 12:34:30)

Offline

#4 2007-04-07 12:59:41

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Creating prev/next anchor links for navigation

Try not to modify the core – just use <txp:php>echo 'hello world';</txp:php> tags. Check out the global variables reference. You’ll want ['pretext']['next_id'] and ['pretext']['prev_id']. Ignore the next and previous titles and use ID’s in your form to simplify. Here’s a starting point:

<h3 id="article_<txp:article_id />">
	<txp:title />
</h3>

<txp:body />

<p>
	<txp:php>	
		echo '<a href="#article_'.$GLOBALS['pretext']['prev_id'].'">Previous</a> | <a href="#article_'.$GLOBALS['pretext']['next_id'].'">Next</a>';
	</txp:php>
</p>

Last edited by jm (2007-04-07 13:02:12)

Offline

#5 2007-04-07 15:32:32

joel
Member
Registered: 2004-11-26
Posts: 162

Re: Creating prev/next anchor links for navigation

Thanks for the tips jm!

The reason why I need the next/prev-ID’s is that each article shall lead to the next one. Everything will be displayed in article-list-mode.

Offline

#6 2007-04-07 15:51:13

joel
Member
Registered: 2004-11-26
Posts: 162

Re: Creating prev/next anchor links for navigation

Unfortunately the code above only outputs the given html. Not the variables.

<p><a href="#article_">Previous</a> | <a href="#article_">Next</a></p>

I need it to be something like:

<p><a href="#article_prev_title_or_id">Previous</a> | <a href="#article_next_title_or_id">Next</a></p>

Is this possible?

Thanks again! :)

Offline

#7 2007-04-07 17:39:42

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Creating prev/next anchor links for navigation

I think the ‘prev/next_id’ variables are not defined in an article list, so perhaps this works (not tested):

<txp:php>
  global $thisarticle, $s;
  $Posted = safe_field('Posted', 'textpattern', 'ID='.$thisarticle['thisid']);
  $pn = getNextPrev($thisarticle['thisid'] , $Posted, $s);
  if ($pn['prev_id']) echo '<a href="#article_'.$pn['prev_id'].'">Previous</a>';
  if ($pn['prev_id'] and $pn['next_id']) echo ' | ';
  if ($pn['next_id']) echo '<a href="#article_'.$pn['next_id'].'">Next</a>';
</txp:php>

However, this won’t work when the article list spans multiple pages, because the first prev link and the last next link would then point to articles on a different page.

Last edited by ruud (2007-04-07 17:42:21)

Offline

#8 2007-04-07 18:09:52

joel
Member
Registered: 2004-11-26
Posts: 162

Re: Creating prev/next anchor links for navigation

ruud wrote:

I think the ‘prev/next_id’ variables are not defined in an article list, so perhaps this works (not tested):

<txp:php>
  global $thisarticle, $s;
  $Posted = safe_field('Posted', 'textpattern', 'ID='.$thisarticle['thisid']);
  $pn = getNextPrev($thisarticle['thisid'] , $Posted, $s);
  if ($pn['prev_id']) echo '<a href="#article_'.$pn['prev_id'].'">Previous</a>';
  if ($pn['prev_id'] and $pn['next_id']) echo ' | ';
  if ($pn['next_id']) echo '<a href="#article_'.$pn['next_id'].'">Next</a>';
</txp:php>

However, this won’t work when the article list spans multiple pages, because the first prev link and the last next link would then point to articles on a different page.

Thanks ruud! This really made the job!!!

Multiple pages is not a problem since I will display all the articles on one list-page.

Once again, many many thanks! :)

Last edited by joel (2007-04-07 18:10:11)

Offline

Board footer

Powered by FluxBB