Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-04-06 19:12:31

beztak
Member
From: Czech Republic
Registered: 2005-07-21
Posts: 184
Website

How display article from another section but with URL from current sec

I know it sounds little bit wierd, but here is the thing I want. I have article in section “projects” like domain.com/projects/title-of-project
Now I would like to display this article in another section but in detail, so not in article list, but as individual article, eg.: domain.com/references/title-of-project

I know it is against rules, because txp looks for section and ID in url scheme section/title and that is why it throws 404 because this ID does not exist in this section.

In article listing for specific section is not problem to use txp functions to display articles from different section where article_custom is short for it:

<txp:php>
$rs = safe_rows_start('*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod', 'textpattern', '(section="projekty" AND custom_5="Ano") OR section="realizace-staveb" ORDER BY custom_4 desc');
if ($rs) {
  $articles = array();
  while($a = nextRow($rs)) {
    populateArticleData($a);
    global $thisarticle;
    $articles[] = parse_form('reference-vypis');
  }
  echo doWrap($articles, '', '');
}
</txp:php>

In page form for individual article I’ve got this:

<txp:if_individual_article>
<txp:php>
HERE I NEED HELP
</txp:php>
</txp:if_individual_article>

How to call article with actual url – url_title (which belongs to another section) and avoid 404? Does anybody know? Is it possible?

Last edited by beztak (2009-04-06 20:03:08)

Offline

#2 2009-04-06 20:12:13

beztak
Member
From: Czech Republic
Registered: 2005-07-21
Posts: 184
Website

Re: How display article from another section but with URL from current sec

I found an easy solution, now I can have one article in unlimited sections with clean URL. It’s absolutly awesome, I edited few lines in publish.php from this:

case 'section_title':
	if (empty($u2)) {
		$out['s'] = (ckEx('section',$u1)) ? $u1 : '';
		$is_404 = empty($out['s']);
	}
	else {
		$rs = lookupByTitleSection($u2,$u1);
		$out['id'] = @$rs['ID'];
		$out['s'] = @$rs['Section'];
		$is_404 = (empty($out['s']) or empty($out['id']));
	}
break;

to this godlike code:

case 'section_title':
	if (empty($u2)) {
		$out['s'] = (ckEx('section',$u1)) ? $u1 : '';
		$is_404 = empty($out['s']);
	}
	else {
		$rs = lookupByTitleSection($u2,$u1);
		$out['id'] = @$rs['ID'];
		$out['s'] = @$rs['Section'];
		if (empty($out['id'])){
			$rs = lookupByTitle($u2);
			$out['id'] = @$rs['ID'];
			$out['s'] = ckEx('section', $u1);
		}
		$is_404 = (empty($out['s']) or empty($out['id']));
	}
break;

So if there is no ID in particular section start to lookup by title (url_title) and push up current section from URL. This works for url scheme section_title and of course if url_title is unique. Hope this will help to other people. It also works with MLP ;)

Last edited by beztak (2009-04-06 20:18:24)

Offline

#3 2009-04-06 20:43:52

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: How display article from another section but with URL from current sec

now I can have one article in unlimited sections with clean URL

Interesting.
Would like to read why you needed this feature.
Now that there is rel="canonical" there isn’t too much worry about duplicated content on the same site, but why would you want to have your content not just twice but “unlimited times” in different sections?

It could be fine for having many “related” contents in just one article, divided by if_section tags. not too hard for clients to learn…


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2009-04-06 21:04:42

beztak
Member
From: Czech Republic
Registered: 2005-07-21
Posts: 184
Website

Re: How display article from another section but with URL from current sec

maniqui wrote:

Interesting.
Would like to read why you needed this feature.
Now that there is rel="canonical" there isn’t too much worry about duplicated content on the same site, but why would you want to have your content not just twice but “unlimited times” in different sections?

In fact I need to show one article only in two sections (but changed code can push article in unlimited section just according to URL) because meaing of article is the same – two sections are “projects” and “realization”. Client can only do some project but this can be realized or not. So one article can belongs in two logical sections. Plus if they built something they didn’t projected this can be pushed only to section “realization”. Thanks custom_field I told system if “project” was also realized, if yes display it on “realization” section too.

This can be very helpful on every page with client references – e.g. webdesigners portfolio – one reference can be displayed in graphics, e-shop, xhtml coding.

Offline

Board footer

Powered by FluxBB