Communauté « Blogs « Questions about YACS (in English) «
A simple Count of recent pages + links?
How can I do it?
I'd like to know how to do a simple count of links + articles and have it show up on my home page.
Something like this:
SELECT COUNT(id) as number FROM table WHERE whatever > 1234;
but I'd like to do it SAFELY within the context of YACS.
Something like:
Select Count(ID) as number FROM links WHERE created > yesterday...
Something like this:
SELECT COUNT(id) as number FROM table WHERE whatever > 1234;
but I'd like to do it SAFELY within the context of YACS.
Something like:
Select Count(ID) as number FROM links WHERE created > yesterday...
| Rhodes, Nick | You would also need to check that the pages are published and correct permissions for the current user, I shall try and work out a query for you in a few days. It might be worth looking for the query that puts recent articles on the homepage. Nick NGRhodes |
![]() Udut Kennethfrom Naples, FL 52 posts | Thanks! i'd really appreciate it. I thought there was a wrapper or template I could have based it on, but I just couldn't wrap my brain around how to do it. |
| Rhodes, Nick | Hi Sorry for the delay. OK the good news is that there is already code in place to do this. If you look at links/index.php there is some code at approx line 50 to 53 the outputs the count (and considers things like published and visible for current user). If you look at articles/index.php the similar code is at lines 72-75 approx. Using articles as example, these are the useful bits of code: This gives us an array of stats:
$stats = Articles::stat();
This is the count we need:
$stats['count']
And this outputs the stats nicely: sprintf(i18n::ns('%d page', '%d pages', $stats['count']), $stats['count'])Now question is where on the homepage would you want to put this information ? As a suggestion of where to place this code, if you look at /index.php at line 1022 approx is code for showing the last poll in a box, this will require tweaking of the code What I have done is modified this to show the counts:
// build a boxSee attached file for better formatted version of the above As an example I have this running on my site, you should see it on the menu at the bottom. Nick NGRhodes |
| Rhodes, Nick | Stats file attached. BTW this will need reapplying each time YACS gets upgraded, tested on 8.11.RC30 Nick NGRhodes Stats.txt |
![]() Udut Kennethfrom Naples, FL 52 posts | Thanks Nick! You've given me enough to work with this idea further! What I'm looking to do (and I *think* what you provided gives me a great starting point for this) is to show the # of new articles on the whole site and the # of new links per section. I pull a lot of feeds into my site -- in fact, YACS' ability to pull in feeds easily and remove duplicate links was the biggest reason why I developed with YACS. So for example, let's say that, since yesterday, there were 37 new news feed items, 23 new job feed items and three new postings in the Business Directory section. I'll be putting a gigantic, "New for Today": 37 News Stories, 23 New Jobs, 3 new businesses listed". (something like that) I could have done a simple SQL query but I prefer to work "within the system" of yacs as the security settings are already in place, etc. And what you've provided will definitely give me a direction to go in. Thanks again! Ken |
| Rhodes, Nick | I think should look at overlays and see if you can store the data via one of them, then I am pretty sure you can output that info to the homepage. Cheers, Nick Nick NGRhodes |











