Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2012-06-25 21:13:02
- Alweb
- Member
- Registered: 2010-10-08
- Posts: 25
Related articles: <txp:keywords />?
Hi forum,
While builiding a website I can’t solve a problem. I need a list with related articles which have the same keywords. If there is minimum 1 keyword that is the same as the current article, than the list with the related articles must be shown. The code that I used:
<txp:article_custom keywords="<txp:keywords />" limit="99">
<div class="post-excerpt">
<h1 class="title title-xsmall"><a href="<txp:permlink />"><txp:title/></a></h1>
<p>Lorem ipsum emphasised text dolor sit amet, strong text consectetur adipisicing elit...</p>
</div>
</txp:article_custom>
When I use <txp:keywords /> tag, than no articles are shown. If I replace that with a keyword, than it works. Hope someone can help me..
Thanks in advance :)
Offline
#2 2012-06-25 22:35:13
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Related articles: <txp:keywords />?
You should at least change that to single quotes:
<txp:article_custom keywords='<txp:keywords />' limit="99">
But I’m not sure if it will return something if the article has more than one keyword and only one of them matches other articles; never used it myself.
Offline
#3 2012-06-26 15:00:22
- Alweb
- Member
- Registered: 2010-10-08
- Posts: 25
Re: Related articles: <txp:keywords />?
Thank you Els, it worked…
What do you advise me to use? I found the <txp:related_articles> tag, but with this one you can’t get related articles with keywords.
Offline
#4 2012-06-26 17:25:32
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: Related articles: <txp:keywords />?
You might wish to exclude the current article from the article list. Have a look at how txp:if_article_id
is used for this purpose in example 2.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#5 2012-06-26 18:11:35
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Related articles: <txp:keywords />?
Alweb wrote:
What do you advise me to use? I found the <txp:related_articles> tag, but with this one you can’t get related articles with keywords.
If using the keywords tag doesn’t work good enough for you, you could have a look at one of the tagging plugins. I have been using tru_tags to do exactly this (the plugin uses the keywords field), and there is smd_tags.
Offline
#6 2012-06-27 13:52:25
- Alweb
- Member
- Registered: 2010-10-08
- Posts: 25
Re: Related articles: <txp:keywords />?
@uli: that’s also something that I searched.. :) But as I’m more a graphic webdesigner, less programmer, I’m not so good at programmig. Can you please tell me how I can implementate this in my code?
Offline
#7 2012-06-27 15:04:23
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: Related articles: <txp:keywords />?
I’d not name that programming, it’s simple if/else logic. You’ll quickly grasp it.
I’ve changed bit of your code where I found it made sense, you’ll still recognise it.
<txp:article_custom keywords='<txp:keywords />' limit="99" wraptag="div" class="post-excerpt">
<txp:if_article_id>
<txp:hide>Nothing to show here, cause it's the current article</txp:hide>
<txp:else />
<txp:hide>Code for the rest of your articles</txp:hide>
<h1 class="title title-xsmall">
<a href="<txp:permlink />"><txp:title/></a>
</h1>
<txp:excerpt />
</txp:if_article_id>
</txp:article_custom>
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#8 2012-08-13 13:50:50
- Alweb
- Member
- Registered: 2010-10-08
- Posts: 25
Re: Related articles: <txp:keywords />?
Thanks uli! :)
The entire code of this is as below. The next problem is that there are not everywhere related articles. How can I hide the “Related articles”-label, when there arn’t related articles?
<p class="widget-title">Related articles:</p>
<div class="divider"> </div>
<ul class="posts-list">
<txp:article_custom keywords='<txp:keywords />' limit="99">
<txp:if_article_id>
<txp:hide>Nothing to show here, cause it's the current article</txp:hide>
<txp:else />
<txp:hide>Code for the rest of your articles</txp:hide>
<h1 class="title title-xsmall">
<a href="<txp:permlink />"><txp:title/></a>
</h1>
<txp:excerpt />
</txp:if_article_id>
</txp:article_custom>
</ul>
Offline
Re: Related articles: <txp:keywords />?
Alweb wrote:
How can I hide the “Related articles”-label, when there arn’t related articles?
Your code does not look that it will produce valid xhtml as you will have a <ul>
without any <li>
insde it and you will have a number of <h1>
tags
try
<txp:variable name="ra" value=''<txp:article_custom keywords='<txp:keywords />' limit="99" />' ' />
<txp:if variable name="ra" value="">
<txp:else />
<p class="widget-title">Related articles:</p>
<div class="divider"> </div>
</txp:if variable>
<txp:article_custom keywords='<txp:keywords />' limit="99" class="posts-list" wraptag="div">
<txp:if_article_id>
<txp:else />
<h3 class="title title-xsmall"><a href="<txp:permlink />"><txp:title/></a></h3>
<txp:excerpt />
</txp:if_article_id>
</txp:article_custom>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#10 2012-08-13 15:05:33
- Alweb
- Member
- Registered: 2010-10-08
- Posts: 25
Re: Related articles: <txp:keywords />?
colak, the real code is with <li> inside, excuses for that. I will put the whole code below:
(I’m not very good at this, so I hope I don’t have to much errors in my code)
<txp:glx_if_frontpage>
<p class="title">Recent article </p>
<div class="divider"> </div>
<ul class="posts-list">
<txp:article limit="3">
<li class="secondary">
<article>
<div class="post-excerpt">
<h1 class="title title-xsmall"><a href="<txp:permlink />"><txp:title/></a></h1>
<txp:rss_auto_excerpt showlinkwithexcerpt="0" words="40" />
<span class="category"><a href="<txp:permlink />">(+) Read more...</a></span>
</div>
</article>
<div class="cleaner"> </div>
<div class="divider"> </div>
</il>
</txp:article>
</ul>
<txp:else />
<p class="widget-title">Related articles</p>
<div class="divider"> </div>
<ul class="posts-list">
<txp:article_custom keywords='<txp:keywords />' limit="99">
<txp:if_article_id>
<txp:else />
<li class="secondary">
<article>
<div class="post-excerpt">
<h1 class="title title-xsmall"><a href="<txp:permlink />"><txp:title/></a></h1>
<txp:rss_auto_excerpt showlinkwithexcerpt="0" words="40" />
<span class="category"><a href="<txp:permlink />">(+) Read more...</a></span>
</div>
</article>
<div class="cleaner"> </div>
<div class="divider"> </div>
</il>
</txp:if_article_id>
</txp:article_custom>
</ul>
</txp:glx_if_frontpage>
The way you told me with the “variable” didn’t work.
Offline
Re: Related articles: <txp:keywords />?
The code is still does not look right to me. Having said this, I am not very familiar with the validation of html5 which is obviously what you are using.
I would go this way:
...
<txp:variable name="ra" value='<txp:article_custom keywords=''<txp:keywords />'' limit="99" />' /> <txp:hide>Set a variable</txp:hide>
<txp:if_variable name="ra" value=""> <txp:hide>if there are no related articles display nothing</txp:hide>
<txp:else />
<p class="widget-title">Related articles:</p> <txp:hide>if there are related articles display title and the divider div</txp:hide>
<div class="divider"> </div>
</txp:if_variable>
<div class="posts-list"><txp:hide>I would change the ul to a div as I'm not cerain if divs can go in lis (see below)</txp:hide>
<txp:article_custom keywords='<txp:keywords />' limit="99">
<txp:if_article_id>
<txp:else />
<div class="secondary"> <txp:hide>I would change the li here to a div as I'm not cerain if divs can go in lis</txp:hide>
<article>
<div class="post-excerpt">
<h2 class="title title-xsmall"><a href="<txp:permlink />"><txp:title/></a></h2> <txp:hide>I am changing h1 to h2 here as you are only allowed one h1/page</txp:hide>
<txp:rss_auto_excerpt showlinkwithexcerpt="0" words="40" />
<span class="category"><a href="<txp:permlink />">(+) Read more...</a></span>
</div>
</article>
<div class="cleaner"> </div>
<div class="divider"> </div> <txp:hide>do you actually need 2 empty divs here?</txp:hide>
</div>
</txp:if_article_id>
</txp:article_custom>
</div>
...
> edited ithe code to uli’s suggestion
Last edited by colak (2012-08-16 05:58:07)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#12 2012-08-13 17:21:36
- Alweb
- Member
- Registered: 2010-10-08
- Posts: 25
Re: Related articles: <txp:keywords />?
colak, thnx, but the variable piece isn’t working…
Offline