Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#289 2014-10-09 23:33:09

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

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

Bloke wrote #284661:

SQL_CALC_FOUND_ROWS

Try the latest version and see if that’s any more useful. If I’ve totally misunderstood your intentions and requirements, please explain it to me like I’m a parsnip and I might then get it.


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

#290 2014-10-10 00:32:08

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

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

Excellent! Just given it a quick run-through and that seems to have done it. Will check again in the morning when I’m more alert, but I think we have a winner! Thank you!


TXP Builders – finely-crafted code, design and txp

Offline

#291 2014-10-10 08:00:57

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

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

Bloke wrote #284661:

MySQL does have a nifty feature SQL_CALC_FOUND_ROWS. Simply adding that to the query and then calling SELECT FOUND_ROWS() immediately afterwards tells you how many rows are in your total result set, regardless of offset/limit.

Tremendously useful info, thanks, Stef! Gonna try it somewhere…

Offline

#292 2014-10-10 08:13:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

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

etc wrote #284690:

Tremendously useful info, thanks, Stef! Gonna try it somewhere…

You’re welcome. It’s relatively new to me too but it’s very handy.

To improve things even further (and I may do this in smd_tags if jakob verifies that the count is correct under all conditions he can test), you can cache the total rows after the first query has run — maybe in the session against an md5 of the query string, minus its limit/offset. Subsequent calls for exactly the same query can then take advantage of not having to add SQL_CALC_FOUND_ROWS to the query at all, thus improving performance. You have to be careful if things are changing rapidly in the database so as not to return ‘stale’ or misleading info and flush the value accordingly. The comments on this post offer more.

As I mentioned, the downside is lack of compatibility outside MySQL (as far as I’m aware). Ideas welcome on how to handle situations for other engines under PDO.


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

#293 2014-11-27 08:29:57

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

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

Hi,
I think I have the same problem as kees-b in August:

I have a full list of tags on my site,
when clicking one of them a new page with the related articles opens,
there I still want to have the full list of tags,
but with the one now active highlighted.

Couldn’t find any hint how to find and style the active tag with an if_statement.
Any solution?

Offline

#294 2014-11-27 09:19:52

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

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

Maybe this at least is a workaround:

<txp:smd_tag_list wraptag="" break="">
<txp:variable name="current_tag" value='<txp:smd_tag_name title="0" />' />
</txp:smd_tag_list>
<txp:smd_tag_list parent="" showall="1" wraptag="ul" break="" sublevel="all" >
<li<txp:if_variable name="current_tag" value='<txp:smd_tag_name title="0" />'> class="smd_tag_name_current"</txp:if_variable>><txp:smd_tag_name link="1" title="1" /></li>
</txp:smd_tag_list>

This will put out a list of all tags with the class smd_tag_name_current added to the li at the currently active tag list.

Last edited by saccade (2014-11-27 09:22:27)

Offline

#295 2015-04-16 08:51:36

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

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

Hi, maybe I wrong something but I use the Example 1: linked tag tree
and I have setting in preference Trigger(s) for tag lists: articles.

Now, in articles page, I have put this code:

<section class="wrapper">
    <txp:smd_if_tag>
      <txp:article limit="1" />
      <txp:else />
    	<txp:article form="simple" />
    </txp:smd_if_tag>
  </section>

But independently of tag I send to this page it show always the same article. Why?

Offline

#296 2015-04-16 11:22:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

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

MarcoK wrote #290023:

independently of tag I send to this page it show always the same article. Why?

Because you’re not changing the context. Your <txp:article> tag is picking up the default Textpattern context based on the URL: in this case, your Section. So it’ll display the most recent article from the articles Section, as if the smd_tags weren’t there.

What I think you want to do is display a list of article that have the tag given in the URL, correct? In that case, you might try something like this:

<txp:smd_if_tag>
   <txp:smd_tag_list wraptag="" break="">
      <txp:smd_related_tags wraptag="ul" break="li" />
   </txp:smd_tag_list>
<txp:else />
   <txp:article form="simple" />
</txp:smd_if_tag>

So what that does is the following:

  • Am I in a tag context?
  • If so, make a list of tags from the URL (normally just the one) and set the context to that tag.
  • Ask smd_related_tags to find other articles that match the tag.
  • Display them as a list of links with their titles.
  • Else: display the article / article list from the current Section as given in the URL.

You can use <txp:smd_related_tags> as a container to customise what you see in the article list.

btw, this method comes with a big caveat: ensure that your tag names never match the url-title of an article, because you’re (ab)using the articles Section for two purposes. Txp will always take precedence if there’s a clash. Or things might go a bit weird: I’m not entirely sure!


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

#297 2015-04-16 12:46:33

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

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

Many thanks Stef!!

Offline

#298 2015-06-04 12:26:12

bojay
Member
Registered: 2010-04-13
Posts: 11

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

Hi, I’m trying to get my head around structuring my tags.
And was wondering if some of you could share your thoughts.

I need my page to display a list of the four most relevant articles (for further reading) .. related to the article your current reading.
I have plenty of article and a lot of matching on a single-tags-level.

But if an article is tagged with “Fantasy” and “Frodo”, I’d love other article with both tags to be matched prior to something just matching “Fantasy”.

So if 10 article exist with both tags .. I need four random from those.
But then nothing from less-relevant matches eg. Only Fantasy and only Frodo.

And if only 2 other articles exist with both tags, I need them every time .. and then random from articles matching one of the other tags (preferably fixed)

At the moment my tags are without a parent, and all-on-the-same-level, but I can’t get my head around the structure and how to ask related_tags to match on more than one criteria.

Any thoughts are greatly appreciated :-)

Moderator’s annotation:
Edited to translate foreign language remainder.
– Uli –

Last edited by uli (2015-06-04 13:59:34)

Offline

#299 2015-06-04 13:58:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

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

bojay wrote #291301:

how to ask related_tags to match on more than one criteria.

That’s a very good point and something the plugin should be able to do. I don’t think it’s down to the hierarchy and structure of your tag lists per se, but something the plugin needs to offer. I was already partway there with jakob nudging me to add tag counts for the next version (although I think trying to match using tag_count doesn’t work properly so I need to look at that). Anyway, I just added a small mod to the next version to include the tag sums per content type. If you wouldn’t mind trying out the beta then you can do what I think you want like this:

<txp:smd_related_tags limit="4" sort="tag_sum desc" />

That should return only the articles that match any of the tags in the current article, and the more tags that match, the higher up the list the matched article is. If you also want to pimp newer stuff over older you can use sort="tag_sum desc, Posted desc".

If you’re comfortable compiling the plugin or have ied_plugin_composer available to install the new version directly from the template file, that’s grand. If you need a compiled version, drop me an email and I’ll send you one over.

Please let me know how well (and if!) it does what you want.


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

#300 2015-06-04 14:04:07

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

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

Thinking out loud without having tried this, could you achieve this in a multi-step process?

1. first the multi-tag search but only use it to output id numbers separated by commas into a variable called for example two_tag_articles. A sample output could be “12,56,84” or whatever the id numbers of the matching articles happens to be.

2. A small bit of php along the lines of the following to count the number of matches and output that to a variable called two_tag_matches:

<txp:php>global $variable; $variable['two_tag_matches'] = count(explode(",", $variable['two_tag_articles']));</txp:php>

3. Test whether you have enough two_tag_matches, e.g. using smd_if.

3a) If you do, build a txp:article_custom statement with the id='<txp:variable name="two_tag_articles" />' limit="4" sort="rand()" you output your linked articles. That should give you a random list of four matching articles.

3b) If you don’t, do a similar exercise as 1) for your single tag variants, again outputting possible matches into a comma-separated list, or lists, e.g. one_tag_articles_a and one_tag_articles_b.

Then use something like the following to join the two lists of ids and shuffle them randomly, outputting them as a variable one_tag_articles.

<txp:php>global $variable; $tmp_list= explode(",", ($variable['one_tag_articles_a'] . "," . $variable['one_tag_articles_b']) ); $variable['one_tag_articles'] = implode("," , shuffle($tmp_list) );</txp:php>

Finally output your txp:article_custom statement with first the two_tag_articles, then the remaining one_tag_articles in the id attribute of your article_custom statement, e.g. id='<txp:variable name="two_tag_articles" />,<txp:variable name="one_tag_articles" />' limit="4".

It’s a bit convoluted – and only deals with your two tag plus two single tags situation – so maybe someone else has a better idea… [ EDIT: And Stef already does :-) ]


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB