Wednesday, February 23, 2011

Show post with next previous links with jquery wordpress

First you need to download three images and upload it to your theme/images directory..
Here is the images..


second copy this code and paste it in the function.php in your theme directory.

function my_init_method() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js');
    wp_enqueue_script( 'jquery' );
}    
add_action('init', 'my_init_method');

if(!function_exists('limit_post')) {
function limit_post($content) {
 $content = get_the_content($more_link_text, $stripteaser, $more_file);
      $content = apply_filters('the_content', $content);
      $content = str_replace(']]>', ']]>', $content);
      $content = substr(strip_tags($content), 0, 50).'…';
      echo $content;
}
}

if(!function_exists('content')) {
function content($id=''){
    $single = new WP_Query;
    $single->query("p=$id&showposts=1");
    while ($single->have_posts()) : $single->the_post(); ?>
               <div class="meta">             
               <a href="<?php the_permalink() ?>"><?php limit_post('the_content()'); ?></a>
               </div>
<?php endwhile;
}
}

And place this code where you want to show post links.

<?php if(!is_page()) { ?>
<style>
#postPagination {float:left; padding: 3px;}
#postPagination label { color: #a68a5a;}
#contentInner {float: left;  padding: 3px;}
#contentInner a{color:#333333; text-decoration: none; }
#contentInner a:hover {color: #ff4b33; }
</style>
<div id="postPagination">
   <label>latest on blog</label>
   <a href="<?php echo get_permalink(get_adjacent_post(false,'',true)); ?>" title="Previous"><img src="<?php bloginfo('template_directory') ?>/images/previous.gif" border="0" /></a>
   <a href="<?php echo get_permalink(get_adjacent_post(false,'',false)); ?>" title="Next"><img src="<?php bloginfo('template_directory') ?>/images/next.gif" border="0" /></a>
</div>
<div id="contentInner">
   <?php 
if($_POST['id']) {
content($_POST['id']);
} else {
content();
} ?>
</div>
  
<script type="text/javascript" charset="utf-8">
  jQuery(document).ready(function(){

jQuery('#postPagination a').live('click', function(e){
e.preventDefault();
var link = jQuery(this).attr('href');
var id = link.split("=");
jQuery('#contentInner').html(function(){
return "<img src='<?php bloginfo('template_directory') ?>/images/loading.gif' />"
});
jQuery('#contentInner').load(link+' #contentInner', {id:id[1]});
jQuery('#postPagination').load(link+' #postPagination');
});
});
</script>
<?php } ?>

Computer automatically start with safe mode

Sometimes PC automatically start with safe mode to resolve this problem just follow these steps..

1) Go to start
2) Click Run
3) type msconfig
4) Click the boot tab
5) Uncheck the safe boot option

That's it...

Monday, February 7, 2011

WordPress Post List With Thumbnails

The function bellow, shows a list with posts and custom size thumbnails(for the post first image), linked to each post permalink. First copy this code and paste it in the function.php in your theme directory.

function thumb($id)
{
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $id
);
$attachments = get_posts($args);
// here we set the variable for the attachment string
$imgsrc = "";
if ($attachments):
// here we take the first image and break the loop
foreach ($attachments as $attachment) {
// this brings the attachment array $imgobj = wp_get_attachment_image_src($attachment->ID);
// if you use the line obove, you can call $imgobj[0] to get the image source
// you can set the thumbnail dimensions, here we use 40 x 40
$imgsrc = wp_get_attachment_image($attachment->ID, array(150,100), $icon = false);
break;
}
endif;
return $imgsrc;
}


Call the function in your index.php or home.php ..

<a href="<?php the_permalink() ?>"><?php echo thumb($post->ID); ?></a>


That's all done..

Wednesday, February 2, 2011

Character Limit (Pages & Posts) content

Just open your home.php. This file is located in your theme folder. Open this file with your text editor.

find this line in your home.php file -

<?php the_content('Read the rest of this entry &raquo;'); ?>

Replace with this

<?php 
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo substr(strip_tags($content), 0, 250).'…' ; 
?>


Now do same with your index.php file.
That's all...