Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-01-30 16:53:14

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,256
Website GitHub Mastodon Twitter

Number of links from a particular link category

Is there a way to show in the front end, the number of links from a particular link category?

Something like the functionality of mdn_count but for link categories.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2011-01-30 17:16:48

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Number of links from a particular link category

It’s a simple query:

SELECT COUNT(*) FROM txp_link WHERE category = 'the_category'

which you can run via:

safe_count('txp_link', "category = 'the_category'");

(better because then safe_prefix() is built in)

or via smd_query (likewise).

I wouldn’t necessarily want to take this approach for a long category list, however — too many queries.


Code is topiary

Offline

#3 2011-01-30 17:29:00

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,256
Website GitHub Mastodon Twitter

Re: Number of links from a particular link category

Hi Jeff thanks for the quick reply but it doesn’t seem to work. It is 100% my fault though… I’m sure

This is what I have inserted in the page

<txp:php>safe_count('txp_link', "category = 'contributors'");</txp:php>

I wouldn’t necessarily want to take this approach for a long category list, however – too many queries.

What would a long list be? I currently have just under 400 links. Would that be too many queries?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2011-01-30 18:28:13

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Number of links from a particular link category

Try:

<txp:php>echo safe_count('txp_link', "category = 'contributors'");</txp:php>

colak wrote:

What would a long list be? I currently have just under 400 links. Would that be too many queries?

It’s the number of categories you want to display on the page that matters.


Code is topiary

Offline

#5 2011-01-31 06:09:38

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,256
Website GitHub Mastodon Twitter

Re: Number of links from a particular link category

jsoo wrote:

Try:

<txp:php>echo safe_count('txp_link', "category = 'contributors'");</txp:php>

oops. missed the echo. Thanks… this works:)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB