WordPress Post attachment MIME Types

function get_attachment_icons($echo = false){
	$sAttachmentString = "<div class='documentIconsWrapper'> \n";
	if ( $files = get_children(array(   //do only if there are attachments of these qualifications
	 'post_parent' => get_the_ID(),
	 'post_type' => 'attachment',
	 'numberposts' => -1,
	 'post_mime_type' => 'application/pdf',  //MIME Type condition
	 ))){
	 foreach( $files as $file ){ //setup array for more than one file attachment
		$file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
		$file_name_array=explode("/",$file_link);
		$file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
		$sAttachmentString .= "<div class='documentIcons'>";
		$sAttachmentString .= "<a href='$file_link'>";
		$sAttachmentString .= "<img src='".get_stylesheet_directory_uri()."/_inc/images/mime/pdf.png'/>";
		$sAttachmentString .= "</a>";
		$sAttachmentString .= "<br>";
		$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
		$sAttachmentString .= "</div>";
		}
	}
	//Word Documents
	if ( $files = get_children(array(   //do only if there are attachments of these qualifications
	 'post_parent' => get_the_ID(),
	 'post_type' => 'attachment',
	 'numberposts' => -1,
	 'post_mime_type' => 'application/msword',  //MIME Type condition
	 ))){
	 foreach( $files as $file ){ //setup array for more than one file attachment
		$file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
		$file_name_array=explode("/",$file_link);
		$file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
		$sAttachmentString .= "<div class='documentIcons'>";
		$sAttachmentString .= "<a href='$file_link'>";
		$sAttachmentString .= "<img src='".get_stylesheet_directory_uri()."/_inc/images/mime/word.png'/>";
		$sAttachmentString .= "</a>";
		$sAttachmentString .= "<br>";
		$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
		$sAttachmentString .= "</div>";
		}
	}
	//Powerpoint Documents
	if ( $files = get_children(array(   //do only if there are attachments of these qualifications
	 'post_parent' => get_the_ID(),
	 'post_type' => 'attachment',
	 'numberposts' => -1,
	 'post_mime_type' => 'application/vnd.ms-powerpoint',  //MIME Type condition
	 ))){
	 foreach( $files as $file ){ //setup array for more than one file attachment
		$file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
		$file_name_array=explode("/",$file_link);
		$file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
		$sAttachmentString .= "<div class='documentIcons'>";
		$sAttachmentString .= "<a href='$file_link'>";
		$sAttachmentString .= "<img src='".get_stylesheet_directory_uri()."/_inc/images/mime/PowerPoint.png'/>";
		$sAttachmentString .= "</a>";
		$sAttachmentString .= "<br>";
		$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
		$sAttachmentString .= "</div>";
		}
	}
	//Excel Documents
	if ( $files = get_children(array(   //do only if there are attachments of these qualifications
	 'post_parent' => get_the_ID(),
	 'post_type' => 'attachment',
	 'numberposts' => -1,
	 'post_mime_type' => 'application/vnd.ms-excel',  //MIME Type condition
	 ))){
	 foreach( $files as $file ){ //setup array for more than one file attachment
		$file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
		$file_name_array=explode("/",$file_link);
		$file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
		$sAttachmentString .= "<div class='documentIcons'>";
		$sAttachmentString .= "<a href='$file_link'>";
		$sAttachmentString .= "<img src='".get_stylesheet_directory_uri()."/_inc/images/mime/XLS8.png'/>";
		$sAttachmentString .= "</a>";
		$sAttachmentString .= "<br>";
		$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
		$sAttachmentString .= "</div>";
		}
	}
	//Zipped Files
	if ( $files = get_children(array(   //do only if there are attachments of these qualifications
	 'post_parent' => get_the_ID(),
	 'post_type' => 'attachment',
	 'numberposts' => -1,
	 'post_mime_type' => 'application/zip',  //MIME Type condition
	 ))){
	 foreach( $files as $file ){ //setup array for more than one file attachment
		$file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
		$file_name_array=explode("/",$file_link);
		$file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
		$sAttachmentString .= "<div class='documentIcons'>";
		$sAttachmentString .= "<a href='$file_link'>";
		$sAttachmentString .= "<img src='".get_stylesheet_directory_uri()."/_inc/images/mime/zip.png'/>";
		$sAttachmentString .= "</a>";
		$sAttachmentString .= "<br>";
		$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
		$sAttachmentString .= "</div>";
		}
	}

	//Audio Files
	$mp3s = get_children(array(   //do only if there are attachments of these qualifications
	 'post_parent' => get_the_ID(),
	 'post_type' => 'attachment',
	 'numberposts' => -1,
	 'post_mime_type' => 'audio',  //MIME Type condition
	 ) );

	if (!empty($mp3s)) :
	$sAttachmentString .= "<ul class='audiofiles'>";
		foreach($mp3s as $mp3) :
    		$sAttachmentString .= "<li>";
			if(!empty($mp3->post_title)) : //checking to make sure the post title isn't empty
				$sAttachmentString .= "<h4 class='title'>".$mp3->post_title."</h4>";
			endif;

			if(!empty($mp3->post_content)) : //checking to make sure something exists in post_content (description)
				$sAttachmentString .= "<p class='description'>".$mp3->post_content."</p>";
			endif;

			$sAttachmentString .= "<object width='438' height='24' id='single".$mp3->ID."' name='single".$mp3->ID."'>";
				$sAttachmentString .= "<param name='movie' value='player.swf'>";
				$sAttachmentString .= "<param name='allowfullscreen' value='true'>";
				$sAttachmentString .= "<param name='allowscriptaccess' value='always'>";
				$sAttachmentString .= "<param name='wmode' value='transparent'>";
				$sAttachmentString .= "<param name='flashvars' value='file=".$mp3->guid."'>";
					$sAttachmentString .= "<embed ";
					  $sAttachmentString .= "id='single".$mp3->ID."' ";
					  $sAttachmentString .= "name='single".$mp3->ID."' ";
					  $sAttachmentString .= "src='".get_stylesheet_directory_uri()."/_inc/images/player.swf' ";
					  $sAttachmentString .= "width='438' ";
					  $sAttachmentString .= "height='24' ";
					  $sAttachmentString .= "bgcolor='#ffffff' ";
					  $sAttachmentString .= "allowscriptaccess='always' ";
					  $sAttachmentString .= "allowfullscreen='true' ";
					  $sAttachmentString .= "flashvars='file=".$mp3->guid."' ";

					$sAttachmentString .= "/>";
			$sAttachmentString .= "</object>";
                        $sAttachmentString .= "<a href='".$mp3->guid."'>Download</a>";
			$sAttachmentString .= "</li>";
		endforeach;
	$sAttachmentString .= "</ul>";
	endif;	
	
	//Video Files
	$mpeg3s = get_children(array(   //do only if there are attachments of these qualifications
	 'post_parent' => get_the_ID(),
	 'post_type' => 'attachment',
	 'numberposts' => -1,
	 'post_mime_type' => 'video/mp4',  //MIME Type condition
	 ) );

	if (!empty($mpeg3s)) :
	$sAttachmentString .= "<ul class='videofiles'>";
		foreach($mpeg3s as $mp3) :
    		$sAttachmentString .= "<li>";
			if(!empty($mp3->post_title)) : //checking to make sure the post title isn't empty
				$sAttachmentString .= "<h4 class='title'>".$mp3->post_title."</h4>";
			endif;

			if(!empty($mp3->post_content)) : //checking to make sure something exists in post_content (description)
				$sAttachmentString .= "<p class='description'>".$mp3->post_content."</p>";
			endif;

			$sAttachmentString .= "<object width='700' height='400' id='single".$mp3->ID."' name='single".$mp3->ID."'>";
				$sAttachmentString .= "<param name='movie' value='player.swf'>";
				$sAttachmentString .= "<param name='allowfullscreen' value='true'>";
				$sAttachmentString .= "<param name='allowscriptaccess' value='always'>";
				$sAttachmentString .= "<param name='wmode' value='transparent'>";
				$sAttachmentString .= "<param name='flashvars' value='file=".$mp3->guid."'>";
					$sAttachmentString .= "<embed ";
					  $sAttachmentString .= "id='single".$mp3->ID."' ";
					  $sAttachmentString .= "name='single".$mp3->ID."' ";
					  $sAttachmentString .= "src='".get_stylesheet_directory_uri()."/_inc/images/player.swf' ";
					  $sAttachmentString .= "width='700' ";
					  $sAttachmentString .= "height='400' ";
					  $sAttachmentString .= "bgcolor='#ffffff' ";
					  $sAttachmentString .= "allowscriptaccess='always' ";
					  $sAttachmentString .= "allowfullscreen='true' ";
					  $sAttachmentString .= "flashvars='file=".$mp3->guid."' ";

					$sAttachmentString .= "/>";
			$sAttachmentString .= "</object>";
                        $sAttachmentString .= "<a href='".$mp3->guid."'>Download</a>";
			$sAttachmentString .= "</li>";
		endforeach;
	$sAttachmentString .= "</ul>";
	endif;	
	
$sAttachmentString .= "</div>";
if($echo){
    echo $sAttachmentString;
  }
  return $sAttachmentString;
}
add_shortcode('attachment icons', 'get_attachment_icons');

get_attachment_icons($echo=true);

<style>
.documentIcons{
float:left;
height:125px;
line-height:30px;
overflow:hidden;
padding:10px;
text-align:center;
width:125px;
}
.documentIcons a{
font-size:10px;
line-height:13px;
}
.documentIcons img{
border:0px solid #606060;
}
.documentIconsWrapper ul.audiofiles, .documentIconsWrapper ul.videofiles{
float:left;
width:100%;
margin:0;
}
.audiofiles li{
list-style:none outside none;
margin:20px 5px;
padding:12px;
width:438px;
float:left;
}
.videofiles li{
list-style:none outside none;
margin:20px 5px;
padding:12px;
width:100%;
float:left;
clear:both;
text-align:center;
}
.videofiles li a {float:left;width:100%;}
</style>

Source : http://tgrayimages.com/automate-file-attachments-on-your-wordpress-posts/

Future Post inner page

add_filter('the_posts', 'jm_future_posts');

function jm_future_posts($posts)
{
   global $wp_query, $wpdb;

   if(is_single() && $wp_query->post_count == 0)
   {
      $posts = $wpdb->get_results($wp_query->request);
   }

   return $posts;
}

Change the Courseware word to something else

function before_header() {
	ob_start("callback");
}

function callback($buffer) {
	$buffer = str_replace('Courseware', 'Classroom', $buffer);
	return $buffer;
}

function buffer_end() {
	ob_end_flush();
}

add_action('wp_head', 'before_header', 1);
add_action('wp_footer', 'buffer_end', 1);

Export WordPress Posts to Excel

Create a file in your theme ‘download.php’. And the save the file with the below content.

<?php
/* Template Name: Download */
wp_head(); ?>
<table id="download">
<tr>
<th>Title</th>
<th>Address</th>
<th>Area</th>
<th>Postal Code</th>
<th>City</th>
<th>Manager</th>
<th>Phone No</th>
<th>E-Mail</th>
<th>Website</th>
<th>Category</th>
</tr>
<?php $downloads = new WP_Query('showposts=-1');
while ($downloads->have_posts()): $downloads->the_post();
global $post; ?>
<tr>
<td><?php the_title();?></td>
<td><?php the_permalink();?></td>
<td><?php echo get_post_meta($post->ID,'custom_field_name',true);?></td>
<td><?php $poc = get_the_terms( $post->ID, 'custom_taxonomy_name', '', ', ', '' ); $list = ''; if ($poc) { foreach ($poc as $data) $list .= $data->name.', '; echo $list; } ?></td>
<td><?php $cats = get_the_category(', '); $list = ''; if ($cats) { foreach ($cats as $data) $list .= $data->cat_name.', '; echo $list; } ?></td>
</tr>
<?php
endwhile;
wp_reset_query(); ?>
</table>

And create a new page in your WordPress admin dashboard , with the name ‘Download’ and select the page template to ‘Download’, and keep the page has private and just view the page.

You will get the all your posts.

Just copy it and save it in XLS.

Remove update notice from WordPress Admin Dashboard

function version()
{
remove_action('admin_notices', 'update_nag', 3);	
}
add_action('admin_init','version');

Expand onfocus and window scroll down

Jquery

$(document).ready(function(){
$('textarea.expand').focus(function () {
    $(this).animate({ height: "400px" }, 500);
    $('html, body').animate({scrollTop: '140px'}, 800);
});
});

HTML
<textarea class="expand" rows="1" cols="10" readonly="readonly"></textarea>

CSS
<style>
.expand{height:100px;padding:5px;}
</style>

Show only status update in Buddypress Activity Stream

function custom_query_filter( $query_string ) {
$query_string .= 'action=activity_update';

return $query_string;
}
add_filter( 'bp_dtheme_ajax_querystring', 'custom_query_filter' );

Follow

Get every new post delivered to your Inbox.