Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Get excerpt of sticky article
I am trying to a little SEO and set the meta description to the excerpts of articles. This works great for almost all of my web pages except for sections with sticky articles. I think I need a plugin for this. Does anyone know of a plugin that will get the excerpt of the sticky article outside of the article context, or one similar enough that I can hack? Right now the source looks something like:
<txp:else /><txp:if_search>
<meta name="description" content="search results">
<txp:else /><txp:if_category>
<meta name="description" content="listing of articles in category <txp:category title="1" />">
<txp:else /><txp:if_author>
<meta name="description" content="listing of articles by <txp:author />">
<txp:else /><txp:if_individual_article>
<meta name="description" content="<txp:excerpt />">
<txp:else /><txp:if_article_list>
<meta name="description" content="listing of articles in section <txp:section title="1" />">
<txp:else />
<meta name="description" content="oops...should never get here">
</txp:if_article_list>
</txp:if_individual_article>
</txp:if_author>
</txp:if_category>
</txp:if_search>
Sections with sticky articles end up using the if_article_list branch.
Offline
Re: Get excerpt of sticky article
You can get any article using the article_custom tag. For instance getting a sticky article from the current section is as simple as:
<txp:article_custom section='<txp:section />' status="sticky" limit="1">
<txp:excerpt />
</txp:article_custom>
Last edited by Gocom (2013-06-20 20:18:45)
Offline
Re: Get excerpt of sticky article
Sweet. Thanks, Jukka. Is there a way to see if there is a sticky article at all? That way I can use the list description if there isn’t a sticky article.
Last edited by skewray (2013-06-20 20:50:17)
Offline
#4 2013-06-20 20:57:54
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Get excerpt of sticky article
Yes, like this:
<txp:variable name="stickytester"><txp:article_custom section='<txp:section />' status="sticky" limit="1"><txp:excerpt /></txp:article_custom>
</txp:variable>
<txp:if_variable name="stickytester" value="">
<!-- Code for "false" results -->
<txp:else />
<txp:variable name="stickytester" />
</txp:if_variable>
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Get excerpt of sticky article
Thanks, Uli. That works. Sadly I have the sticky article for the landing page in the ‘articles’ section, so now ‘articles’ has the excerpt for the default section while the default section has none. I am getting closer, though.
Last edited by skewray (2013-06-21 01:56:22)
Offline
Re: Get excerpt of sticky article
Just in case anyone else wants to try this, here is what I got to work:
<txp:if_search>
<meta name="description" content="result of searching the <txp:site_name /> website for '<txp:search_term />'" >
<txp:else />
<txp:if_category>
<meta name="description" content="listing of articles at the <txp:site_name /> website in category <txp:category title="1" />" >
<txp:else />
<txp:if_author>
<meta name="description" content="listing of articles at the <txp:site_name /> website by <txp:author />">
<txp:else />
<txp:if_individual_article>
<meta name="description" content="<txp:excerpt />">
<txp:else />
<txp:if_section name="">
<txp:variable name="meta_excerpt"><txp:article_custom section="articles" status="sticky" limit="1"><txp:excerpt /></txp:article_custom></txp:variable>
<meta name="description" content='<txp:variable name="meta_excerpt" />' >
<txp:else />
<txp:if_section name="articles">
<meta name="description" content="listing of articles at the <txp:site_name /> website in section <txp:section title="1" />">
<txp:else />
<txp:variable name="meta_excerpt"><txp:article_custom section='<txp:section />' status="sticky" limit="1"><txp:excerpt /></txp:article_custom></txp:variable>
<txp:if_variable name="meta_excerpt" value="">
<meta name="description" content="listing of articles at the <txp:site_name /> website in section <txp:section title="1" />">
<txp:else />
<meta name="description" content='<txp:variable name="meta_excerpt" />' >
</txp:if_variable>
</txp:if_section>
</txp:if_section>
</txp:if_individual_article>
</txp:if_author>
</txp:if_category>
</txp:if_search>
Offline
Pages: 1