how to do: top ten articles per catergory

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Nat,
natmanu wrote:1. so far so good the only bug left in it is that when on the index page:
http://localhost/faqs/index.php?
&
ask/contact pages
http://localhost/faqs/index.php?action=ask

the top 10 is : cat1 then followed by cat 2 etc. I would like it on these pages (general pages 'not general cat, which is 1') to combine all the catergories top 10s. so it should be a list of top 10 from all catergories combined, don't seperated then by catergory here.
--
TOP 10
1. from cat1
2. from cat3
3. from cat 1
4. from cat 2
5. from cat2
--
Mmmmhhh... so the previous one was not the final spec :wink:.
Please, use the generateTopTen() function below:

Code: Select all

function generateTopTen($language = '')
{
    global $PMF_LANG, $PMF_CONF, $tree, $cat, $action;

    $output = "";
    $exit = false;
    foreach ($tree->categories as $category) {
        if (    ((0 != $cat) && ($cat == $category['id']))
             || ((0 == $cat) && (!$exit) ) ) {
            $topTenOnAllFAQ = (0 == $cat) && (('main' == $action) || ('ask' == $action));
            if ($topTenOnAllFAQ) {
                $result = generateTopTenData($language);
                $exit = true;
             }
             else {
                $result = generateTopTenData($language, PMF_NUMBER_RECORDS_TOPTEN, $category['id']);
             }
            if (count($result) > 0) {
                $output .= "<ol>".($topTenOnAllFAQ ? "" : "<h3>".$category['name'])."</h3>\n";
                foreach ($result as $row) {
                    $output .= "\t<li><strong>".$row['visits']." ".$PMF_LANG["msgViews"].":</strong><br />";
                    $output .= '<a href="'.$row['url'] . '">'.makeShorterText(PMF_htmlentities($row['thema'], ENT_NOQUOTES, $PMF_LANG['metaCharset']), 8)."</a></li>\n";
                }
                $output .= "</ol>\n";
            }
        }
    }
    if ('' == $output) {
        $output = $PMF_LANG["err_noTopTen"];
    }

    return $output;
}
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Re: THE RSS FEED

Post by matteo »

Hi Nat,
natmanu wrote:it seems like it is trying to find a file called
http://www.uvolunteer.org/faqs/feed/top ... .php&cat=3

and can cannot find it. It is not running the script , i think!

and ideas? anyway i'll look more ito it 2mor. goodnight
I've just posted the solution just some entries before this one :wink:
Just read here why you must use ? instead of &

Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
natmanu
Posts: 22
Joined: Wed May 24, 2006 7:07 pm

Post by natmanu »

Morning,

Thanks for the new snippet. It does the job perfect.
I even managed to ammend it so that it will work on the 'sitemap' and 'show all' pages.

The only problem left to fix is the rss problem but I think that will be easier. It's just that at the mo i have a problem with my PHP include_path on my remote server. but once that is sorted I think i should be able to fix it.

Thanks for the link expalining URI

I'll keep you posted on my progress, so that when I've fixed this remaining bug you can stand back & admire your work :-)

Do you also have a wish list?
Nat
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi,
natmanu wrote:I'll keep you posted on my progress, so that when I've fixed this remaining bug you can stand back & admire your work :-)
Thanks! :)
natmanu wrote:Do you also have a wish list?
Currently nothing, AFAIK in Italy there is no wish list services at all: I was thinking to create a list with the Amazon UK service but nothing has been done yet...

Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
natmanu
Posts: 22
Joined: Wed May 24, 2006 7:07 pm

When you thought all was well

Post by natmanu »

All was going well and THEN :-(

just a small hitch :-)
1. There are two funny error at the top of the page that i don't quite know what they are.
http://uvolunteer.org/faqs/index.php

2. the last bit to do on the top10 is to fix the headers. The headers for the comined top10 used to be in the template but know it's being generated by the gen...top10() function for the catergory top 10s. If i add it back in I get this:
http://uvolunteer.org/faqs/index.php?action=show&cat=1

which is not ideal. so if seems like we should generate the combined top10 header also from the original function....


Cheers
Nat
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi,
it' quite difficult to understand what is the issue for two reasons:
  1. this is not the standard PMF code so line 807 reference doesn't help me;
  2. Maybe you have inserted the function in a different order or manner
So the only idea is that you've reset the generateTopTenData() function to the original, missing the 3rd new parameter, $categoryId.
Just to summarize, you must use:
  1. this generateTopTenData() hacked function;
  2. this generateTopTen() hacked function.
Using those functions above, everything works on my test server.
Maybe you could post (use

Code: Select all

 tag) the [i]generatetoptendata()[/i] you're running: perhaps the [url=http://forum.phpmyfaq.de/viewtopic.php?p=12929#12929]changes you've done (behaviour changed also for [i]sitemap[/i] and [i]show[/i][/url]) are breaking something.
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Nat,
reviewing my last post I found a difference with the code I'm running. You must replace this line:

Code: Select all

function generateTopTenData($language = '', $count = PMF_NUMBER_RECORDS_TOPTEN, $categoryId)
{ 
with this line below:

Code: Select all

function generateTopTenData($language = '', $count = PMF_NUMBER_RECORDS_TOPTEN, $categoryId = 0)
{
Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
natmanu
Posts: 22
Joined: Wed May 24, 2006 7:07 pm

Post by natmanu »

Hello,
I've made that amendment and all is fine now.

The only thing left to do is to tackle the header problem on the combined top 10 pages. if you notice the header disappears on:
http://www.uvolunteer.org/faqs/index.php

As i mentioned before, i think it is because initially the header was in the template but now the header is being generated by the function.

Cheers
Nat
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Nat,
yes, the header missing is due to your template design, but give a chance to this new review of "your" generateTopTen() function:

Code: Select all

function generateTopTen($language = '')
{
    global $PMF_LANG, $PMF_CONF, $tree, $cat, $action;

    $output = "";
    $exit = false;
    foreach ($tree->categories as $category) {
        if (    ((0 != $cat) && ($cat == $category['id']))
             || ((0 == $cat) && (!$exit) ) ) {
            $topTenOnAllFAQ = (0 == $cat) && (('main' == $action) || ('ask' == $action));
            if ($topTenOnAllFAQ) {
                $result = generateTopTenData($language);
                $exit = true;
             }
             else {
                $result = generateTopTenData($language, PMF_NUMBER_RECORDS_TOPTEN, $category['id']);
             }
            if (count($result) > 0) {
                $output .= "<ol><h3>".($topTenOnAllFAQ ? $PMF_LANG["msgTopTen"] : $category['name'])."</h3>\n";
                foreach ($result as $row) {
                    $output .= "\t<li><strong>".$row['visits']." ".$PMF_LANG["msgViews"].":</strong><br />";
                    $output .= '<a href="'.$row['url'] . '">'.makeShorterText(PMF_htmlentities($row['thema'], ENT_NOQUOTES, $PMF_LANG['metaCharset']), 8)."</a></li>\n";
                }
                $output .= "</ol>\n";
            }
        }
    }
    if ('' == $output) {
        $output = $PMF_LANG["err_noTopTen"];
    }

    return $output;
}
Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
natmanu
Posts: 22
Joined: Wed May 24, 2006 7:07 pm

Post by natmanu »

Thank you for all your work on MY TOP10 FUNCTION

I noticed the amendment ($PMF_LANG["msgTopTen"]) you made but still don't understand what exactly is happening in the function! But I know all is working great. So at last we have it working as imagined

You can probably tell by now that I'm not a programmer but a designer who likes to get his hands dirty in code. So if there is any design work that you need in conjunction with this projects please feel free to ask me.

Ciao,
Nat
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Nat,
natmanu wrote:You can probably tell by now that I'm not a programmer but a designer who likes to get his hands dirty in code. So if there is any design work that you need in conjunction with this projects please feel free to ask me.
IMHO working on a project means a bit of overlapping between skills, to better understand constraints and find alternative solutions for reaching the goals. So, your "dirty hands" are welcome :wink:.

Thanks for your offer: if I'll need it I'll contact U! :)
Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Nat,
today we start working hardly on the code of the PMF 2.x release.

It would be nice if you could suggest improvements for its design, especially the backend. Currently the code is not ready to be safely used but if you're interested we could keep you aligned when the code will be stable enough for a design study e.g.: in PMF 2.0.x we've more admin features and some of them already work.
We could keep in touch through the email:
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
Post Reply