Advertisement
firoze

wordpress READMORE here expand in current page

Jul 22nd, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. // show in wordpress template for home page and blog page that mean front_page.php and index.php
  2.  
  3. <?php
  4. global $post;
  5. $args = array( 'posts_per_page' =>1, 'post_type'=> 'post','order'=>'ASC');
  6. $myposts = get_posts( $args );
  7. foreach( $myposts as $post ) : setup_postdata($post); ?>
  8. <div class="more_article">
  9. <h2><?php the_title(); ?></h2>
  10. <?php the_content();?>
  11. </div>
  12. <?php endforeach;?>
  13.  
  14.  
  15. ***********************************************************************
  16. // show in wordpress template for only blog page that mean index.php
  17.  
  18. <?php if(have_posts()) : ?>
  19. <?php while (have_posts()) : the_post(); ?>
  20. <div class="more_article">
  21. <h2><?php the_title(); ?></h2>
  22. <?php the_content();?>
  23. </div >
  24. <?php endwhile;?>
  25. <?php endif;?>
  26.  
  27. **********************************************************************
  28. // show in footer
  29.  
  30. <script src="https://raw.githubusercontent.com/jedfoster/Readmore.js/master/readmore.js"></script>
  31. <script src="<?php echo get_template_directory_uri(); ?>/js/readmore.min.js"></script>
  32. <script>
  33. jQuery('.more_article').readmore({
  34. speed: 75,
  35. collapsedHeight: 140, // this content that show before read more try by you increase or decrease height and see preview
  36. lessLink: '<a href="#">Read less</a>'
  37. });
  38. </script>
  39.  
  40.  
  41. ************************************************************************************
  42. // readmore.min.js
  43.  
  44. /*!
  45. * @preserve
  46. *
  47. * Readmore.js jQuery plugin
  48. * Author: @jed_foster
  49. * Project home: http://jedfoster.github.io/Readmore.js
  50. * Licensed under the MIT license
  51. *
  52. * Debounce function from http://davidwalsh.name/javascript-debounce-function
  53. */
  54. !function(e){"use strict";function t(e,t,a){var i;return function(){var n=this,o=arguments,r=function(){i=null,a||e.apply(n,o)},s=a&&!i;clearTimeout(i),i=setTimeout(r,t),s&&e.apply(n,o)}}function a(e){var t=++h;return String(null==e?"rmjs-":e)+t}function i(e){var t=e.clone().css({height:"auto",width:e.width(),maxHeight:"none",overflow:"hidden"}).insertAfter(e),a=t.outerHeight(),i=parseInt(t.css({maxHeight:""}).css("max-height").replace(/[^-\d\.]/g,""),10),n=e.data("defaultHeight");t.remove();var o=e.data("collapsedHeight")||n;i?i>o&&(o=i):o=n,e.data({expandedHeight:a,maxHeight:i,collapsedHeight:o}).css({maxHeight:"none"})}function n(e){if(!d[e.selector]){var t=" ";e.embedCSS&&""!==e.blockCSS&&(t+=e.selector+" + [data-readmore-toggle], "+e.selector+"[data-readmore]{"+e.blockCSS+"}"),t+=e.selector+"[data-readmore]{transition: height "+e.speed+"ms;overflow: hidden;}",function(e,t){var a=e.createElement("style");a.type="text/css",a.styleSheet?a.styleSheet.cssText=t:a.appendChild(e.createTextNode(t)),e.getElementsByTagName("head")[0].appendChild(a)}(document,t),d[e.selector]=!0}}function o(t,a){var i=this;this.element=t,this.options=e.extend({},s,a),e(this.element).data({defaultHeight:this.options.collapsedHeight,heightMargin:this.options.heightMargin}),n(this.options),this._defaults=s,this._name=r,window.addEventListener("load",function(){i.init()})}var r="readmore",s={speed:100,collapsedHeight:200,heightMargin:16,moreLink:'<a href="#">Read More</a>',lessLink:'<a href="#">Close</a>',embedCSS:!0,blockCSS:"display: block; width: 100%;",startOpen:!1,beforeToggle:function(){},afterToggle:function(){}},d={},h=0,l=t(function(){e("[data-readmore]").each(function(){var t=e(this),a="true"===t.attr("aria-expanded");i(t),t.css({height:t.data(a?"expandedHeight":"collapsedHeight")})})},100);o.prototype={init:function(){var t=this;e(this.element).each(function(){var n=e(this);i(n);var o=n.data("collapsedHeight"),r=n.data("heightMargin");if(n.outerHeight(!0)<=o+r)return!0;var s=n.attr("id")||a(),d=t.options.startOpen?t.options.lessLink:t.options.moreLink;n.attr({"data-readmore":"","aria-expanded":!1,id:s}),n.after(e(d).on("click",function(e){t.toggle(this,n[0],e)}).attr({"data-readmore-toggle":"","aria-controls":s})),t.options.startOpen||n.css({height:o})}),window.addEventListener("resize",function(){l()})},toggle:function(t,a,i){i&&i.preventDefault(),t||(t=e('[aria-controls="'+this.element.id+'"]')[0]),a||(a=this.element);var n=this,o=e(a),r="",s="",d=!1,h=o.data("collapsedHeight");o.height()<=h?(r=o.data("expandedHeight")+"px",s="lessLink",d=!0):(r=h,s="moreLink"),n.options.beforeToggle(t,a,!d),o.css({height:r}),o.on("transitionend",function(){n.options.afterToggle(t,a,d),e(this).attr({"aria-expanded":d}).off("transitionend")}),e(t).replaceWith(e(n.options[s]).on("click",function(e){n.toggle(this,a,e)}).attr({"data-readmore-toggle":"","aria-controls":o.attr("id")}))},destroy:function(){e(this.element).each(function(){var t=e(this);t.attr({"data-readmore":null,"aria-expanded":null}).css({maxHeight:"",height:""}).next("[data-readmore-toggle]").remove(),t.removeData()})}},e.fn.readmore=function(t){var a=arguments,i=this.selector;return t=t||{},"object"==typeof t?this.each(function(){if(e.data(this,"plugin_"+r)){var a=e.data(this,"plugin_"+r);a.destroy.apply(a)}t.selector=i,e.data(this,"plugin_"+r,new o(this,t))}):"string"==typeof t&&"_"!==t[0]&&"init"!==t?this.each(function(){var i=e.data(this,"plugin_"+r);i instanceof o&&"function"==typeof i[t]&&i[t].apply(i,Array.prototype.slice.call(a,1))}):void 0}}(jQuery);
  55.  
  56.  
  57.  
  58.  
  59.  
  60. **********************************************************************************************************
  61. // source link : https://github.com/jedfoster/Readmore.js
  62.  
  63. // Example link : http://jedfoster.com/Readmore.js/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement