Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-02-23 12:46:00

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

[SOLVED] links count?

In my use of links for creating a site-wide bibliography, I’d like to be able to give a total count of source items in the biblio list (e.g. in the intro text) without actually numbering the list (because you don’t number a bibliography). Is there a way to output that?

Last edited by Destry (2022-02-25 13:34:56)

Offline

#2 2022-02-24 04:06:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,877
Website GitHub Twitter

Re: [SOLVED] links count?

Hi Destry,

I take it that all your links are in the links pane and are saved under a category. If that category is named bibliography, the following php snippet returns the number of links belonging to that category.

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

Yiannis
——————————
neme.org | hblack.net | EMAP | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#3 2022-02-25 06:55:00

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

Re: [SOLVED] links count?

Hi Colak. Yes, links panel context. The whole site is a glossary site and links are not used for anything but biblio references, so no category, in fact.

I could try to create categories to group reference types, but then could I add multiple comma-separated cats in the value to sum them?

Still, that seems overly clumsy and extra work with categories just to get a single total count.

It’s not a big deal. I can do without the count value, if it comes to that. I just wondered if it was easily possible.

Last edited by Destry (2022-02-25 06:57:06)

Offline

#4 2022-02-25 07:56:03

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

Re: [SOLVED] links count?

I just looked and realized I had added a bunch of categories to classify refs by type, but I’ve not actually done the parsing yet, as it was not an easy figuring to distinguish them all. So no cats used in code, really.

But I guess I could lump them all into a single ‘biblio’ category for purposes here. That’s easy enough, now that I’ve had my first coffee.

Thanks, colak.

Last edited by Destry (2022-02-25 07:59:38)

Offline

#5 2022-02-25 08:06:24

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

Re: [SOLVED] links count?

Oh, I remember now (it’s been some time since I Iast looked at this part of the project), all the type categories were just for my own benefit behind the scenes, not something I was going to use front-side. So it is a bit of a disappointment that I’m limited to one category only and will lose my sub-groupings if I go with a single ‘biblio’ category.

Anyway, at least I know what choice to make here.

Have the UCF’s landed yet? 👽

Last edited by Destry (2022-02-25 08:18:53)

Offline

#6 2022-02-25 08:49:30

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

Re: [SOLVED] links count?

Hi Destry, if you just want to count all the links regardless of category, you can just change the WHERE part of the function to be 1 = 1 (meaning no filter):

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

(there’s a similar example in the source code here)


TXP Builders – finely-crafted code, design and txp

Offline

#7 2022-02-25 09:55:40

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

Re: [SOLVED] links count?

Thanks. I’m getting this error if using that in the relevant excerpt field (pref is set to use php in articles):

Parse error: syntax error, unexpected ‘=’, expecting ‘,’ or ‘)’ in /Users/destry/Sites/wood/textpattern/publish/taghandlers.php(4396) : eval()’d code on line 1

I’m still on Txp v. 4.8.4 here. I will upgrade today.

Offline

#8 2022-02-25 10:06:45

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

Re: [SOLVED] links count?

Maybe I inadvertently mixed my quotes and it should be '1 = 1' but I thought you could mix quotes as in Yiannis’ example. The function has been around for ages so should work in earlier versions. Are you sure you don’t have a copy-paste or carry-over error in there?

The example from GitHub in the source code there is a bit more defensive in that it won’t return an error if there are no matching results.


TXP Builders – finely-crafted code, design and txp

Offline

#9 2022-02-25 13:10:23

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

Re: [SOLVED] links count?

The source code uses double quotation marks, but the real problem seems to be that you can’t add the txp:php tag in an excerpt field. If I add the intro text with the tag to the body instead, it works.

EDIT: I take that back. It seems to be a problem with using the tag within a paragraph. So this does not work, as I was trying:

Below is every resource read or considered to some extent for the development of content in this website. New sources are added as they are considered. There are currently <txp:php>echo safe_count("txp_link", "1 = 1");</txp:php> source items.

But using the tag by itself does work.

Last edited by Destry (2022-02-25 13:14:26)

Offline

#10 2022-02-25 13:20:13

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

Re: [SOLVED] links count?

Oh, maybe I need to set it up as a variable? That’s how I have this working in the footer:

<footer>
<txp:variable name="current_year">
  <txp:php>echo safe_strftime('%Y');</txp:php>
</txp:variable>
...
<p>... <txp:variable name="current_year" /> ...</p>
</footer>

No, that’s probably not right because we’re talking about a table records value in this case. And it works fine if the tag is used by itself.

Beats me.

Last edited by Destry (2022-02-25 13:22:22)

Offline

#11 2022-02-25 13:29:44

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

Re: [SOLVED] links count?

The tag seems to need to be on a line by itself surrounded by blank lines, which isn’t going to work for me presentation wise.

I’ll just skip it.

Thanks anyway. Sorry for the trouble.

Offline

#12 2022-02-25 13:34:24

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,851
Website

Re: [SOLVED] links count?

Success. It does work as desired if I set it up as a variable.

You can’t just assume I know these things. :)

Offline

Board footer

Powered by FluxBB