Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-09-21 10:07:37

whaleen
Member
From: Portland
Registered: 2006-05-11
Posts: 373
Website

Forcing the Article ID in the URL-only title field

I’m looking to do just that upon the publish action for a new article.

I need to force the Article ID in the URL-only title field. Or something along these lines.

Reason being: I have articles being created which have no title. I have no need for them for certain types of articles. Therefore I’m left within an incomplete URL when I go to display an individual article.


txtstrap (Textpattern + Twitter Bootstrap + etc…)

Offline

#2 2009-09-21 11:52:53

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

Re: Forcing the Article ID in the URL-only title field

whaleen wrote:

Or something along these lines.

Is it an option to enter a title and assign the article to another form?


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

Offline

#3 2009-09-21 12:13:06

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

Re: Forcing the Article ID in the URL-only title field

Create a plugin that does something like this (which also fixes existing articles, setting url_title to the article ID if the url_title is empty). Not tested and of course the function name should be changed:

register_callback('prefixed_function_name', 'article', 'edit');

function prefixed_function_name()
{
  safe_update('textpattern', 'url_title = ID', "url_title=''");
}

However, if you use <txp:title />, that will show the article ID for articles that previously didn’t have a title.

Another way to solve this would be not to use the title in the article URL, but switch to an URL scheme that uses the article ID instead.

Offline

#4 2009-09-22 12:42:27

whaleen
Member
From: Portland
Registered: 2006-05-11
Posts: 373
Website

Re: Forcing the Article ID in the URL-only title field

uli wrote:

Is it an option to enter a title and assign the article to another form?

The idea was to skip the step of thinking of a title to enter and entering it when it has no meaning. There is no need for a title in my case but I was still wanting to use the title attribute in URL building.

Running something like this:

register_callback('prefixed_function_name', 'article', 'edit');

function prefixed_function_name()
{
  safe_update('textpattern', 'url_title = ID', "url_title=''");
}

after a frenzy of entering untitled articles would prep me for my existing URLs however:

Another way to solve this would be not to use the title in the article URL, but switch to an URL scheme that uses the article ID instead.

I’ve since my initial post started to learn more about screwing with URLs and bending their display and output and have a number of ideas I’m working through.

Thanks to you both for your help.


txtstrap (Textpattern + Twitter Bootstrap + etc…)

Offline

#5 2009-09-25 18:34:52

nabrown78
Member
From: Northampton, MA, USA
Registered: 2006-10-04
Posts: 294
Website

Re: Forcing the Article ID in the URL-only title field

Though you may have no reason for a title in the output – mightn’t it be nice to have titles when looking at your admin-side article list? Otherwise, if you want to select an article to edit, you’ll be choosing from a bunch of article id’s instead. Might be more convenient to have some titles, and just not output them.

Offline

#6 2009-09-26 03:48:45

whaleen
Member
From: Portland
Registered: 2006-05-11
Posts: 373
Website

Re: Forcing the Article ID in the URL-only title field

nabrown78 wrote:

Though you may have no reason for a title in the output – mightn’t it be nice to have titles when looking at your admin-side article list? Otherwise, if you want to select an article to edit, you’ll be choosing from a bunch of article id’s instead. Might be more convenient to have some titles, and just not output them.

A group of folks are entering several hunderd articles every monday. Titles just aren’t relevant becuase several of the custom fields are what makes the sorting criterea for the end user.

The reason I was considering loading something else dynamically into the title field was so that I could use the <txp:title /> tag to build URLs and other odds and ends. I’ve since learned how to build the URLS I need so it’s actually a resolved problem. The only last naggin aspect is having the warning saying that the URL title was left blank. This bothers our editors becuase they feel like something is broken.

People have mentioned custom data types in the forums here and as I continue to use the article context to do things that might not fall within that idea, I’m begining to understand what that might mean.

I’m gradually using Michael Manfre’s plugins to build custom input screens so that I can present the illusion to contributors and editors that custom data types are not all mashed together using the same article input write tab. As I do this, the articles tab itself will be used less becuase I’ll be using front end tags to show the site managers where the content they need to manage or add to is.

mightn’t it be nice to have titles when looking at your admin-side article list

We labored over this for a while and in the end determined that we couldn’t give meaningfull titles given the nature of the content. Posted, and Custom Field(s) are the only meaningful parts of these articles. Having to think about a title would triple the workload anyway and it would, again, have no meaning. :)

Last edited by whaleen (2009-09-26 03:52:40)


txtstrap (Textpattern + Twitter Bootstrap + etc…)

Offline

#7 2012-09-13 03:52:04

Teemu
Member
From: Shanghai
Registered: 2010-04-27
Posts: 60

Re: Forcing the Article ID in the URL-only title field

Reviving an old thread here.

I’m trying to achieve pretty much the same as op. When publishing the article I’d like the ‘Url-only title’ to be same as article ID.

Reason for this is that I’m doing a multilingual site with MLP and those automatically generater ascii url-only titles for Chinese just gets too long and some cases returns ‘nice try’ error in the front-end.

I’ve tried ruud’s solution above, generating a plugin with ied_plugin_composer, but somehow that code doesn’t seem to have any effect. Op had articles with no title, which it not the case here. So perhaps the code needs to be modified?

Any help would be appreciated.

Offline

#8 2012-09-13 05:03:55

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Forcing the Article ID in the URL-only title field

Teemu wrote:

Reason for this is that I’m doing a multilingual site with MLP and those automatically generater ascii url-only titles for Chinese just gets too long and some cases returns ‘nice try’ error in the front-end.

You can up the request URL limit in Advanced Preferences. By default it’s set as 200. Increasing it will not cause issues.

So perhaps the code needs to be modified?

Yep. For Textpattern 4.5.0 and newer you could try:

new abc_id_as_urltitle();

class abc_id_as_urltitle {

	/**
	 * Constructor
	 */

	public function __construct() {
		register_callback(array($this, 'update'), 'article_saved');
		register_callback(array($this, 'update'), 'article_posted');
	}

	/**
	 * Updates URL title
	 * @param string $event
	 * @param string $step
	 * @param array $r
	 */

	public function update($event, $step, $r) {
		safe_update('textpattern', 'url_title = ID', 'ID = '.intval($r['ID']));
	}
}

The above would hook to article saving process, and updates the edited article’s URL title. Requires Textpattern v4.5+. Requires that the plugin type is set as 4 (async).

Last edited by Gocom (2012-09-13 05:06:05)

Offline

#9 2012-09-13 05:43:57

Teemu
Member
From: Shanghai
Registered: 2010-04-27
Posts: 60

Re: Forcing the Article ID in the URL-only title field

Kiitti Jukka for prompt reply!

How about TXP 4.4.1? Would it be totally different block of code or just some small adjustments needed? I haven’t upgraded yet since there’s some issues with plugins that I use.

Last edited by Teemu (2012-09-13 08:19:29)

Offline

#10 2012-10-18 16:34:53

springworks
Member
Registered: 2005-01-06
Posts: 172
Website

Re: Forcing the Article ID in the URL-only title field

Gocom wrote:

Yep. For Textpattern 4.5.0 and newer you could try:

new abc_id_as_urltitle();

class abc_id_as_urltitle {

	/**
	 * Constructor
	 */

	public function __construct() {
		register_callback(array($this, 'update'), 'article_saved');
		register_callback(array($this, 'update'), 'article_posted');
	}

	/**
	 * Updates URL title
	 * @param string $event
	 * @param string $step
	 * @param array $r
	 */

	public function update($event, $step, $r) {
		safe_update('textpattern', 'url_title = ID', 'ID = '.intval($r['ID']));
	}
}

The above would hook to article saving process, and updates the edited article’s URL title. Requires Textpattern v4.5+. Requires that the plugin type is set as 4 (async).

Apologies for thread hijack, but I would like to be able to automatically set the URL title to a concatenation of the article Title and the contents of a custom field (respecting the admin preference for replacing spaces with hyphens or underscores).

How would I go about writing a plugin to do that for TXP 4.5.2?

Last edited by springworks (2012-10-18 16:35:32)

Offline

#11 2012-10-18 17:12:56

springworks
Member
Registered: 2005-01-06
Posts: 172
Website

Re: Forcing the Article ID in the URL-only title field

Actually, I’ve had a go and this seems to work OK for me:

new spr_custom_url_title();

class spr_custom_url_title {

	/**
	 * Constructor
	 */

	public function __construct() {
		register_callback(array($this, 'update'), 'article_saved');
		register_callback(array($this, 'update'), 'article_posted');
	}

	/**
	 * Updates URL title
	 * @param string $event
	 * @param string $step
	 * @param array $r
	 */

	public function update($event, $step, $r) {
		if (!($r['custom_4']==""))
			$new_url_title = stripSpace($r['custom_4'], 1)."-".$r['url_title'];
		else
			$new_url_title = $r['url_title'];
		safe_update('textpattern', "url_title = '$new_url_title'", 'ID = '.intval($r['ID']));
	}
}

I’d be grateful if you can spot any obvious issues with it and let me know.

Cheers

Offline

#12 2012-10-18 18:54:32

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

Re: Forcing the Article ID in the URL-only title field

springworks, because this is a kind of publication here and you’ve already thought of using a prefix, I reserved it for you.


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

Offline

Board footer

Powered by FluxBB