Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-07-31 22:17:50

gesiwuj
Member
Registered: 2008-07-01
Posts: 20

Show excerpt of "next" page & conditional for oldest/newest article

Sorry if this has been answered before, but I have searched the forums for 10 minutes and not found a solution.

Basically, it’s simple enough to use the <txp:next_title /> (or of course <txp:previous_title />) tag to show the title of the next article (or of the previous article). Is there a similar way to show the excerpt of the previous and next article?

Secondly, I understand that if_first_article and if_last_article don’t actually show the first and latest article in a given section but only the first and last in the list. Is there a way to check if the article is either the first or the latest?

The above two features are for a section at the bottom of individual post pages which have links to the previous and next article (with title & excerpt) but it would show a message if the current article is the oldest or the newest (eg: it’d say, “This is the newest article. Check back soon because we update frequently, and be sure to check out the archives too”). It would also have a similar message for the oldest of course.

Thankyou in advance for your responses!

Last edited by gesiwuj (2008-07-31 23:06:05)

Offline

#2 2008-07-31 23:55:01

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Show excerpt of "next" page & conditional for oldest/newest article

It is easily done with a brief plugin and a simple hack of publish.php. The problem I see is that articles, by design, all have titles, but not all articles have excerpts; the links are still there if any text is added by default whether there is a link or not but nothing else when no excerpt is used.

This is for linking previous and next excerpts in the place of titles.

Last edited by rsilletti (2008-07-31 23:56:41)

Offline

#3 2008-08-01 00:16:53

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Show excerpt of "next" page & conditional for oldest/newest article

It is easily done with a brief plugin and a simple hack of publish.php.

Iff ffat am … *wipe off drool* … is that an announcement? If so, could I simply change it to show custom fields? :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2008-08-01 00:40:31

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Show excerpt of "next" page & conditional for oldest/newest article

Rick, sorry: There’s jmd_neighbor. And it were more sorting criteria I was after, not the cf’s. I’ll go to sleep now ;)

gesiwuj, try it out.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2008-08-01 00:54:26

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Show excerpt of "next" page & conditional for oldest/newest article

The patch is untested and speculative – it works for me, at least on the surface. The tags that follow it are reliable enough, but if there is a good plugin out there I would certainly use that instead. (custom fields? :)

**************************
Index: /Library/Apache2/htdocs/adev/textpattern/publish.php
===================================================================
--- /Library/Apache2/htdocs/adev/textpattern/publish.php	(revision 2958)
+++ /Library/Apache2/htdocs/adev/textpattern/publish.php	(working copy)
@@ -911,7 +911,7 @@
 		$type = ($type == '>') ? '>' : '<';
 		$safe_name = safe_pfx('textpattern');
 		$q = array(
-			"select ID, Title, url_title, unix_timestamp(Posted) as uposted
+			"select ID, Title, Excerpt, url_title, unix_timestamp(Posted) as uposted
 			from ".$safe_name." where Posted $type '".doSlash($Posted)."'",
 			($s!='' && $s!='default') ? "and Section = '".doSlash($s)."'" : filterFrontPage(),
 			'and Status=4 and Posted < now() order by Posted',
@@ -937,6 +937,7 @@
 		$out['next_title']  = ($thenext) ? $thenext['Title'] : '';
 		$out['next_utitle'] = ($thenext) ? $thenext['url_title'] : '';
 		$out['next_posted'] = ($thenext) ? $thenext['uposted'] : '';
+		$out['next_excerpt']= ($thenext) ? $thenext['Excerpt'] : '';

 		$theprev            = getNeighbour($Posted,$s,'<');
 		$out['prev_id']     = ($theprev) ? $theprev['ID'] : '';
@@ -943,6 +944,7 @@
 		$out['prev_title']  = ($theprev) ? $theprev['Title'] : '';
 		$out['prev_utitle'] = ($theprev) ? $theprev['url_title'] : '';
 		$out['prev_posted'] = ($theprev) ? $theprev['uposted'] : '';
+		$out['prev_excerpt']= ($theprev) ? $theprev['Excerpt'] : '';

 		if ($theprev) {
 			$cache[$theprev['ID']] = $theprev;
*****************************


// link to next article, if it exists

	function ras_link_to_next($atts, $thing = NULL)
	{
		global $id, $next_id, $next_excerpt;

		extract(lAtts(array(
			'showalways' => 0,
		), $atts));

		if (intval($id) == 0)
		{
			global $thisarticle, $s;

			assert_article();

			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_excerpt != $thing ? ' title="'.$next_excerpt.'"' : '').
					'>'.$thing.'</a>';
			}

			return $url;
		}

		return ($showalways) ? parse($thing) : '';
	}

// -------------------------------------------------------------
// link to previous article, if it exists

	function ras_link_to_prev($atts, $thing = NULL)
	{
		global $id, $prev_id, $prev_excerpt;

		extract(lAtts(array(
			'showalways' => 0,
		), $atts));

		if (intval($id) == 0)
		{
			global $thisarticle, $s;

			assert_article();

			extract(getNextPrev(
				$thisarticle['thisid'],
				@strftime('%Y-%m-%d %H:%M:%S', $thisarticle['posted']),
				@$s
			));
		}

		if ($prev_id)
		{
			$url = permlinkurl_id($prev_id);

			if ($thing)
			{
				$thing = parse($thing);

				return '<a rel="prev" href="'.$url.'"'.
					($prev_excerpt != $thing ? ' title="'.$prev_excerpt.'"' : '').
					'>'.$thing.'</a>';
			}

			return $url;
		}

		return ($showalways) ? parse($thing) : '';
	}

// -------------------------------------------------------------

	function next_excerpt()
	{
		return $GLOBALS['next_excerpt'];
	}

// -------------------------------------------------------------

	function prev_excerpt()
	{
		return $GLOBALS['prev_excerpt'];
	}

// -------------------------------------------------------------

Offline

#6 2008-08-01 01:38:37

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Show excerpt of "next" page & conditional for oldest/newest article

Given a brief look at jmd_neighbor it appears to draw content of type article (most anything you can use in an article form) from neighboring articles, which may be all you need. It doesn`t provide navigation linkage itself, but if you lay out your tags properly link_to_next and link_to_prev will do that for you.
All I`m doing with the patch is retrieving an Excerpt along with the rest of the values and cloning existing tags and tailoring them to look for that instead, not really a good development method but it may work for a specific case.

Offline

#7 2008-08-02 11:52:57

gesiwuj
Member
Registered: 2008-07-01
Posts: 20

Re: Show excerpt of "next" page & conditional for oldest/newest article

I’ll try that plugin. Don’t worry, I don’t need the excerpt to be a link (I have a title as a link anyway). So does anyone have a solution for the second problem at all?

Offline

#8 2008-08-02 12:17:28

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

Re: Show excerpt of "next" page & conditional for oldest/newest article

gesiwuj wrote:

So does anyone have a solution for the second problem at all?

I assume you are not sorting the articles by date posted? (since in that case if_first and if_last_article would actually give you the oldest and the latest article)

Offline

#9 2008-08-02 14:20:51

gesiwuj
Member
Registered: 2008-07-01
Posts: 20

Re: Show excerpt of "next" page & conditional for oldest/newest article

This is on an individual article’s page. At the bottom are three “boxes” – one with the previous article, one with current article stuff (just as a reference point) and one with the next article. When I use <txp:if_first_article> it always returns true even if I’m not on the first article. The same for <txp:if_last_article>

PS. jmd_neighbour is working perfectly for problem 1! Thankyou very much!

Last edited by gesiwuj (2008-08-02 14:21:29)

Offline

#10 2008-08-02 18:52:09

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

Re: Show excerpt of "next" page & conditional for oldest/newest article

gesiwuj wrote:

it always returns true even if I’m not on the first article.

I see. Yes of course it would do that. Did you have a look at smd_if?

Offline

Board footer

Powered by FluxBB