Advertisement
arnabkumar

post-excerpt_and_readmore

Mar 31st, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. <?php             //Here are two type of code you can use any one
  2.  
  3.                                         //Number one Code
  4.  
  5. /* post-excerpt and read more in index.php */
  6.  
  7. /* add this function to function.php */
  8.  
  9. /* code for read more  in functions.php*/
  10. function excerpt($num) {
  11. $limit = $num+1;
  12. $excerpt = explode(' ', get_the_excerpt(), $limit);
  13. array_pop($excerpt);
  14. $excerpt = implode(" ",$excerpt)." <a href='" .get_permalink($post->ID) ." ' class='".readmore."'>read more</a>";
  15. echo $excerpt;
  16. }
  17.  
  18. /* then create a file call post-excerpt and put this code */
  19. <div class="page_area fix ">
  20.         <div class="page column fix">
  21.        
  22.     <?php if(have_posts()) : ?>
  23.                     <?php while (have_posts()) : the_post(); ?>    
  24.                     <div class="single_post">
  25.                    
  26.                     <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  27.                             <div class="post_info">
  28.                                 Posted In: <?php the_category(', '); ?> | Posted on: <?php the_time('M d, Y') ?> <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?>
  29.         </div>
  30.  
  31.  
  32.         <div class="post_content">
  33.             <a href="<?php the_permalink(); ?>"></a>
  34.         <?php echo excerpt('20'); ?>/* 20 this is the limit number of word */
  35.    
  36.                     <?php endwhile; ?> 
  37.                     <?php endif; ?>
  38.            
  39. </div>
  40.         </div>
  41.      </div>
  42.      </div>
  43.  
  44.  
  45. /* whare to use it just call it like this index.php */
  46.  
  47. <?php get_template_part( 'post-excerpt' ); ?>
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.                                       //Number two Code (I like to use this code )
  55.                                      
  56.                                      
  57.  
  58. //Control post Excerpt in WordPress from functions.php (this code for length)
  59. function new_excerpt_length($length) {
  60. return 5; //5 this nubmber is word number
  61. }
  62. add_filter('excerpt_length', 'new_excerpt_length');
  63.  
  64.  
  65.  
  66. function new_excerpt_more( $more ) {            //(this code for readmore)
  67. return ' <a class="readmore" href="'. get_permalink( get_the_ID() ).'">Read More</a>';
  68. }
  69. add_filter( 'excerpt_more', 'new_excerpt_more' );
  70.  
  71. // for call how to use (like number one code post-excerpt file)
  72.  
  73. <?php the_excerpt() ;  ?>
  74.  
  75. //style put this style in your style css but if you want to use any style you can do this
  76.  
  77. /* read more */
  78. .readmore{border: none;
  79. padding: 5px 15px;
  80. background: #7E196E;
  81. color: #FAF7F7;
  82. border-radius: 5px;
  83. cursor: pointer;
  84. text-decoration: none;}
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement