Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Set hash in the default section
Hi,
Is it possible to output links with an hash in the default section please?
<a href="<txp:site_url />#example">Example</a>
For some reason I end up with only the site url.
If it’s not possible then I will like to know please how can I set a redirect from the default section to another one name “home” ?
(in .htaccess)
Last edited by THE BLUE DRAGON (2012-08-08 12:21:46)
Offline
#2 2012-08-08 11:22:00
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,313
Re: Set hash in the default section
Apart from your example being invisible/empty, it should actually work. Do you have a second, visible, link wich really gives out the site_url, and you mistook the two as the first one is invisible?
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Set hash in the default section
uli wrote:
Apart from your example being invisible/empty, it should actually work. Do you have a second, visible, link wich really gives out the site_url, and you mistook the two as the first one is invisible?
Forgot to add a text to the link in the example above, fixed that, but the problem still remains.
Try copy paste it to your default section, take a look at the source code and you will see that the hash is gone from the link source attribute.
Offline
#4 2012-08-08 12:44:41
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,313
Re: Set hash in the default section
I’m getting http://localhost/txp441/#example
, like I expected to see.
Just to make sure this is not a verbal misunderstanding: you’d get http://localhost/txp441/
?
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Set hash in the default section
uli wrote:
I’m getting
http://localhost/txp441/#example
, like I expected to see.Just to make sure this is not a verbal misunderstanding: you’d get
http://localhost/txp441/
?
Yep, and I just found that it’s because I’m using “gbp_permanent_links” plugin, thanks for checking :)
Last edited by THE BLUE DRAGON (2012-08-08 13:53:38)
Offline
Re: Set hash in the default section
Is there a way that I can get a permanent links rule of only “section/id” and not “section/id/title” without using a plugin please?
That’s why I’m currently using “gbp_permanent_links” plugin.
Offline
Re: Set hash in the default section
THE BLUE DRAGON wrote:
Is there a way that I can get a permanent links rule of only “section/id” and not “section/id/title” without using a plugin please?
Currently as of Textpattern v4.4.1 and v4.5, the title part of the section/id/title
scheme is completely optional. This has a high change of changing in the future releases, but for now the unexpected behavior allows linking to articles using section/id
format.
In the page templates instead of using permlink tag to generate the article URLs, you could use tags such as article_id, section and site_url to crate title-less URLs. For instance:
<txp:site_url /><txp:section/>/<txp:article_id />
Textpattern also offers an PHP code path, a custom URL functionality, that allows changing the URLs the permlink tag generates. This could also be used to change the tags behavior which then would allow still using the tag and would even change the URLs present in RSS feeds and such.
As this behavior has the possibility of getting fixed, alternatively you could use section/title
scheme and set the URL title as the article’s ID. The URL title could be set manually, but it could also be done automatically when an article is saved.
Textpattern v4.5 (and the beta) offers a callback event named article_posted
meant specifically for these type of tasks. This event is fired each time an article is published, which makes it ideal spot for updating the URL title. For instance:
/**
* Hook function "abc_id_urltitle" to the callback event "article_posted"
*/
register_callback('abc_id_urltitle', 'article_posted');
/**
* Updates the URL title when article has been posted
* @param string $event Callback event
* @param string $step Callback step
* @param array $r Article's data as an array
*/
function abc_id_urltitle($event, $step, $r) {
safe_update(
'textpattern',
"url_title='".doSlash($r['ID'])."'",
"ID='".doSlash($r['ID'])."'"
);
}
Offline
Re: Set hash in the default section
You are awesome! :)
thanks a lot!
Offline
Pages: 1