Tuesday 26 April 2016

Read More link in blog in php and Wordpress using Jquery


Read More link  in blog in php and Wordpress using Jquery

<script src="https://code.jquery.com/jquery-2.2.3.js"></script>
<script type="application/javascript">
jQuery(document).ready(function($) {



jQuery(document).on("click","a.less",function(event){

var href = jQuery(this).text();
if(href=="read more..."){

var moretext =jQuery(this).parent().parent().find('input[name=more]').val();
jQuery(this).parent().html(moretext);
}

if(href=="less"){

var lesstext =jQuery(this).parent().parent().find('input[name=less]').val();
jQuery(this).parent().html(lesstext);

}
return false;
event.preventDefault();

});
});
</script>
<?php

$string="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
?>
<div class="product_text">
                 
                   
<?php   $string = strip_tags($string)." <a class='less' href='javascript:void(0)'>less</a>";
$substr = substr($string, 0, strpos(wordwrap($string, 250), "\n"))." <a class='less' href='javascript:void(0)'>read more...</a>";
?>
                <input type="hidden" name="less" value="<?php echo $substr; ?>" />
                <input type="hidden" name="more" value="<?php echo $string; ?>" />

<?php

echo '<p class="readMore">'.$substr."</p>";


?>


                  
                  </div>

No comments:

Post a Comment

Thank You For Comment