Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#371 2018-02-24 18:22:58

jpdupont
Member
From: Virton (BE)
Registered: 2004-10-01
Posts: 752
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

Is it possible to list the tags of articles belonging to a well-defined section?

With the functions of smd_tags, I do not see how.
With a smd_query?
I have below a query that displays all the tags and articles that are marked by this tag. Possible to modify it? Or to use the new functions of the 4.7 dev in order to display only non empty tags (without article)?

<ul>
<!-- QUERY 1 = the TAGS -->
<txp:smd_query query='SELECT name AS parentName, title AS parentTitle, id AS parentID 
FROM smd_tags WHERE parent ="root" AND type = "article" AND name <> "root" ORDER BY title ASC' break="">
<li>{parentTitle}
<!-- QUERY 2 = ARTICLES -->
<txp:smd_query query='SELECT textpattern.Title, textpattern.Status, textpattern.ID, textpattern.Body,textpattern.Section FROM textpattern INNER JOIN smd_tags_used ON smd_tags_used.item_id = textpattern.id WHERE Status=4 AND smd_tags_used.tag_id = "{parentID}"  ' wraptag="dl" class="" break="">
<dt><a href='/{Section}/{ID}/{Title}'>{Title}</a></dt>
<dd>
<txp:smd_wrap_all transform="strip_tags, cut|200|20w|&hellip;">
{Body}
</txp:smd_wrap_all>&nbsp;
<a href='/{Section}/{ID}/{Title}'><span>More</span></a>
</dd>
</txp:smd_query>
</li>
</txp:smd_query>
</ul>

Offline

#372 2018-02-25 08:30:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,644
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

jpdupont wrote #309416:

Is it possible to list the tags of articles belonging to a well-defined section?

Try something along the lines of this query:

SELECT tags.name, tags.title
FROM smd_tags_used AS tagu
LEFT JOIN smd_tags AS tags ON (tags.id = tagu.tag_id)
LEFT JOIN textpattern AS txp ON (tagu.item_id = txp.ID)
WHERE tagu.type = 'article'
AND txp.section = '<your section here>'

I think that gets you near where you want to be. Might need to add a clause for status='4' in there if you need to limit it to only published articles.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#373 2018-02-25 09:44:15

jpdupont
Member
From: Virton (BE)
Registered: 2004-10-01
Posts: 752
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

Thanks Stef, I will test. Before seeing your post, I tried the new txp: evaluate. It works, see below. Is this very expensive in resources?

<ul>
<!-- QUERY 1 = the TAGS -->
<txp:smd_query query='SELECT name AS parentName, title AS parentTitle, id AS parentID 
FROM smd_tags WHERE parent ="root" AND type = "article" AND name <> "root" ORDER BY title ASC' break="">
<txp:evaluate test="smd_query"> <!-- <-----EVALUATE THE NEXT QUERY -->
<li>{parentTitle}
<!-- QUERY 2 = ARTICLES -->
<txp:smd_query query='SELECT textpattern.Title, textpattern.Status, textpattern.ID, textpattern.Body,textpattern.Section FROM textpattern INNER JOIN smd_tags_used ON smd_tags_used.item_id = textpattern.id 
WHERE Status=4 
AND smd_tags_used.tag_id = "{parentID}"  
AND textpattern.Section = "mysection" 
' wraptag="dl" class="" break=""> <!-- ADD THE  FILTER ON  "MYSECTION"-->
<dt><a href='/{Section}/{ID}/{Title}'>{Title}</a></dt>
<dd>
<txp:smd_wrap_all transform="strip_tags, cut|200|20w|&hellip;">
{Body}
</txp:smd_wrap_all>&nbsp;
<a href='/{Section}/{ID}/{Title}'><span>More</span></a>
</dd>
</txp:smd_query>
</li>
</txp:evaluate> <!-- EVALUATE -->
</txp:smd_query>
</ul>

Offline

#374 2018-02-25 10:24:06

jpdupont
Member
From: Virton (BE)
Registered: 2004-10-01
Posts: 752
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

After tests, your query does not work, Stef. I get a very long page, with many tags alone (without articles) and many tags + articles with duplicates.
It may be necessary somewhere “DISTINCT” ??? , but I am not a master of SQL queries …

Offline

#375 2018-02-25 11:24:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,644
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

jpdupont wrote #309424:

After tests, your query does not work, Stef. I get a very long page, with many tags alone (without articles) and many tags + articles with duplicates.

The query wasn’t to render a page it was just a raw query to demonstrate how to use the smd_tag_used table to link to articles and output a list of tags in one query. If you want to output more fields form the article, add them to the SELECT and then pull them out in your smd_query container via {replacements}.

You’re right though: it’ll need some DISTINCT clause somewhere to prevent duplicates.

Alternatively, just tweak the query I posted to get a list of unique tag names in use across the section you are interested in, then use <txp:smd_related_tags /> to display the articles associated with each one. Depending on the number of tags in use, it might be a bit expensive in terms of queries though.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#376 2018-02-25 12:09:29

jpdupont
Member
From: Virton (BE)
Registered: 2004-10-01
Posts: 752
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

Thank you Stef. I will look at the last suggestion with <txp:smd_related_tags/>.

On the other hand, is my solution with <txp:evaluate /> (which works correctly) a somewhat twisted use of evaluate, and too greedy in resource? Or the <txp:evaluate /> code optimizes all this?

Offline

#377 2018-02-25 13:23:11

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

jpdupont wrote #309426:

On the other hand, is my solution with <txp:evaluate /> (which works correctly) a somewhat twisted use of evaluate, and too greedy in resource? Or the <txp:evaluate /> code optimizes all this?

The multiple queries seem expansive, and <txp:evaluate /> does not help in any way here. I would rather try to extract everything in one go as suggested by Stef, but the only way to be sure is test and look at the debug info.

Offline

#378 2018-02-25 19:06:32

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 651
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

First of all a big thank you to you, Stef, for this awesome plugin. I will make sure to meet your donation button soon again. But then

debeo wrote #302925:

If anyone would be so kind to explain probably obvious thing that I can’t grasp.

I have articles under many sections and want to show them all under particular tag to which are they assigned. What do I do with ‘URL name parameter’ if I have something like this…
<txp:smd_if_tag> <txp:smd_related_tags type="article" match="tag_name" wraptag="ul" break="li"> <txp:permlink><txp:title /></txp:permlink> </txp:smd_related_tags> </txp:smd_if_tag> ?

I am having the same problem. I display a tag tree somewhere and want to display a list of articles using a one particular tag, when clicking on that respective tag in the tree. (Bloke’s fix below your post didn’t work here).
Using smd_tags 0.60 fresh installed today on a txp 4.6.2.

I am using

<txp:smd_if_tag_list auto_detect="0" type="article"> <txp:smd_if_tag> <txp:smd_related_tags section="music" type="article" match="tag_name" wraptag="ul" break="li" /> <txp:permlink><txp:title /></txp:permlink> </txp:smd_if_tag> </txp:smd_if_tag_list>

as part of an article form.
This article is entitled “results”, has a section “filter”, which is what i told smd_tags to use to construct tag links (smd_tag_u_sec).
When i call that article i [edit…] as an article_custom with above form applied, like in <txp:site_url />/filter/article/band i get not just articles tagged with “band”, but all articles in section music (like called in form above). Though not the articles, which didn’t use any tag at all. That seems to show, that there is some recognition of the form code… [/edit]

Anyhow, a tag doesn’t seem to play a role in the detection of the results.

Is it wrong to use the smd code above as part of an article form?

Where is my error?

Last edited by jayrope (2018-02-25 23:51:15)


a hole turned upside down is a dome, when there’s also gravity.

Offline

#379 2018-02-26 14:14:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,644
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

jayrope wrote #309430:

I display a tag tree somewhere and want to display a list of articles using a one particular tag, when clicking on that respective tag in the tree.

This should be pretty standard functionality in smd_tags. First of all, a few things to note/questions:

  • When you say you display the tag tree “somewhere”, where is that exactly? In the Page template of your filtersection? How’s it being displayed? (what tag code?)
  • Why are you putting an article in the filter section and results code in an attached Form? I mean, it might work (in theory) but I’m not sure if Txp’s internal proccessing will get in the way (which might in fact have a bearing on your other query). It’ll probably depend on your use of <txp:if_individual_article> / <txp:if_article_list> and where the tag tree is displayed in the page flow.

That second point requires exploration. When Txp encounters your filter section it’ll load a given Page/Style as a “landing page” (a.k.a. list page / not an individual article page). The plugin wakes up, since the URL matches, and it’ll look at the remainder of the URL to determine if you’re viewing an individual tag:

  1. If not (example.com/filter) it should be instructed in your page template to render a tag list, either all tags, tags from a parent, used/unused/whatever. That allows visitors to click tags in the tree to see more.
  2. If individual tags are given (example.com/filter/article/tag1+tag2+tag3+...) then your page should detect this situation and use <txp:smd_related_tags> to fetch all articles that match the given tag(s).

Notice in the above two situations that under no conditions is an article called. As far as the plugin is concerned, there is no individual article view on a tag page.

So, by the time Txp gets involved – after the plugin has checked the URL status – and Txp decides to try an individual article, it’ll find your results page and dutifully render it. But all the tag stuff that the plugin set up might become confused because it’s not a list any more. I’m not sure, never really tested it that far as it’s not how I envisaged it to be used.

What you could do in situation 2 above, inside the <txp:smd_if_tag>, is put your article_custom there to load the article, display some top and tail content and then somewhere sandwiched in the middle, call the result form to display the tag contents/related articles. That might work a bit better.

<txp:smd_if_tag_list auto_detect=“0” type=“article”>

There are no such attributes to this tag. Check the plugin docs for details.

If you’re still stuck, post the relevant parts of your page/form template code and I’ll see if I can figure out what’s going on.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#380 2018-02-26 14:44:16

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 651
Website

Re: smd_tags: unlimited article, image, file and link taxonomy

Bloke, thank you for coming back to this.

I display a sitemap (made from tags) in an article called sitemap, which is not part of my trigger section (the trigger section is called filter).
This is obviously my first mistake.
That sitemap/tag tree displays correctly.
The links of the tags follow the scheme site_url/trigger_section/article(from type)/tag
My landing page in the trigger section “filter” uses just a form with a content like this

<txp:smd_tag_list type="article"> <txp:smd_tag_info item="name" /> - <txp:smd_if_tag_list auto_detect="0"> <txp:smd_if_tag> <txp:permlink><txp:title /></txp:permlink> <txp:smd_related_tags section="music" type="article" match="tag_name" wraptag="ul" break="li" /> <br /> <txp:else /><txp:title /> has no tags, <txp:permlink>please edit</txp:permlink><br /> </txp:smd_if_tag> </txp:smd_if_tag_list> </txp:smd_tag_list>

I understand, that there is no article form used anywhere, so i go that way first.
… and report back. Thanx much!

Last edited by jayrope (2018-02-26 14:49:47)


a hole turned upside down is a dome, when there’s also gravity.

Offline

Board footer

Powered by FluxBB