Wordpress fault in my sidebar (copyright bit)

Dagz

Free Member
Aug 20, 2010
221
3
Bristol
http://redwood-tints.co.uk/

Just noticed I've got a fault in my sidebar since the last update. I made the site myself a couple of years ago and am not a web designer. Is there an obvious fault here, or an easy solution?

<div class="side-box">
<ul id="copyrights">
<li>
<?php
global $wpdb;
$post_datetimes = $wpdb->get_row($wpdb->prepare("SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb->posts WHERE post_date_gmt > 1970"));
if ($post_datetimes) {
$firstpost_year = $post_datetimes->firstyear;
$lastpost_year = $post_datetimes->lastyear;
$copyright = __('Copyright &copy;&nbsp; ', 'piano-black') . $firstpost_year;
if($firstpost_year != $lastpost_year) {
$copyright .= '-'. $lastpost_year;
}
$copyright .= ' ';
echo $copyright;
}
?>
&nbsp;<a href="<?php echo get_option('home'); ?>/"><div class="org">Redwood Window Tinting</div></a></li>
<li><div class="adr">
<div class="street-address">111-117 St George's Road</div></li>
<li><span class="locality">Bristol</span></li>
<li><span class="postal-code">BS1 5UW</span></div></li>
</ul>
</div>

Thankyou.
 
Last edited by a moderator:
Upvote 0
Can you PM me the login details and I will take a look but I am guessing it's down to the code posted above.

WP has been cleaning up it's system, and the code you're using in the sidebar is probably outdated, especially since 3.4 / 3.5 has some serious updates (minimum php 5 etc)
 
Upvote 0
Hmmmmm, pretty scared about changing the theme. Is it recommended even if I can sort the fault? Cos this theme has the perfect look for me. Also, never changed the theme before, surely that's got to end up creating new issues - can't be that simple can it?

Thanks
 
Upvote 0
No need to change the theme, what I think the poster meant was to install any updates to the theme that may be available (depends where you got the theme from etc).

My offer of looking at it still stands
 
Upvote 0
If is just creating a from and to date for the copyright, which is a bit fancy but not that important.

You could just change it to copyright the current year rather than a date range and remove some database activity and speed you site up by a few micro seconds
PHP:
<div class="side-box">
<ul id="copyrights">
<li>
<?php
$copyright = __('Copyright &copy;&nbsp; ', 'piano-black') . date('Y').' ';
echo $copyright;
}
?>
&nbsp;<a href="<?php echo get_option('home'); ?>/"><div class="org">Redwood Window Tinting</div></a></li>
<li><div class="adr">
<div class="street-address">111-117 St George's Road</div></li>
<li><span class="locality">Bristol</span></li>
<li><span class="postal-code">BS1 5UW</span></div></li>
</ul>
</div>

however if you want it to work exactly as is, with the database call just get rid of the $wpdb->prepare as it isn't preparing anything (which would be the second argument that is missing)

PHP:
<div class="side-box">
<ul id="copyrights">
<li>
<?php
global $wpdb;
$post_datetimes = $wpdb->get_row("SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb->posts WHERE post_date_gmt > 1970");
if ($post_datetimes) {
$firstpost_year = $post_datetimes->firstyear;
$lastpost_year = $post_datetimes->lastyear;
$copyright = __('Copyright &copy;&nbsp; ', 'piano-black') . $firstpost_year;
if($firstpost_year != $lastpost_year) {
$copyright .= '-'. $lastpost_year;
}
$copyright .= ' ';
echo $copyright;
}
?>
&nbsp;<a href="<?php echo get_option('home'); ?>/"><div class="org">Redwood Window Tinting</div></a></li>
<li><div class="adr">
<div class="street-address">111-117 St George's Road</div></li>
<li><span class="locality">Bristol</span></li>
<li><span class="postal-code">BS1 5UW</span></div></li>
</ul>
</div>
 
Last edited:
  • Like
Reactions: Dagz
Upvote 0

Latest Articles