Forum Replies Created

Viewing 15 replies - 1 through 15 (of 18 total)
  • BunnyBomb

    saved me hours

    function ucc_get_calendar($initial = true, $echo = true) {
    	global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    	$cache = array();
    	$key = md5( $m . $monthnum . $year );
    /*	if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
    		if ( is_array($cache) && isset( $cache[ $key ] ) ) {
    			if ( $echo ) {
    				echo apply_filters( 'get_calendar',  $cache[$key] );
    				return;
    			} else {
    				return apply_filters( 'get_calendar',  $cache[$key] );
    			}
    		}
    	}*/
    
    	if ( !is_array($cache) )
    		$cache = array();
    
    	// Quick check. If we have no posts at all, abort!
    	if ( !$posts ) {
    		$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
    		if ( !$gotsome ) {
    			$cache[ $key ] = '';
    			wp_cache_set( 'get_calendar', $cache, 'calendar' );
    			return;
    		}
    	}
    
    	if ( isset($_GET['w']) )
    		$w = ''.intval($_GET['w']);
    
    	// week_begins = 0 stands for Sunday
    	$week_begins = intval(get_option('start_of_week'));
    
    	// Let's figure out when we are
    	if ( !empty($monthnum) && !empty($year) ) {
    		$thismonth = ''.zeroise(intval($monthnum), 2);
    		$thisyear = ''.intval($year);
    	} elseif ( !empty($w) ) {
    		// We need to get the month from MySQL
    		$thisyear = ''.intval(substr($m, 0, 4));
    		$d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
    		$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
    	} elseif ( !empty($m) ) {
    		$thisyear = ''.intval(substr($m, 0, 4));
    		if ( strlen($m) < 6 )
    				$thismonth = '01';
    		else
    				$thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
    	} else {
    		$thisyear = gmdate('Y', current_time('timestamp'));
    		$thismonth = gmdate('m', current_time('timestamp'));
    	}
    	$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
    	$last_day = date('t', $unixmonth);
    
    	// Get the next and previous month and year with at least one post
    	$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    		FROM $wpdb->posts
    		WHERE post_date < '$thisyear-$thismonth-01'
    		AND post_type = 'post' AND post_status = 'publish'
    			ORDER BY post_date DESC
    			LIMIT 1");
    	$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    		FROM $wpdb->posts
    		WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
    		AND post_type = 'post' AND post_status = 'publish'
    			ORDER BY post_date ASC
    			LIMIT 1");
    
    	/* translators: Calendar caption: 1: month name, 2: 4-digit year */
    	$calendar_caption = _x('%1$s %2$s', 'calendar caption');
    	$calendar_output = '<table id="wp-calendar">
    	<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
    	<thead>
    	<tr>';
    
    	$myweek = array();
    
    	for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
    		$myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
    	}
    
    	foreach ( $myweek as $wd ) {
    		$day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
    		$wd = esc_attr($wd);
    		$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
    	}
    
    	$calendar_output .= '
    	</tr>
    	</thead>
    
    	<tbody>
    	<tr>';
    
    	// Get days with posts
    	$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    		FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
    		AND post_type = 'post' AND post_status = 'publish'
    		AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
    	if ( $dayswithposts ) {
    		foreach ( (array) $dayswithposts as $daywith ) {
    			$daywithpost[] = $daywith[0];
    		}
    	} else {
    		$daywithpost = array();
    	}
    
    	if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
    		$ak_title_separator = "\n";
    	else
    		$ak_title_separator = ', ';
    
    	$ak_titles_for_day = array();
    	$ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
    		."FROM $wpdb->posts "
    		."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
    		."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
    		."AND post_type = 'post' AND post_status = 'publish'"
    	);
    	if ( $ak_post_titles ) {
    		foreach ( (array) $ak_post_titles as $ak_post_title ) {
    
    				$post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
    
    				if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
    					$ak_titles_for_day['day_'.$ak_post_title->dom] = '';
    				if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
    					$ak_titles_for_day["$ak_post_title->dom"] = $post_title;
    				else
    					$ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
    		}
    	}
    
    	// See how much we should pad in the beginning
    	$pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
    	if ( 0 != $pad )
    		$calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
    
    	$daysinmonth = intval(date('t', $unixmonth));
    	for ( $day = 1; $day <= $daysinmonth; ++$day ) {
    		if ( isset($newrow) && $newrow )
    			$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
    		$newrow = false;
    
    		if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
    			$calendar_output .= '<td id="today">';
    		else
    			$calendar_output .= '<td>';
    
    		if ( in_array($day, $daywithpost) ) // any posts today?
    				$calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
    		else
    			$calendar_output .= $day;
    		$calendar_output .= '</td>';
    
    		if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
    			$newrow = true;
    	}
    
    	$pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
    	if ( $pad != 0 && $pad != 7 )
    		$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
    
    	$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
    
    	$thismonth = ''.zeroise(intval($thismonth - 1), 2);
    	if ($thismonth == '0'){
    		$thismonth = 12;
    		$thisyear = intval($thisyear - 1);
    	}
    //	die('fdgfddgfdgfdgf         '.$thismonth);
    	$thatmonth = $thismonth - 1;
    	$thatyear = $thisyear;
    	if ($thatmonth == '0'){
    		$thatmonth = 12;
    		$thatyear = intval($thisyear - 1);
    	}
    	$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
    	$last_day = date('t', $unixmonth);
    	// Get the next and previous month and year with at least one post
    	$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    		FROM $wpdb->posts
    		WHERE post_date < '$thisyear-$thismonth-01'
    		AND post_type = 'post' AND post_status = 'publish'
    			ORDER BY post_date DESC
    			LIMIT 1");
    	$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    		FROM $wpdb->posts
    		WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
    		AND post_type = 'post' AND post_status = 'publish'
    			ORDER BY post_date ASC
    			LIMIT 1");
    
    	/* translators: Calendar caption: 1: month name, 2: 4-digit year */
    	$calendar_caption = _x('%1$s %2$s', 'calendar caption');
    	$calendar_output .= '<table id="wp-calendar">
    	<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
    	<thead>
    	<tr>';
    
    	$myweek = array();
    
    	for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
    		$myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
    	}
    
    	foreach ( $myweek as $wd ) {
    		$day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
    		$wd = esc_attr($wd);
    		$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
    	}
    
    	$calendar_output .= '
    	</tr>
    	</thead>
    
    	<tfoot>
    	<tr>';
    
    	if ( $previous ) {
    		$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
    	} else {
    		$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    	}
    
    	$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
    
    	if ( $next ) {
    		$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
    	} else {
    		$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
    	}
    
    	$calendar_output .= '
    	</tr>
    	</tfoot>
    
    	<tbody>
    	<tr>';
    
    	// Get days with posts
    	$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    		FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
    		AND post_type = 'post' AND post_status = 'publish'
    		AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
    	if ( $dayswithposts ) {
    		foreach ( (array) $dayswithposts as $daywith ) {
    			$daywithpost[] = $daywith[0];
    		}
    	} else {
    		$daywithpost = array();
    	}
    
    	if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
    		$ak_title_separator = "\n";
    	else
    		$ak_title_separator = ', ';
    
    	$ak_titles_for_day = array();
    	$ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
    		."FROM $wpdb->posts "
    		."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
    		."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
    		."AND post_type = 'post' AND post_status = 'publish'"
    	);
    	if ( $ak_post_titles ) {
    		foreach ( (array) $ak_post_titles as $ak_post_title ) {
    
    				$post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
    
    				if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
    					$ak_titles_for_day['day_'.$ak_post_title->dom] = '';
    				if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
    					$ak_titles_for_day["$ak_post_title->dom"] = $post_title;
    				else
    					$ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
    		}
    	}
    
    	// See how much we should pad in the beginning
    	$pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
    	if ( 0 != $pad )
    		$calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
    
    	$daysinmonth = intval(date('t', $unixmonth));
    	for ( $day = 1; $day <= $daysinmonth; ++$day ) {
    		if ( isset($newrow) && $newrow )
    			$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
    		$newrow = false;
    
    		if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
    			$calendar_output .= '<td id="today">';
    		else
    			$calendar_output .= '<td>';
    
    		if ( in_array($day, $daywithpost) ) // any posts today?
    				$calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
    		else
    			$calendar_output .= $day;
    		$calendar_output .= '</td>';
    
    		if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
    			$newrow = true;
    	}
    
    	$pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
    	if ( $pad != 0 && $pad != 7 )
    		$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
    
    	$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
    
    	$cache[ $key ] = $calendar_output;
    	wp_cache_set( 'get_calendar', $cache, 'calendar' );
    
    	if ( $echo )
    		echo $calendar_output;
    	else
    		return $calendar_output;
    
    }
    
    function ucc_get_calendar_filter( $content ) {
      $output = ucc_get_calendar();
      return $output;
    }
    add_filter( 'get_calendar' , 'ucc_get_calendar_filter' , 10 , 2 );

    nvm that doesnt work ??

    decide if you need the next and prev links to still work,
    by default i understand you want this months and previous months posts in calendar form, but do you want previous button to be below them so they can see previous two months if they click it, and then go forwards or keep going back until no more posts?

    <?php query_posts('post_status=publish&posts_per_page=3&post_type=post');?>
    		<div id="container">
    <div id="content">
    <?php if ( ! have_posts() ) : ?>
    	<div id="post-0" class="post error404 not-found">
    		<h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
    		<div class="entry-content">
    			<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p>
    			<?php get_search_form(); ?>
    		</div><!-- .entry-content -->
    	</div><!-- #post-0 -->
    <?php endif; ?>
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<p><?php the_time('F j, Y \a\t g:i') ?></p>
    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
    	<p><?php the_excerpt(); ?></p>
    	<?php endwhile; else: endif; ?>
    		</div></div><!-- #container -->

    I’m not sure but I believe this is caused by saving header.php with the wrong encoding.

    open header.php with notepad.exe or similar plain text editor, replace the question mark character with &eacute; and do save as header.php with utf-8 encoding.

    You could post header.php’s contents to pastebin or similar site and I’ll make changes and re-post

    I see the diamonds with question mark inside.
    What program are you using to edit header.php?

    Do you have the url of the live site?
    What browser are you using?
    I couldn’t replicate the problem you’re experiencing

    <META NAME="DESCRIPTION" CONTENT="&eacute;&eacute;&eacute;&eacute;&eacute;Your keyword rich marketing sales-pitch meta description goes here">
    <META NAME="KEYWORDS" CONTENT="&eacute;&eacute;&eacute;&eacute;&eacute;your keywords,go here,separated by a comma,but not a space">

    shows up as the following when viewing source for me

    <meta content="éééééYour keyword rich marketing sales-pitch meta description goes here" name="DESCRIPTION">
    <meta content="ééééyour keywords,go here,separated by a comma,but not a space" name="KEYWORDS">

    https://www.ads-software.com/extend/plugins/custom-login-redirect/

    https://www.longren.org/wordpress-tip-redirect-to-previous-page-after-login/

    if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) {
    	add_filter('login_redirect', 'my_login_redirect', 10, 3);
    	function my_login_redirect() {
    		$location = $_SERVER['HTTP_REFERER'];
    		wp_safe_redirect($location);
    		exit();
    	}
    }

    Tested this one, works for sure:

    function modify_fields_required_marker($fields) {
    $commenter = wp_get_current_commenter();
    $req = get_option( 'require_name_email' );
    $aria_req = ( $req ? " aria-required='true'" : '' );
    $fields['author'] = '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required"> (Required)</span>' : '' ) .
    		         '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
    $fields['email'] = '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required"> (Required)</span>' : '' ) .
    		         '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>';
    $fields['url'] = '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
    		         '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>';
    return $fields;
    }
    add_filter('comment_form_default_fields','modify_fields_required_marker');

    This will update every month so the the calendar is always of the previous month

    step 1 make copy of get_calendar function

    step 2 add a filter and a callback function (ucc_get_calendar_filter)

    the filter says to wordpress when get_calendar function is called do ucc_get_calendar instead

    here’s code that makes it previous month instead of current one

    $thismonth = ''.zeroise(intval($thismonth - 1), 2);
    	if ($thismonth == '0'){
    		$thismonth = 12;
    		$thisyear = intval($thisyear - 1);
    	}

    and everything together:

    function ucc_get_calendar($initial = true, $echo = true) {
    	global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    	$cache = array();
    	$key = md5( $m . $monthnum . $year );
    /*	if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
    		if ( is_array($cache) && isset( $cache[ $key ] ) ) {
    			if ( $echo ) {
    				echo apply_filters( 'get_calendar',  $cache[$key] );
    				return;
    			} else {
    				return apply_filters( 'get_calendar',  $cache[$key] );
    			}
    		}
    	}*/
    
    	if ( !is_array($cache) )
    		$cache = array();
    
    	// Quick check. If we have no posts at all, abort!
    	if ( !$posts ) {
    		$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
    		if ( !$gotsome ) {
    			$cache[ $key ] = '';
    			wp_cache_set( 'get_calendar', $cache, 'calendar' );
    			return;
    		}
    	}
    
    	if ( isset($_GET['w']) )
    		$w = ''.intval($_GET['w']);
    
    	// week_begins = 0 stands for Sunday
    	$week_begins = intval(get_option('start_of_week'));
    
    	// Let's figure out when we are
    	if ( !empty($monthnum) && !empty($year) ) {
    		$thismonth = ''.zeroise(intval($monthnum), 2);
    		$thisyear = ''.intval($year);
    	} elseif ( !empty($w) ) {
    		// We need to get the month from MySQL
    		$thisyear = ''.intval(substr($m, 0, 4));
    		$d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
    		$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
    	} elseif ( !empty($m) ) {
    		$thisyear = ''.intval(substr($m, 0, 4));
    		if ( strlen($m) < 6 )
    				$thismonth = '01';
    		else
    				$thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
    	} else {
    		$thisyear = gmdate('Y', current_time('timestamp'));
    		$thismonth = gmdate('m', current_time('timestamp'));
    	}
    	$thismonth = ''.zeroise(intval($thismonth - 1), 2);
    	if ($thismonth == '0'){
    		$thismonth = 12;
    		$thisyear = intval($thisyear - 1);
    	}
    //	die('fdgfddgfdgfdgf         '.$thismonth);
    	$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
    	$last_day = date('t', $unixmonth);
    
    	// Get the next and previous month and year with at least one post
    	$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    		FROM $wpdb->posts
    		WHERE post_date < '$thisyear-$thismonth-01'
    		AND post_type = 'post' AND post_status = 'publish'
    			ORDER BY post_date DESC
    			LIMIT 1");
    	$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    		FROM $wpdb->posts
    		WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
    		AND post_type = 'post' AND post_status = 'publish'
    			ORDER BY post_date ASC
    			LIMIT 1");
    
    	/* translators: Calendar caption: 1: month name, 2: 4-digit year */
    	$calendar_caption = _x('%1$s %2$s', 'calendar caption');
    	$calendar_output = '<table id="wp-calendar">
    	<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
    	<thead>
    	<tr>';
    
    	$myweek = array();
    
    	for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
    		$myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
    	}
    
    	foreach ( $myweek as $wd ) {
    		$day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
    		$wd = esc_attr($wd);
    		$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
    	}
    
    	$calendar_output .= '
    	</tr>
    	</thead>
    
    	<tfoot>
    	<tr>';
    
    	if ( $previous ) {
    		$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
    	} else {
    		$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    	}
    
    	$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
    
    	if ( $next ) {
    		$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
    	} else {
    		$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
    	}
    
    	$calendar_output .= '
    	</tr>
    	</tfoot>
    
    	<tbody>
    	<tr>';
    
    	// Get days with posts
    	$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    		FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
    		AND post_type = 'post' AND post_status = 'publish'
    		AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
    	if ( $dayswithposts ) {
    		foreach ( (array) $dayswithposts as $daywith ) {
    			$daywithpost[] = $daywith[0];
    		}
    	} else {
    		$daywithpost = array();
    	}
    
    	if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
    		$ak_title_separator = "\n";
    	else
    		$ak_title_separator = ', ';
    
    	$ak_titles_for_day = array();
    	$ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
    		."FROM $wpdb->posts "
    		."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
    		."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
    		."AND post_type = 'post' AND post_status = 'publish'"
    	);
    	if ( $ak_post_titles ) {
    		foreach ( (array) $ak_post_titles as $ak_post_title ) {
    
    				$post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
    
    				if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
    					$ak_titles_for_day['day_'.$ak_post_title->dom] = '';
    				if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
    					$ak_titles_for_day["$ak_post_title->dom"] = $post_title;
    				else
    					$ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
    		}
    	}
    
    	// See how much we should pad in the beginning
    	$pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
    	if ( 0 != $pad )
    		$calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
    
    	$daysinmonth = intval(date('t', $unixmonth));
    	for ( $day = 1; $day <= $daysinmonth; ++$day ) {
    		if ( isset($newrow) && $newrow )
    			$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
    		$newrow = false;
    
    		if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
    			$calendar_output .= '<td id="today">';
    		else
    			$calendar_output .= '<td>';
    
    		if ( in_array($day, $daywithpost) ) // any posts today?
    				$calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
    		else
    			$calendar_output .= $day;
    		$calendar_output .= '</td>';
    
    		if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
    			$newrow = true;
    	}
    
    	$pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
    	if ( $pad != 0 && $pad != 7 )
    		$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
    
    	$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
    
    	$cache[ $key ] = $calendar_output;
    	wp_cache_set( 'get_calendar', $cache, 'calendar' );
    
    	if ( $echo )
    		echo $calendar_output;
    	else
    		return $calendar_output;
    
    }
    
    function ucc_get_calendar_filter( $content ) {
      $output = ucc_get_calendar();
      return $output;
    }
    add_filter( 'get_calendar' , 'ucc_get_calendar_filter' , 10 , 2 );

    Maybe this is what you’re looking for?

    <?php
    function comment_form_fixer($content){
    return str_replace('*', ' (Required)', $content);
    }
    add_filter('comment_form', 'comment_form_fixer');
    ?>

    Forum: Hacks
    In reply to: Animated menu

    https://core.trac.www.ads-software.com/browser/tags/3.3.1/wp-includes/general-template.php
    make a copy of the get_calendar function and name it something else and put it in your active theme’s function.php file. Modify the function to get the previous month’s posts: subtract 1 from $monthnum, if $monthnum = 0 then set it to 12 and subtract 1 from year

    1074	function get_calendar($initial = true, $echo = true) {
    1075	        global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    1076
    1077	        $cache = array();
    1078	        $key = md5( $m . $monthnum . $year );
    1079	        if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
    1080	                if ( is_array($cache) && isset( $cache[ $key ] ) ) {
    1081	                        if ( $echo ) {
    1082	                                echo apply_filters( 'get_calendar',  $cache[$key] );
    1083	                                return;
    1084	                        } else {
    1085	                                return apply_filters( 'get_calendar',  $cache[$key] );
    1086	                        }
    1087	                }
    1088	        }
    1089
    1090	        if ( !is_array($cache) )
    1091	                $cache = array();
    1092
    1093	        // Quick check. If we have no posts at all, abort!
    1094	        if ( !$posts ) {
    1095	                $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
    1096	                if ( !$gotsome ) {
    1097	                        $cache[ $key ] = '';
    1098	                        wp_cache_set( 'get_calendar', $cache, 'calendar' );
    1099	                        return;
    1100	                }
    1101	        }
    1102
    1103	        if ( isset($_GET['w']) )
    1104	                $w = ''.intval($_GET['w']);
    1105
    1106	        // week_begins = 0 stands for Sunday
    1107	        $week_begins = intval(get_option('start_of_week'));
    1108
    1109	        // Let's figure out when we are
    1110	        if ( !empty($monthnum) && !empty($year) ) {
    1111	                $thismonth = ''.zeroise(intval($monthnum), 2);
    1112	                $thisyear = ''.intval($year);
    1113	        } elseif ( !empty($w) ) {
    1114	                // We need to get the month from MySQL
    1115	                $thisyear = ''.intval(substr($m, 0, 4));
    1116	                $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
    1117	                $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
    1118	        } elseif ( !empty($m) ) {
    1119	                $thisyear = ''.intval(substr($m, 0, 4));
    1120	                if ( strlen($m) < 6 )
    1121	                                $thismonth = '01';
    1122	                else
    1123	                                $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
    1124	        } else {
    1125	                $thisyear = gmdate('Y', current_time('timestamp'));
    1126	                $thismonth = gmdate('m', current_time('timestamp'));
    1127	        }
    1128
    1129	        $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
    1130	        $last_day = date('t', $unixmonth);
    1131
    1132	        // Get the next and previous month and year with at least one post
    1133	        $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    1134	                FROM $wpdb->posts
    1135	                WHERE post_date < '$thisyear-$thismonth-01'
    1136	                AND post_type = 'post' AND post_status = 'publish'
    1137	                        ORDER BY post_date DESC
    1138	                        LIMIT 1");
    1139	        $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    1140	                FROM $wpdb->posts
    1141	                WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
    1142	                AND post_type = 'post' AND post_status = 'publish'
    1143	                        ORDER BY post_date ASC
    1144	                        LIMIT 1");
    1145
    1146	        /* translators: Calendar caption: 1: month name, 2: 4-digit year */
    1147	        $calendar_caption = _x('%1$s %2$s', 'calendar caption');
    1148	        $calendar_output = '<table id="wp-calendar">
    1149	        <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
    1150	        <thead>
    1151	        <tr>';
    1152
    1153	        $myweek = array();
    1154
    1155	        for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
    1156	                $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
    1157	        }
    1158
    1159	        foreach ( $myweek as $wd ) {
    1160	                $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
    1161	                $wd = esc_attr($wd);
    1162	                $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
    1163	        }
    1164
    1165	        $calendar_output .= '
    1166	        </tr>
    1167	        </thead>
    1168
    1169	        <tfoot>
    1170	        <tr>';
    1171
    1172	        if ( $previous ) {
    1173	                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
    1174	        } else {
    1175	                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    1176	        }
    1177
    1178	        $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
    1179
    1180	        if ( $next ) {
    1181	                $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
    1182	        } else {
    1183	                $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
    1184	        }
    1185
    1186	        $calendar_output .= '
    1187	        </tr>
    1188	        </tfoot>
    1189
    1190	        <tbody>
    1191	        <tr>';
    1192
    1193	        // Get days with posts
    1194	        $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    1195	                FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
    1196	                AND post_type = 'post' AND post_status = 'publish'
    1197	                AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
    1198	        if ( $dayswithposts ) {
    1199	                foreach ( (array) $dayswithposts as $daywith ) {
    1200	                        $daywithpost[] = $daywith[0];
    1201	                }
    1202	        } else {
    1203	                $daywithpost = array();
    1204	        }
    1205
    1206	        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
    1207	                $ak_title_separator = "\n";
    1208	        else
    1209	                $ak_title_separator = ', ';
    1210
    1211	        $ak_titles_for_day = array();
    1212	        $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
    1213	                ."FROM $wpdb->posts "
    1214	                ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
    1215	                ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
    1216	                ."AND post_type = 'post' AND post_status = 'publish'"
    1217	        );
    1218	        if ( $ak_post_titles ) {
    1219	                foreach ( (array) $ak_post_titles as $ak_post_title ) {
    1220
    1221	                                $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
    1222
    1223	                                if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
    1224	                                        $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
    1225	                                if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
    1226	                                        $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
    1227	                                else
    1228	                                        $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
    1229	                }
    1230	        }
    1231
    1232
    1233	        // See how much we should pad in the beginning
    1234	        $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
    1235	        if ( 0 != $pad )
    1236	                $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
    1237
    1238	        $daysinmonth = intval(date('t', $unixmonth));
    1239	        for ( $day = 1; $day <= $daysinmonth; ++$day ) {
    1240	                if ( isset($newrow) && $newrow )
    1241	                        $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
    1242	                $newrow = false;
    1243
    1244	                if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
    1245	                        $calendar_output .= '<td id="today">';
    1246	                else
    1247	                        $calendar_output .= '<td>';
    1248
    1249	                if ( in_array($day, $daywithpost) ) // any posts today?
    1250	                                $calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
    1251	                else
    1252	                        $calendar_output .= $day;
    1253	                $calendar_output .= '</td>';
    1254
    1255	                if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
    1256	                        $newrow = true;
    1257	        }
    1258
    1259	        $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
    1260	        if ( $pad != 0 && $pad != 7 )
    1261	                $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
    1262
    1263	        $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
    1264
    1265	        $cache[ $key ] = $calendar_output;
    1266	        wp_cache_set( 'get_calendar', $cache, 'calendar' );
    1267
    1268	        if ( $echo )
    1269	                echo apply_filters( 'get_calendar',  $calendar_output );
    1270	        else
    1271	                return apply_filters( 'get_calendar',  $calendar_output );
    1272
    1273	}

Viewing 15 replies - 1 through 15 (of 18 total)