This post is showing a simple way of creating a custom archive page showing post listing with “Read More” link if read-more tag is specified in the post content.
First of all, we need to make sure that posts contain read-more tag. In order to do so, we just need to place the text cursor in the desired position, where text before read-more tag can be displayed in archive page, in the content. And then press “Insert More Tag” button in the text editor in WordPress.
The following image shows how it looks in text editor.
Once the read-more tag is set, we can put some coding into archive.php file. In this file, we can use WP_Query function from WordPress to retrieve the list of post objects. And use the_content(__(‘Read more…’)); in the loop of post objects to show “Read More” link.
The following is the basic coding I have done to get it to work.
//retrieve a list of posts <!--?php $loop = new WP_Query( array( 'post_type' =----> 'post', //post type is post or can be set to any other custom post type 'post_status' => 'publish', //post status is 'publish' 'category_name' => 'root', //post category is 'root' or can be using an other custom post taxonomy 'orderby' => 'post_date', //post order by 'post_date' 'order' => 'DESC', //post order is in descending order 'posts_per_page' => 10, //number of post per page is 10 (pagination setting) 'paged'=>$paged //current page number (pagination setting) ) );?> <!--?php global $more; $more = 0; //declare and set $more before The Loop ?--> <!--?php if ($loop--->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); //begin The Loop ?>
<!--?php endwhile; //end of The Loop ?--> <!--?php endif; //end of The Loop ?-->
There will be some other ways to do so…
I hope this little article helps you with daily web development.