Wordpress Add Read More Tag to a post content (Single.php) -
i have wordpress custom theme made scratch including:
- header.php, footer.php, single.php, index.php, functions.php
for listing blog list used index.php excerpt , read more link respective post.
index.php
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> <div class="single_excerpt"> <h1 class="red_text"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>" class="read_more"><button class="btn btn-default" type="">read more</button></a> </div> <?php endwhile; ?>
functions.php
function new_excerpt_more( $more ) { return ''; } add_filter('excerpt_more', 'new_excerpt_more');
this works fine expected, problem single.php when want add read more tag post content after first paragraph,nothing happened. please me add read more tag backend post content after first paragraph or desired , on single post view content display before tag , after read more button , after clicking button full content display on same single view of post.
single.php
<div class="col-lg-12 col-md-12 col-sm-12 "> <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> <div class="single_post"> <h1 class="red_text"><?php the_title(); ?></h1> <div class="post_info"> posted by: <?php the_author_posts_link(); ?> | posted on: <?php the_date(); ?> | posted in:<?php the_category(', '); ?> | <?php comments_popup_link('no comment', '1 comment', '% comments'); ?> </div> <?php the_content(); ?> <?php comments_template( '', true ); ?> </div> <?php endwhile; ?> <?php else : ?> <div class="post"> <h3><?php _e('404 error: not found', 'brightpage'); ?></h3> </div> <?php endif; ?> </div>
the more function doesn't work on single.php default. should add global $more; $more = 0;
loop:
<?php if(have_posts()) : while(have_posts()) : the_post(); global $more; $more = 0; the_content(); $more = 1; the_content('',true,''); ?>
now have content text before more tag first ($more = 0
), followed text after more tag ($more = 1
). javascript can show-hide content onclick.
Comments
Post a Comment