Tag Archive for wordpress

List upcoming Events in Sidebar via PHP Code Widget

<?php $today = date ('Y-m-d'); ?>
<?php query_posts('cat=6&showposts=5&meta_key=event_date&meta_compare=>=&meta_value='.$today.'&orderby=meta_value&order=ASC'); ?>
<?php if ( have_posts() ) : ?>
  <ul>
  <?php while ( have_posts() ) : the_post(); ?>
   	<li class="cat-post-item"><a class="post-title" title="Permalink to <?php the_title() ?>" rel="bookmark" href="<?php the_permalink() ?>"><?php the_title() ?></a></li>   
  <?php endwhile; ?>
  </ul>
<?php endif; wp_reset_query(); ?>

source

WordPress – show top 10 tags by usage

<?php
function top_tags() {
	$tags = get_tags();

	if (empty($tags))
		return;

	$counts = $tag_links = array();
	foreach ( (array) $tags as $tag ) {
		$counts[$tag->name] = $tag->count;
		$tag_links[$tag->name] = get_tag_link( $tag->term_id );
	}

	asort($counts);
	$counts = array_reverse( $counts, true );

	$i = 0;
	foreach ( $counts as $tag => $count ) {
		$i++;
		$tag_link = clean_url($tag_links[$tag]);
		$tag = str_replace(' ', '&nbsp;', wp_specialchars( $tag ));
		if($i < 11){
			print "<li><a href="$tag_link">$tag ($count)</a></li>";
		}
	}
}
?>
<h4>Top tags</h4>
<ul>
<?php
top_tags();
?>
</ul>

source

Remove Dashboard Widgets

<?php 
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' );
?>

source

Remove Encoded Spans From SlideDeck Title

jQuery('.slidedeck dt').each(function(){
	this.innerHTML = this.innerHTML.replace(/&lt;(.*)&gt;(.*)&lt;(.*)&gt;/,'$2'); 
});

source

Better Pagination

/******* BETTER PAGINATION *********/

function pagination( $query, $baseURL ) {
	$page = $query->query_vars["paged"];
	if ( !$page ) $page = 1;
	$qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : "";
	// Only necessary if there's more posts than posts-per-page
	if ( $query->found_posts > $query->query_vars["posts_per_page"] ) {
		echo '<ul class="paging">';
		// Previous link?
		if ( $page > 1 ) {
			echo '<li class="previous"><a href="'.$baseURL.'page/'.($page-1).'/'.$qs.'">&laquo; previous</a></li>';
		}
		// Loop through pages
		for ( $i=1; $i <= $query->max_num_pages; $i++ ) {
			// Current page or linked page?
			if ( $i == $page ) {
				echo '<li class="active">'.$i.'</li>';
			} else {
				echo '<li><a href="'.$baseURL.'page/'.$i.'/'.$qs.'">'.$i.'</a></li>';
			}
		}
		// Next link?
		if ( $page < $query->max_num_pages ) {
			echo '<li><a href="'.$baseURL.'page/'.($page+1).'/'.$qs.'">next &raquo;</a></li>';
		}
		echo '</ul>';
	}
}

source

Custom Post Type: Board Of Directors

/******* CUSTOM POST TYPE: BOARD OF DIRECTORS *********/

add_action('init', 'bod_register');

function bod_register() {
	$args = array(
		'label' => __('Board of Directors'),
		'singular_label' => __('Board Member'),
		'public' => true,
		'show_ui' => true,
		'capability_type' => 'post',
		'hierarchical' => false,
		'rewrite' => true,
		'supports' => array('title', 'thumbnail')
	);

	register_post_type( 'board-member' , $args );
}

	add_action("admin_init", "bod_admin_init");
	add_action('save_post', 'save_bod_meta');

	function bod_admin_init(){
		add_meta_box("bod_meta", "Board Member Options", "bod_meta_options", "board-member", "normal", "core");
	}

	function bod_meta_options(){
		global $post;
		$custom = get_post_custom($post->ID);
		$bod_suffix = $custom["bod_suffix"][0];
		$bod_position = $custom["bod_position"][0];
	
?>
	<div style="float:left;padding:5px 15px;">
		<label for="bod_suffix">Suffix </label>
		<input type="text" name="bod_suffix" size="20" autocomplete="on" value="<?php echo $bod_suffix; ?>">
	</div>
	<div style="float:left;padding:5px 15px;">
		<label for="bod_position">Position </label>
		<input type="text" name="bod_position" size="30" autocomplete="on" value="<?php echo $bod_position; ?>">
	</div>
	<p>&nbsp;</p>
	<p>&nbsp;</p>
<?php
	}

function save_bod_meta(){
	global $post;
	update_post_meta($post->ID, "bod_suffix", $_POST["bod_suffix"]);
	update_post_meta($post->ID, "bod_position", $_POST["bod_position"]);
}

add_filter("manage_edit-board-member_columns", "bod_edit_columns");
add_action("manage_posts_custom_column",  "bod_custom_columns");

function bod_edit_columns($columns){
		$columns = array(
			"cb" => "<input type="checkbox" />",
			"title" => "Name",
			"bod_suffix" => "Suffix",
			"bod_position" => "Position",
			"bod_image" => "Featured Image"
		);

		return $columns;
}

function bod_custom_columns($column){
		global $post;
		switch ($column)
		{
			case "bod_suffix":
				$custom = get_post_custom();
				echo $custom["bod_suffix"][0];
				break;
			case "bod_position":
				$custom = get_post_custom();
				echo $custom["bod_position"][0];
				break;
			case "bod_image":
				$sl_thumb = get_thumbnail($post->ID,"60","75");
				echo "<img src="". $sl_thumb ."" />";
				break;
		}
}

source

Show/Hide Content Based On User Role in WordPress

<?php if (is_user_logged_in() ) { //only logged in user can see this ?>
<div><p>You are logged in!</p></div>
<?php } ?>

<?php if ( current_user_can( 'delete_others_posts' ) ) { //only admins and editors can see this ?>
   <p>You are an admin</p>
<?php } else { ?>
   <p>You are not an admin</p>
<?php } ?>

source

Previous / Next page links for WordPress

<?php				
/* prev/next links */
if ($post->post_parent == 19) { /* 19 == id of 'Rooms' page */
$exclude = implode(',',array('984'));

$toplevel = 'title_li=&depth=1&echo=0&exclude='.$exclude;
$siblings = $toplevel.'&child_of='.$post->post_parent;
if (function_exists(pause_exclude_pages)) {
 pause_exclude_pages();
 $links =  ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel);
 resume_exclude_pages();
}
else {
 $links =  ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel);
}

$links = array_filter(explode("</li>",$links));

foreach($links as $k=>$v) { if (strpos($v,'current_page_item') !== FALSE) { $current = $k;   } $links[$k] = $v.'</li>';}

$total = count($links)-1;   $prev = (int)$current-1; $next = $current+1;

if ($current == $total) $next = '0'; // if you're on the last page, next will be the first
if ($current == '0') $prev = $total; // if you're on the first page, prev will be the last

$prevLink = strip_tags($links[$prev],'<a>'); //remove the <li> tags
$nextLink = strip_tags($links[$next],'<a>'); //remove the <li> tags

function change_anchor_text($link, $newtext, $placement) {
	$pos1 = strpos($link, '>')+1;
	$pos2 = strpos($link, '<', 1);
	$anchortext = substr($link, $pos1, $pos2-$pos1);
	
	if($placement == 'before') {
	 return str_replace($anchortext, $newtext.' '.$anchortext, $link);
	}
	else if ($placement == 'after') {
	 return str_replace($anchortext, $anchortext.' '.$newtext, $link);
	}
	else if ($placement == 'replace') {
	 return str_replace($anchortext, $newtext, $link);
	}
	
}
$prevLinkb = $prevLink;
$prevLink = change_anchor_text($prevLink, ' &lt; View Previous Room ', 'replace'); /* link customization goes here */
$nextLink = change_anchor_text($nextLink, ' View Next Room &gt; ', 'replace');
$prepend = '';
$separator = '<a href="/lodging/" class="norm">Return to All Rooms</a>';
$separator2 = '<a href="#" class="norm">Check Availability Online</a>';

echo '<p class="pnpn">'.$prepend.$prevLink.$separator.$nextLink.'</p>';

}
/* end prev/next links */ 
?>

source

WordPress Archives Basic

<ul><?php wp_get_archives('type=monthly'); ?></ul>

source

Javascript HTML

<script type="text/javascript" src="/wp-content/themes/PlanetLabel2/script.js"></script>

source