Textpattern Forum

You are not logged in. Register | Login | Help

#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
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,388
Website

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.


<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields

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/Köln
Registered: 2006-08-15
Posts: 3,084

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
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,388
Website

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.


<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields

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/Köln
Registered: 2006-08-15
Posts: 3,084

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">&nbsp;</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

#9 2012-08-13 14:03:03

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,970
Website

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">&nbsp;</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.org | neme-imca.org | hblack.net | LABS

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">&nbsp;</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">&nbsp;</div>
         <div class="divider">&nbsp;</div>
           </il>
  </txp:article>
       </ul>
<txp:else />
       <p class="widget-title">Related articles</p>
       <div class="divider">&nbsp;</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">&nbsp;</div>
    <div class="divider">&nbsp;</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

Board footer

Powered by FluxBB