Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display page excerpt in Wordpress

Tags:

wordpress

I am new in using Wordpress, I created a page that contains a long list of items.

* Item 1
* Item 2
* Item 3
* Item 4 ... and so on

I am planning to embed this page with long list of items on a separate page. How am I going to do it? I followed tutorials online and got the idea of putting this piece of code add_post_type_support( 'page', 'excerpt' ); on functions.php. After putting the code, an new option will be available when you create/edit pages. But after that, how can I display the my page excerpt?

like image 554
kagat-kagat Avatar asked Jun 13 '13 09:06

kagat-kagat


1 Answers

First to put this code on your theme function.php file.

add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
     add_post_type_support( 'page', 'excerpt' );
}

After that enable excerpt for page see below define image:

Showing excerpt

Using this code to get page excerpt:

<?php echo get_the_excerpt(); ?>

<?php 
    query_posts("page_id=36");
    while ( have_posts() ) : the_post()
?>
    <h1><a href="<?php echo the_permalink(); ?>"><?php echo get_the_title(); ?></a></h1>
    <?php the_excerpt(); ?>

<?php
    endwhile; 
    wp_reset_query();
?>      
like image 79
Ravi Patel Avatar answered Nov 03 '22 01:11

Ravi Patel