Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-08-27 17:21:41

atrox
Member
From: London, UK
Registered: 2004-07-20
Posts: 12
Website

Custom field as an article_custom attribute for keywords [Hack]

Hi,

After the need of ability to control other elements on the page from within the article became clear to me and some other people. I decided to write a plugin which would be able to do it for me. After going through the source code of TXP I thought that the best option for me would be to use existing article_custom with new added functionality. Therefore I made a hack because I don’t know how to add functionality to existing functions and including the whole original code for the sake of 5 lines didn’t seem logical to me. If someone knows how to convert it to a plugin, please tell me, I would be very happy to do so.

What does it do?

Say, I need to display certain articles in the side column when the article is displayed. My way of doing it is creating the articles I want to display and giving them keywords. Then, when I want to display a particular article in the side column I create a custom field called ‘Sidebar’ and type in the keywords which are associated with the articles I want to display.

For example: I have an ‘About’ page and want to display my photo, my contact details and contact form in the side bar. I create those articles with photo, contact form and details and assign a keyword to each one of them: ‘my_photo’, ‘my_contacts’, ‘contact_form’. Now, in about page I add to the Sidebar custom field: ‘my_photo, my_contacts, contact_form’ and they will be displayed in the side bar (or anywhere else where you specify in form). If you don’t specify any keywords in your custom field, keyword ‘nothing’ will be assigned to it to prevent from showing all articles.

How to use it?

Very simple: <code><txp:article_custom form=“formname” customfield=“customfieldname” /></code>
In article you want to display your additional articles just type in the keywords separated by commas in the custom field you’ve chosen.

Installation.

Go to /textpattern/publish.php and find function called doArticles. Add $thisarticle to globals, add:

<code>‘customfield’ => ‘’, // new attribute</code> to the list of attributes and right after the list, before // if an article ID is specified… comment:

<pre><code> // custom field controls keywords $cf = $theAtts[‘customfield’]; // assign customfield attribute to $cf $cfname = $thisarticle[$cf]; // get the name of the custom field $kw = (!$cfname) ? nothing : $cfname; // get keywords from custom field, if nothing is there ‘nothing’ is set as a keyword $theAtts[‘keywords’] = $kw; // show the keywords
</code></pre>

That’s it! Tell me your thoughts on this. I’m not a programmer, I’m sure it could be done in a more elegant way but I needed this functionality and I couldn’t find anything similar on the forums.

Offline

#2 2005-08-27 18:15:25

kemie
Plugin Author
From: mexico<-->sweden
Registered: 2004-05-20
Posts: 495
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

strox, this sounds like what i need, ill install asap and test


~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~

Offline

#3 2005-08-27 18:31:36

kemie
Plugin Author
From: mexico<-->sweden
Registered: 2004-05-20
Posts: 495
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

hm, im not sure this is the solution for me if i understand correctly. In some sections of my site, i use article_custom for the main article, this would only work if i had txp:article for the main one and article_custom for the keyword-defined list, right?


~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~

Offline

#4 2005-08-27 18:49:45

atrox
Member
From: London, UK
Registered: 2004-07-20
Posts: 12
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

Hmm… You’re right. I posted it too early. I will need to do some more testing. Maybe the best way is indeed to create a separate tag for keywords.

Last edited by atrox (2005-08-27 18:50:18)

Offline

#5 2005-08-27 19:14:19

atrox
Member
From: London, UK
Registered: 2004-07-20
Posts: 12
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

Ok, Here’s a very rough version of plugin. Basically, I just copied article_custom, renamed it and hacked. This shouldn’t have any problems with article_custom as it is unrelated to it now. At least it seems to work on my site.

Offline

#6 2005-08-27 20:49:38

kemie
Plugin Author
From: mexico<-->sweden
Registered: 2004-05-20
Posts: 495
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

hey atrox! thanks for this!
will try :)


~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~

Offline

#7 2005-08-27 21:13:53

kemie
Plugin Author
From: mexico<-->sweden
Registered: 2004-05-20
Posts: 495
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

atrox, i could kiss you. it works perfectly:look!


~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~

Offline

#8 2005-08-27 21:21:29

atrox
Member
From: London, UK
Registered: 2004-07-20
Posts: 12
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

I’m glad you found it useful. I now need to rewrite the plugin to make it more compact and maybe add some features.
There is still one thing that I can’t figure out: when in section/category/title mode, category shows the list of articles and if I want to have a sticky article instead of the list, it will fetch the keywords for the last article from normal flow, rather than the sticky one. Somehow, I need to make keywords plugin status aware.

Offline

#9 2005-08-28 02:56:28

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

Atrox,

Is this section aware?
If it isn’t could it be?


Offline

#10 2005-08-28 03:00:53

atrox
Member
From: London, UK
Registered: 2004-07-20
Posts: 12
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

As it is pretty much the copy of article_custom, yes, it is section aware.

Offline

#11 2005-08-28 03:05:44

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Custom field as an article_custom attribute for keywords [Hack]

atrox: I believe when they’re asking is it section-aware, they’re asking if it behaves like article, not article_custom.

Offline

#12 2005-08-28 03:13:57

atrox
Member
From: London, UK
Registered: 2004-07-20
Posts: 12
Website

Re: Custom field as an article_custom attribute for keywords [Hack]

> atrox: I believe when they’re asking is it section-aware, they’re asking if it behaves like article, not article_custom.

mary: I only ever needed article_custom functionality to this plugin and don’t really see the point of it behaving like article plugin as most of the time I need to display multiple articles in my side bar as well as single articles, excerpts, body texts, sort them, filter by section, category and everything else that article_custom does. It is a copy of article_custom with added functionality. Why would we need article instead of article_custom?

Offline

Board footer

Powered by FluxBB