• I’m trying to create a function to display the top voted images, but it’s pushing me beyond my php skills. The code below is in my functions.php. It is not returning any errors, but it also isn’t returning the images. I put it together from:

    • The db query found in this forum post
    • The html to display the images found in the nextgen gallery plugin. (/view/gallery.php lines 38 and following)

    My hunch is that I’m close, but like I said, I don’t know php quite well enough to figure out what’s not working right. Appreciate any help getting it right:

    function top_images() {
    global $wpdb;
    
    $images = $wpdb->get_results("SELECT pid, SUM(vote) AS totalVote;
    FROM wp_nggv_votes;
    GROUP BY pid;
    ORDER BY totalVote DESC;
    LIMIT 10;");
    
    foreach($images as $image) {
    global $wp_query;
    $wp_query->get_queried_object();
    echo "<a href='";
    echo $image->imageURL;
    echo "' title='";
    echo $image->description;
    echo "'";
    echo $image->thumbcode;
    echo "'><img title='";
    echo $image->alttext;
    echo "' alt='";
    echo $image->alttext;
    echo "' src='";
    echo $image->thumbnailURL;
    echo "'";
    echo $image->size;
    echo " /></a>";
    }
    }
Viewing 15 replies - 16 through 30 (of 47 total)
  • Plugin Author shauno

    (@shauno)

    @slickvicent: Dude, there’s a button for that in the backend.

    @jacopod: Dude, there’s a button for that in the backend.

    Did you guys even read the thread? Specifically the part where I said

    Check out v1.8 ??
    Cool new filter to list top voted images.

    @Everyone-who-asks-to-see-top-or-average-image-results-somewhere-ever-again: Dude, there’s a button for that in the backend.

    I am totally laughing at your reply… I just got a notification to update to 1.8 I thought I was updated all along. Thanks for the laugh @shauno

    Plugin Author shauno

    (@shauno)

    Lol, glad you took that the right way. Psst, it’s been in since 1.8 ??

    Lol…

    Hey Shauno… I’m still looking for the back end BUTTON to display top voted images and I can’t find it…

    I guess I am terrible at this

    Plugin Author shauno

    (@shauno)

    It’s under the ‘NGG Voting Defaults’ toolbar on the left side. The option labeled ‘Top Rated Images’.

    Ok I saw that but how do I get images to display on my website anywhere I want it to show. I really want to display top rated pics on my home page…. not the side bar

    Thanks for all the help

    Plugin Author shauno

    (@shauno)

    Um, you can’t…
    That’s purely for the admin to have a look at what’s-what with their images.

    If I had to make a front end thing I would need to make it templatable, and be able to handle arguments like what gallery, how many images, voting thresholds etc.

    Maybe in the future. But for now, it’s bed time for bitter programmers in South Africa ??

    PS, have a look at the function nggv_admin_top_rated_images() on line 803 if you want to try hack it together yourself…

    Ok thanks for everything then…

    Would of loved to display for visitors on the home page. I wish I could program but I can’t. Well maybe in the future. I know someone on this thread has top ten images posting on the website but his function and website is german.

    Well thanks again…. night! night!

    Plugin Author shauno

    (@shauno)

    Copy and paste this into your functions file:

    function shaunos_awsome_top_images_i_should_really_consider_donating($limit=10) {
    	global $wpdb, $nggdb;
    	$qry = 'SELECT pid, SUM(vote) AS total, AVG(vote) AS avg, MIN(vote) AS min, MAX(vote) AS max, COUNT(vote) AS num'; //yes, no joins for now. performance isnt an issue (i hope...)
    	$qry .= ' FROM '.$wpdb->prefix.'nggv_votes';
    	$qry .= ' WHERE';
    	$qry .= ' pid > 0';
    	$qry .= ' GROUP BY pid';
    	$qry .= ' ORDER BY avg DESC';
    	$qry .= ' LIMIT 0, '.$limit;
    
    	$list = $wpdb->get_results($qry);
    
    	foreach ($list as $key=>$val) {
    		$val->image = nggdb::find_image($val->pid);
    
    		/*
    		//Uncomment this amazing piece of code to see all the magical attributes provided, free of charge, by NextGEN. Radical bro.
    		print("<pre style='font-family:verdana;font-size:13;color:#000;z-index:99999;background:#ccc;'>");
    		print_r($val);
    		print("</pre>");
    		*/
    
    		echo "<a href='";
    		echo $val->image->imageURL;
    		echo "' title='";
    		echo $val->image->description;
    		echo "'";
    		echo $val->image->thumbcode;
    		echo "'><img title='";
    		echo $val->image->alttext;
    		echo "' alt='";
    		echo $val->image->alttext;
    		echo "' src='";
    		echo $val->image->thumbURL;
    		echo "'";
    		echo $val->image->size;
    		echo " /></a>";
    	}
    }

    Then paste this code anywhere you want to show your top images:
    <?php shaunos_awsome_top_images_i_should_really_consider_donating(10); ?>
    You can change the 10 to the number of images you want to show.

    Hey Sauno you are awesome even though I haven’t tried the program you just wrote.

    But when you say copy and paste into your functions file do you mean functions in the theme back end area??? Sorry don’t know where exactly I would copy and paste.

    I will be sending donation as soon as I can. Thanks for doing this for me and obviously everyone else that would like to use.

    I posted on Photocrati Theme: Theme Functions (functions.php) below the line to insert custom functions

    not sure if that’s where I should put your program.

    installed Exec-PHP plugin and now i get this…

    Fatal error: Call to undefined function shaunos_awsome_top_images_i_should_really_consider_donating() in /home/content/99/7381199/html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 1

    I think I’m on to something….

    Plugin Author shauno

    (@shauno)

    You do put it in your theme’s function file. That should make it available anywhere in your site.

    You then should just need to paste the call to the function anywhere in your theme you want to show the pictures (I tested in my index.php in the default twentyten theme). You don’t need Exec-PHP or anything else.

    posted in the following areas

    functions.php ( My Theme Functions )
    single.php ( My Single Post )
    and
    index.php ( My Main Index Template )

    I posted program at the very bottom and when I use the call to the function on my home page and I wasnt able to call my top rated images

    I also posted in the following areas

    page.php
    and
    page-with-sidebar.php

    and I still can’t call the function.

Viewing 15 replies - 16 through 30 (of 47 total)
  • The topic ‘[Plugin: NextGEN Gallery Voting] Need help displaying the top voted images’ is closed to new replies.