Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-24 21:00:56

alannie
Member
From: Minnesota, USA
Registered: 2005-09-15
Posts: 150

How to use the if_custom_field for custom page titles

Hello, I’ve set up a custom field called “page-title” in Textpattern, so that writers can put in custom page titles in the Advanced Options of each article. If no title is entered, the article page instead displays the default TXP page title. It took some figuring out, and I thought I’d share my solution with others who have this same need.

Edit: the below tag example uses multiple instances of txp:article, which can cause duplicate comment forms and other unexpected behavior (such as duplicate error messages with zem_contact_reborn). If anybody knows of any alternatives to using txp:article, please let me know.

Edit 2: tried using txp:chh_article_custom in place of txp:article. Didn’t work.

First, something to be aware of is that I’ve set up my site as a regular corporate website rather than as a blog. I’m using “sticky” articles to display content on the index page of each section.

To start, I set up a custom field in the Admin preference called “page-title”. This field now shows up under Advanced Options in the Write tab.

Next, I set up an article form named “custom-title” with the following content:

<txp:if_custom_field name="page-title">
<txp:custom_field name="page-title" />
<txp:else />
<txp:page_title />
</txp:if_custom_field>

Then in my page template, in the head, I put in:

<title>
<txp:if_article_list>
<txp:article form="custom-title" status="sticky" />
<txp:else />
<txp:article form="custom-title" />
</txp:if_article_list>
</title>

A similar approach can be used for meta page descriptions.

I’m sure this is not an original solution, but my searches in the forums or manual didn’t turn up exactly what I needed. Hope others find this helpful.

Last edited by alannie (2007-06-11 02:08:48)

Offline

#2 2007-06-10 15:41:30

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

Re: How to use the if_custom_field for custom page titles

alannie, thanks for your contribution. I have a similar case where I want to style parts of the headline, and then the problem arises how to hide these ugly xhtml tags showing up in the window titles.

Referring to your two edits: have you tried to use only the upper code in the head and embrace it with <title> and </title>. For my site it worked.

May I add something to your solution? For these cases where the custom field’s name is applied there’s the site name missing from the window title. You can easily add it by prefixing the custom field tag with <txp:sitename />: (don’t forget the blank space at the end of the string to create titles that are identical to those txp:title outputs).

I needed some time to get your approach running because I didn’t perceive that there were curly quotes in your code example. (Textile changed them because you used bq. for your code instead of bc.) Would you please change the different characters for future readers? Thanks.

Last edited by uli (2007-06-11 00:11:02)


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

Offline

#3 2007-06-11 02:15:12

alannie
Member
From: Minnesota, USA
Registered: 2005-09-15
Posts: 150

Re: How to use the if_custom_field for custom page titles

uli, thanks for the comment! I will try out your suggested edits soon (this was a old post for a previous version of Textpattern and I haven’t had the chance to try it out with the latest version yet).

I also updated the code formatting per your suggestion, now that this forum no longer automatically renders HTML and has added Textile support for code (yay!).

Offline

#4 2007-06-15 16:22:35

alannie
Member
From: Minnesota, USA
Registered: 2005-09-15
Posts: 150

Re: How to use the if_custom_field for custom page titles

uli wrote:

Referring to your two edits: have you tried to use only the upper code in the head and embrace it with <title> and </title>. For my site it worked.

I tried what you suggested and, as I suspected, it produced this error:

tag_error <txp:if_custom_field name="page-title"> ->  
Textpattern Notice: Article tags cannot be used outside an article context  on line 1821

I am wondering exactly where you have your title appearing, mine is in the head of my document where I don’t have article tags.

Offline

#5 2007-06-15 18:36:02

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

Re: How to use the if_custom_field for custom page titles

Sure, this isn’t kosher, but it should work, though (at least in the window title), did it? Watch whether it causes other functionality on your site to stop working (Under certain conditions I sometimes met some deactivated links when txp put up error notes in testing mode). If everything’s fine, I’d set production mode to “live”.

Alright, looked through your code again, must have been missing something the first time:
I don’t understand why you see a need for “sticky” which lead you to using txp:article in the head. Doesn’t make sense for me, there. Have you tried txp:output_form (type misc.) instead of txp:article? If you really need to check “sticky”: couldn’t txp:if_status help?


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

Offline

#6 2007-06-15 19:35:21

alannie
Member
From: Minnesota, USA
Registered: 2005-09-15
Posts: 150

Re: How to use the if_custom_field for custom page titles

Actually, I discovered it works only on individual article pages. On article-list pages, it produces the aforementioned error. I need custom page titles on both individual article and article-list pages. I am using “sticky” articles to insert content on the article-list pages, as mentioned in my original post:

First, something to be aware of is that I’ve set up my site as a regular corporate website rather than as a blog. I’m using “sticky” articles to display content on the index page of each section.

Offline

#7 2007-06-15 21:03:33

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

Re: How to use the if_custom_field for custom page titles

I am using “sticky” articles to insert content on the article-list pages, as mentioned in my original post

Yup, I’m with you, but why in between the title tags?

Before releasing an avalanche, the simpleast way is maybe answering yourself these questions:
If the error message occurs: is the correct window title output? If so: are the other page elements working correctly? If so: set the production status to live. –> Done, everything’s working fine. The noises you read in production mode will go away in live mode and won’t destroy neither txp’s pistons, nor it’s valves nor harm it’s gearbox soul.

If one of the answers is no, well, then on to the avalanche: I need to know a little bit better about what you want to achieve in which situations, as I’m a little confused about some points (you didn’t answer the questions I asked in #5, plus furthermore):

I am wondering exactly where you have your title appearing, mine is in the head of my document where I don’t have article tags.

This contradicts the following:

<title>
<txp:if_article_list>
<txp:article form=“custom-title” status=“sticky” />
[ … ]

If this is consistent, though, then I don’t have enough information about the state of your page template at the moment. So could you please post the current page plus what you want to achieve in which situation.

Last edited by uli (2007-06-15 21:12:14)


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

Offline

#8 2007-06-20 23:55:57

hhriebe
New Member
From: West Vancouver, BC, Canada
Registered: 2007-06-20
Posts: 8

Re: How to use the if_custom_field for custom page titles

This works fine for me. When I first tried this (before seeing this thread), I received the same error as Alannie because I was trying to use the article tag between the title tags – this went away when I added the form as in the original suggestion.

Another tip: add limit=“1” to the article tag just in case you do have a sticky page with multiple articles, otherwise all their titles end up in the page title! And if you’re using multiple articles, you need to choose which one you want the title from: e.g. use the same sort order as in the content.

Offline

#9 2007-07-16 21:18:34

alannie
Member
From: Minnesota, USA
Registered: 2005-09-15
Posts: 150

Re: How to use the if_custom_field for custom page titles

uli, let me clarify. This is the code I tried out as per your suggestion:

<title> 
	<txp:if_custom_field name="window-title">
		<txp:custom_field name="window-title" />
		<txp:else />
		<txp:page_title />
	</txp:if_custom_field>
</title> 

This works fine for individual article pages. But, for article-list pages, I just get the default page title. It does not pull the custom title from the “sticky” article pages I have designated in each section.

Offline

#10 2007-07-20 13:27:15

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

Re: How to use the if_custom_field for custom page titles

alannie, I think wrapping the if_custom_field tags in if_individual_article tags could work. You live you learn ;)

If not: have you tried (or: is it possible) to filter with the same criteria in the head portion of the page as you do in the body in order to select only the sticky article? I mean, on those pages where the sticky article is displayed you’re filtering per conditionals and/or per attributes of the txp:article tag in order to display just the sticky article. Couldn’t you apply these filters in the head portion of the page, but instead of the article tag you use output_form (type misc) to avoid the article tag in the head?
I’ve recently read that the if_status tag I mentioned above is something completely different, but maybe you can apply a unique category to the sticky article and filter out this category with if_individual_article plus if_article_category.

BTW.: In Textpattern Solutions (on p. 365 in case you have it) I’ve read a section about pref settings on comments, that could be important for your troubles with comment form duplications: Have you set the preference setting “Automatically append comments to articles” to “yes” when the duplication happened? I think “no” might stop your problems.


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

Offline

#11 2007-07-25 18:53:21

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

Re: How to use the if_custom_field for custom page titles

alannie, could this here help you? Filters for article status.


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

Offline

Board footer

Powered by FluxBB