How to make Wordpress Page template

How to make WordPress Page template?

Generally, themes page.php is used as default page template. But if you wants to create a custom page template, then you just need to copy page.php codes and save a new name like template-custom.php . You need to add this code in the very beginning. Additionally, you can add custom php codes, wordpress loops, HTML codes as you wish !


<?php 
/*
Template name: Custom 
*/
?>

Now go to Dashboard > Pages > add new, you will see a drop down option in right side, where you can select your page template. Done !

how to show post excerpt wordpress

How to show post excerpt in wordpress?

There are two ways to show post excerpt in WordPress. I will show you here.

First method:

First add this code in functions.php


function new_excerpt_more( $more ) {
return ' &lt;a class="read-more" href="'. get_permalink( get_the_ID() ) . '"&gt;' . __('Read More', 'your-text-domain') . '&lt;/a&gt;';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );

then add this code in the loop and single.php

the_excerpt();

You can show featured images too, just add the_post_thumbnail();

Another Method:

First add these codes in functions.php just like first methods.

function get_excerpt($count){
$permalink = get_permalink($post-&amp;gt;ID);
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = $excerpt.'... &lt;a href="'.$permalink.'"&gt;more&lt;/a&gt;';
return $excerpt;
}

Then add get_excerpt(125); in your themes loop and single.php

Done !