Jump to content

Help! Wordpress problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
jasoncdu

jasoncdu

    Newbie

  • Members
  • Pip
  • 2 posts
Hey, everyone, before I being I would just like you all to know I'm pretty much a html / php noob.

Now, first go here: bandeq(DOT)com/taiwan/

The area where it says 'Popular this month', is currently not showing anything although it is supposed to show the posts with the most views. It was working fine before - untill I updated the plugin to post view PLUS. Now it just shows N/A as the output.


Here is the code for the sidebar

<li>

<h3 class="sidebartitle"><?php _e('Popular This Month'); ?></h3>

<?php if(function_exists('get_most_viewed')): ?>

  <ul> <?php get_most_viewed(); ?></ul>

<?php endif; ?> </li>


</ul>

</div>

<?php endif; ?>

</div>

<!--/sidebar -->

And here is the code for the function

// Function: Display Most Viewed Page/Post

if( !function_exists('get_most_viewed') ) {

	function get_most_viewed($mode='', $limit=10, $chars=0, $display=true, $with_bot=true) {

		global $wpdb, $post;

		$output_format = get_settings('PV+_option');

		if( $mode=='post' ) {

			$where = "p.post_type = 'post'";

		} elseif( $mode=='page' ) {

			$where = "p.post_type = 'page'";

		} else {

			$where = "(p.post_type = 'post' OR p.post_type = 'page')";

		}

		if( $with_bot ) {

			$most_viewed = $wpdb->get_results("SELECT p.ID, p.post_title, p.post_name, p.post_status, p.post_date, (CAST(pm1.meta_value AS UNSIGNED) + CAST(pm2.meta_value AS UNSIGNED)) AS views FROM ".$wpdb->posts." AS p LEFT JOIN ".$wpdb->postmeta." AS pm1 ON pm1.post_id = p.ID LEFT JOIN ".$wpdb->postmeta." AS pm2 ON pm2.post_id = p.ID WHERE p.post_date < '".current_time('mysql')."' AND p.post_status = 'publish' AND ".$where." AND pm1.meta_key = 'views' AND pm2.meta_key = 'bot_views' AND p.post_password = '' ORDER BY views DESC LIMIT ".$limit);

			$output_format = $output_format['mostviewsbot'];

		} else {

			$most_viewed = $wpdb->get_results("SELECT p.ID, p.post_title, p.post_name, p.post_status, p.post_date, CAST(pm.meta_value AS UNSIGNED) AS views FROM ".$wpdb->posts." AS p LEFT JOIN ".$wpdb->postmeta." AS pm ON pm.post_id = p.ID WHERE p.post_date < '".current_time('mysql')."' AND p.post_status = 'publish' AND ".$where." AND pm.meta_key = 'views' AND p.post_password = '' ORDER BY views DESC LIMIT ".$limit);

			$output_format = $output_format['mostviewsnobot'];

		}

		if( $most_viewed ) {

			$output = '';

			foreach($most_viewed as $post) {

				$post_title = $post->post_title;

				$post_views = number_format(intval($post->views));

				$link = '<a href="'.get_permalink().'">'.snippet_chars($post_title, $chars).'</a>';

				$output .= '<li>'.sprintf($output_format,$post_views,$link).'</li>'."\n";

			}

		} else {

			$output = '<li>'.__('N/A', 'wp-postviews_plus').'</li>';

		}

		if( $display ) {

			echo $output;

		} else {

			return $output;

		}

	}

}


Now my question is: what would I have to do / what code would I have to change / replace so that the output is actually shown?

Hope that makes sense and sorry about the stretched screen ..

Thanks in advanced,
Jason

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
So if( $most_viewed ) {
is false then your else statement gets executed which prints $output = '<li>'.__('N/A', 'wp-postviews_plus').'</li>'; or "N/A", right? If so, that means your database code is incorrect and fetching no rows. Try adding

error_reporting(E_ALL);
to the top of your script and see if you receive any notices.

#3
jasoncdu

jasoncdu

    Newbie

  • Members
  • Pip
  • 2 posts
Hmm .. sorry Jordan, but your method didn't work. It just created alot and alot of php errors. The problem has changed now .. take a look Here It now displays the most viewed posts, but it doesn't show the title. Instead it just shows " ... " Can anyone tell me why this is happening? and possibily the solution.

Thanks,
Jason

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
What I told you to add was a method of turning errors on so you could see what errors occurred. You should leave that set while debugging and resolve all PHP errors that you see/get.