Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php //Here are two type of code you can use any one
- //Number one Code
- /* post-excerpt and read more in index.php */
- /* add this function to function.php */
- /* code for read more in functions.php*/
- function excerpt($num) {
- $limit = $num+1;
- $excerpt = explode(' ', get_the_excerpt(), $limit);
- array_pop($excerpt);
- $excerpt = implode(" ",$excerpt)." <a href='" .get_permalink($post->ID) ." ' class='".readmore."'>read more</a>";
- echo $excerpt;
- }
- /* then create a file call post-excerpt and put this code */
- <div class="page_area fix ">
- <div class="page column fix">
- <?php if(have_posts()) : ?>
- <?php while (have_posts()) : the_post(); ?>
- <div class="single_post">
- <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
- <div class="post_info">
- Posted In: <?php the_category(', '); ?> | Posted on: <?php the_time('M d, Y') ?> <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?>
- </div>
- <div class="post_content">
- <a href="<?php the_permalink(); ?>"></a>
- <?php echo excerpt('20'); ?>/* 20 this is the limit number of word */
- <?php endwhile; ?>
- <?php endif; ?>
- </div>
- </div>
- </div>
- </div>
- /* whare to use it just call it like this index.php */
- <?php get_template_part( 'post-excerpt' ); ?>
- //Number two Code (I like to use this code )
- //Control post Excerpt in WordPress from functions.php (this code for length)
- function new_excerpt_length($length) {
- return 5; //5 this nubmber is word number
- }
- add_filter('excerpt_length', 'new_excerpt_length');
- function new_excerpt_more( $more ) { //(this code for readmore)
- return ' <a class="readmore" href="'. get_permalink( get_the_ID() ).'">Read More</a>';
- }
- add_filter( 'excerpt_more', 'new_excerpt_more' );
- // for call how to use (like number one code post-excerpt file)
- <?php the_excerpt() ; ?>
- //style put this style in your style css but if you want to use any style you can do this
- /* read more */
- .readmore{border: none;
- padding: 5px 15px;
- background: #7E196E;
- color: #FAF7F7;
- border-radius: 5px;
- cursor: pointer;
- text-decoration: none;}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement