Arthemia Premium: Fix for Random Posts

Arthemia Premium: Fix for Random Posts

If you’re using the Arthemia Premium WordPress theme, then you may have come across this problem: The “Random Posts / Video” footer you can choose to have at the bottom of some of your pages assumes that ALL of your posts have thumbnails available. The problem I have is that a lot of my older posts don’t, so I dont get twelve neat little thumbnails – in most cases I get less than twelve.

There are a number of ways to fix this. The problem is simply that the code as it’s written only selects twelve posts at random, regardless of whether they have thumbnails or not. The simplest fix is to modify the code to retrieve more than twelve posts, then discard the ones that don’t have thumbnails. It’s a bit of a botch solution though. A better approach would be to modify the initial SQL query to only retrieve posts that have thumnails – but that’s a little more complicated than it first appears. Also, you could modify the code below to not discard posts, but detect when no thumbnail is available, and offer a generic thumnail instead. Whatever floats your boat – I found the first solution works just fine for me ;o)

Note that this modification only works if you’re using the custom “Image” field to manage your thumbnails in Arthemia. If you’re using the “First Image” option, then this code won’t fix the problem.

Locate your “footer.php” file within your “arthemia-premium” theme, and change the code as follows at around line 24:

ORIGINAL CODE:

get_results("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY RAND() LIMIT 6"); 

	foreach ($randompost as $post) {
		$ID = $post->ID;
		$postid = get_post($post->ID);
		$title = $postid->post_title;
		$values = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $ID AND meta_key = 'Image' ");
		?>	

etc ...

MODIFIED CODE:

get_results("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY RAND() LIMIT 24");

	$iCount = 0;
	foreach ($randompost as $post) {
		$ID = $post->ID;
		$postid = get_post($post->ID);
		$title = $postid->post_title;
		$values = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $ID AND meta_key = 'Image' ");

		if ($values != "") { $iCount += 1; }

		if ($iCount == 13) { break; }
		?>	

etc ....

Make sure you change the SQL query to retrieve more than 12 posts. I’ve set it to 24 (“LIMIT 24”), which works for me. If you have a higher percentage of posts without thumbnails, you may wish to increase this – or consider the other options I mentioned above.

So there you go :o)