Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
552 views
in Q2A Core by
Is there a simple method to limit the quantity of shown users ?
related to an answer for: Showing popular contributors in sidebar

1 Answer

0 votes
by
Use the PHP function array_slice on the $users variable before you start displaying them: http://php.net/manual/en/function.array-slice.php
by
Ah great, this one I used for the tags on the sidebar. Just thought there may be an easier way. I will figure it out.
Thanks and regards

monk333
by
Can you please tell me how you did it?? How did you implement the function array_slice??
by
Hey, I figured it out....For those who wants to display the top 5 users here in the sidebar here is the code...place it in the qa-theme.php file located in the themes folder....

function sidebar()
        {
            global $qa_db;

            qa_html_theme_base::sidebar();

            $users=qa_db_single_select($qa_db, qa_db_top_users_selectspec(0));
            echo "Top 5 Users";  
            foreach (array_slice($users,0,5) as $user)
            $this->output('<P>'.qa_get_one_user_html($user['handle'], false).
                    ' ('.number_format($user['points']).')</P>');
        }

In fact your qa-theme.php file will look like this after placing the code....

<?php

/*
    Question2Answer 1.2.1 (c) 2010, Gideon Greenspan

    http://www.question2answer.org/

   
    File: qa-theme/Candy/qa-theme.php
    Version: 1.2.1
    Date: 2010-07-29 03:54:35 GMT
    Description: Override something in base theme class for Candy theme


    This software is free to use and modify for public websites, so long as a
    link to http://www.question2answer.org/ is displayed on each page. It may
    not be redistributed or resold, nor may any works derived from it.
   
    More about this license: http://www.question2answer.org/license.php


    THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
    TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

    class qa_html_theme extends qa_html_theme_base
    {
        function nav_user_search() // reverse the usual order
        {
            $this->search();
            $this->nav('user');
        }
       
        function sidebar()
        {
            global $qa_db;

            qa_html_theme_base::sidebar();

            $users=qa_db_single_select($qa_db, qa_db_top_users_selectspec(0));
            echo "Top 5 Users";  
            foreach (array_slice($users,0,5) as $user)
                $this->output('<P>'.qa_get_one_user_html($user['handle'], false).
                    ' ('.number_format($user['points']).')</P>');
        }
    

    }
   

/*
    Omit PHP closing tag to help avoid accidental output
*/
...