Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-08-06 18:44:02

mhulse
Plugin Author
From: Eugene Oregon
Registered: 2005-01-21
Posts: 200

Using PHP: Counting articles

Hi,

I am sure the answer is staring me in the face…

Without using a plugin, I would like to count the number of articles that get displayed via an article form using PHP.

Is this possible? I have tried many things, but I can not figure out how to count the loops of an article form.

Hehe, does that make sense?

TIA!
Cheers,
Micky

Offline

#2 2007-08-06 19:07:45

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Using PHP: Counting articles

Put this into your page template somewhere below the <txp:article /> tag:

<txp:php>global $thispage; echo $thispage['grand_total'];</txp:php>

Last edited by wet (2007-08-06 19:08:04)

Offline

#3 2007-08-06 19:26:28

mhulse
Plugin Author
From: Eugene Oregon
Registered: 2005-01-21
Posts: 200

Re: Using PHP: Counting articles

Hi Wet, many thanks for your quick reply. As always, I immensely appreciate your help. :)

That code snippet does the trick, thanks!

Looks like this site needs to add $thispage['grand_total']; to the list. :)

….

Within the article form itself, is there a way to put the count next to the article? For example:

1. <title><body>
2. <title><body>
3. <title><body>

Thanks again Wet!
Cheers,
Micky

Offline

#4 2007-08-07 05:52:58

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Using PHP: Counting articles

mhulse wrote:

Within the article form itself, is there a way to put the count next to the article? For example:

Nothing I can think of.

Offline

#5 2007-08-07 06:01:16

mhulse
Plugin Author
From: Eugene Oregon
Registered: 2005-01-21
Posts: 200

Re: Using PHP: Counting articles

Ah, yah… same here… Been racking my brain all day.

The only thing I can think of is:

1. Get total count of articles.
2. Use a loop that takes prints an article, but uses an article offset based on total count and the current loop number.

Er, I am sure it would have to be more comples than that, but using the article offset feature, I think, might get me somewhere…

Though, I have yet to test my theory. :D

I will post my findings.

Thanks again wet!

Have a good one.
Cheers,
Micky

Offline

#6 2007-08-07 06:06:33

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

Re: Using PHP: Counting articles

I know that you are trying to do it without a plugin but there is mdn_count which might be of help.


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

Offline

#7 2007-08-07 06:33:48

mhulse
Plugin Author
From: Eugene Oregon
Registered: 2005-01-21
Posts: 200

Re: Using PHP: Counting articles

Thanks colak, looking at the plugin now. :)

Sheesh! I wish I did not have to sleep! I am just now shifting gears into geek mode… unfortunately, I have to get up early… I may have to postpone my experiments until tomorrow. :(

I will post my findings asap.

Thanks again for the help.
Cheers,
Micky

Offline

#8 2007-08-09 07:00:54

swati.miniyar
Member
Registered: 2007-08-06
Posts: 39

Re: Using PHP: Counting articles

i am using <txp:php>global $thispage; echo $thispage[‘grand_total’];</txp:php>
with <txp:article_custom>..but i am not getting any results..

why?any help?

Offline

#9 2007-08-09 07:16:28

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Using PHP: Counting articles

How exactly are you using that with article_custom?

Offline

#10 2007-08-09 07:25:40

swati.miniyar
Member
Registered: 2007-08-06
Posts: 39

Re: Using PHP: Counting articles

my code is—

<txp:article_custom section=“archive” limit=99999 form=“monthly_article” /> <txp:php>global $thispage; echo $thispage[‘grand_total’];</txp:php>

monthly_article form links to the articles from a particular month..

it gives me listing of month names which goes to the articles from that month..
i want to show the no of articles from that month..
i want like this-
jan 2007(10)

where 10 is no.of articles from month jan..

any help please…

Last edited by swati.miniyar (2007-08-09 07:29:44)

Offline

#11 2007-08-09 07:30:09

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Using PHP: Counting articles

article_custom doesn’t set the $thispage variable, only the article tag does that.

Offline

#12 2007-08-09 10:22:07

swati.miniyar
Member
Registered: 2007-08-06
Posts: 39

Re: Using PHP: Counting articles

then how to get the no. of article if <txp: article_custom > is used?
i want it for post #10

Offline

Board footer

Powered by FluxBB