10 more custom fields please
IMPORTANT!!! IMPORTANT!!! IMPORTANT!!!
*This hack is available as a plugin now glz_custom_fields*
IMPORTANT!!! IMPORTANT!!! IMPORTANT!!!
Katie was asking the other day about adding more custom fields to TXP. I have written something on the subject a while back, but I realized that I haven’t posted anything on my blog. Well Katie (and others interested in the same thing), here it goes:
The whole process consists of 2 stages:
1. TXP hacks
- modify
include/txp_article.phparound line 16 - modify
include/txp_article.phparound line 86 - modify
include/txp_article.phparound line 186 - modify
include/txp_article.phparound line 400 - modify
publish.phparound line 915 - for your sake, all the above mods in a single .txt file: txp_10_more_custom_pls_txp.txt (6.36KB)
2. DB mods
- add some extra columns (
custom_11,custom_12etc.) to thetextpatterntable - add some extra rows (
custom_11,custom_12etc.) to thetxp_prefs table - add some extra rows (
Custom field 11 name,Custom field 12 nameetc.) to thetxp_lang table - all the above mods in a single .txt file: txp_10_more_custom_pls_db.txt (3.78KB)
As an extra, just in case txp_lang becomes inaccessible (db errors, connection problems etc.) – never happened to me -, you can add the following lines to en-gb.txt (your language file):
custom_11_set => Custom field 11 name custom_12_set => Custom field 12 name custom_13_set => Custom field 13 name custom_14_set => Custom field 14 name custom_15_set => Custom field 15 name custom_16_set => Custom field 16 name custom_17_set => Custom field 17 name custom_18_set => Custom field 18 name custom_19_set => Custom field 19 name custom_20_set => Custom field 20 name
There are various other enhancements that could make life with TXP sweeter, but I am not too keen on highways (grin).
If you need some more extensive TXP hacks/mods or would like to hear about the various plugins that I have used on different projects (property websites, online shops etc.), by all means, drop me a line. I am a decent guy and people tend to like working with me. No, really now.
Please note that all the above mods might not suit your TXP installation (depending on version, localisation etc.). There is little chance for something to go wrong, but if it does, don’t come crying. Cheers ; ).
You have really blown me away with your tutorial! I can’t thank you enough for explaining how to add the custom fields in such an easy to follow manner- you have certainly saved me several hours of coding!
Thank you again for all of your hard work and taking the time to write out the steps to accomplish this. The Textpattern community is lucky to have such a wonderful person like you to help out those of us who are new to the CMS.
Happy Holidays and thanks again!
— Katie Dixon Dec 29, 03:32 PM #
You are very welcome Katie ; ). Always happy to support this wonderful, TXP community.
After all those compliments, I am red as a lobster blush.
All best!
— Gerhard Jan 5, 12:03 AM #
After a couple of e-mails with Katie I came to admit that the hack I originally released wasn’t 100%. Made the right changes so now everything should work fine.
Thanks Katie!
— Gerhard Jan 5, 02:58 AM #
Thanks for this info- I’m starting to build a site, and would like to have a few more custom fields. Where do I go exactly to make the DB Mods? Is it a file? They look like MySQL commands, but I’m basically a stranger to MySQL and was wondering what I needed to do to make those changes to the tables in step 2. Any help is appreciated. Thanks.
— Jeremy Jul 27, 07:20 AM #
Hi Jeremy,
all you need to do is download and install rss_admin_db_manager plugin and then just copy and paste the commands you have in that txt file into extensions > run sql.
Let me know how it works out ; ).
— Gerhard Jul 27, 08:40 AM #
Gerhard,
i can’t thank you enough for this tutorial.
While i try implementing this in 4.0.4 now i want to ask: Adding extra ten rows in DB in txp_pref and txp_lang tables: is that still okay? both of these tables appear to have no entries whatsoever for custom fields 1-10.
Many thanx in advance, and yes: i want to implement a shop into this. That’s why.
jayrope (j.siegele/berlin)
— jayrope (J. Siegele) Oct 27, 12:26 AM #
correction: it all works perfectly okay in 4.0.4.
and, as an example, replaces all entries “en-us” with “en-gb” or “de-de” etc.adding to the above it should be mentioned, that other languages than en-us need additional query (per language) in DB txp_lang aswell to show up right in the Admin tab.
To achieve this one simply copies the last block of your txp_10_more_custom_pls_db.txt
Entries for other than english localisations also need replacement of entries “Custom field 11 name” all thru “Custom field 12 name” with “Name des benutzerdefinierten Feldes Nr. 11” all thru “Name des benutzerdefinierten Feldes Nr. 20” (for “de-de”).
Etc.
Proper entries for installed languages can be found by searching DB txp_lang using the string “custom_”.
EOF.
Thanx again!
— jayrope (J. Siegele) Oct 27, 03:08 AM #
For TXP 4.0.4, I had to add the variable ‘second’ to the $vars array in @include/txp_article.php (step 1/4 of the TXP changes). Otherwise textpattern was throwing date errors when updating a previously published article.
— pyrophone (Jon Swift) Dec 5, 08:08 PM #
Just for the sake of someone else who will likely do the same thing I did, it should be noted that the DB mods to the textpattern table WILL NOT run in
rss_admin_db_manager. That plugin doesn’t support the ‘alter’ statement, so you’ll have to go in to your SQL manually and run the statement there. The other INSERT statements execute fine inrss_admin_db_manager.— Mike Apr 4, 05:29 PM #
Mike, cheers for your input mate ; ).
— Gerhard Lazu Apr 7, 07:31 PM #
Can anybody help with converting custom_field to textarea?
— Jirka May 11, 10:03 PM #
Jirka, just e-mailed you mate.
— Gerhard Lazu May 11, 10:06 PM #
Hi, does this work ‘out of the box’ with Textpattern 4.0.5? I’m can’t find the variable in publish.php to change – although changing it to what I THINK it should be, still doesn’t work… I’m getting “Unknown variable…” in txp_article.php for the new custom fields. Any suggestions appreciated!
— Andy Jul 9, 11:40 AM #
I found solution
— Jirka Jul 23, 11:52 PM #
Yes guys, Jirka is right, I have no idea why that strtolower() made it in the 4.0.5. I suppose there is a good reason for it…
— Gerhard Lazu Jul 24, 08:28 PM #
Using MAMP with PHPMyAdmin I had to change the field ‘Null’ from No to Yes for ‘val’ in the txp_prefs table. Otherwise it would not have accepted the 2nd DB mod.
— Ellen Sep 15, 10:29 PM #
If someone have troubles trying to find the line 915 in publish.php, just search for function getCustomFields()
and change i=<10 for i=<20 and you’re done! ;-)
— Alex Dukal Dec 17, 06:41 AM #
Just for the records:
I´ve had the same problem with the second DB modification and PHPMyAdmin (or rss_admin_db_manager).
I had to change the field NULL to “NOT NULL” to make it work (Textpattern 4.0.5).
And, since i´m working on a multilingual site i´ve used the language tip that jayrope posted below.
Thx for the hack, very useful indeed!
— Dario Jan 29, 06:54 PM #
Thank you a lot!
I was just doing something and realized that I lacked few custom fields. :D
This will defiantly do the trick.
— Nemanja Cosovic Apr 13, 12:49 PM #