• Hi,
    I’ve just started using WordPress a few days ago. I ran into a problem of creating an excerpt of a page. I know there are plugins which might assist with this problem but I was told not to use plugins. So I found online that there is this code:

    add_action(‘init’,’my_add_excerpts_to_pages’);

    function my_add_excerpts_to_pages(){
    add_post_type_support(‘page’,’excerpt’);
    }

    helps the excerpt to work on page which it does the same to posts too. I’m wondering how to code the loop.php to display the excerpt. It will be good if answers can be simplified as I’m kind of confused with what’s WordPress Codex given me.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Sorry but I speak english not so well so it’s hard to me to understand well your problem. If you need to have ‘the_exceprt’ for PAGES as for POSTS as you write above you have to simply insert in your function.php

    add_post_type_support( 'page', 'excerpt' );

    In your loop in page.php you insert something like this

    <?php while (have_posts()) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>
    Thread Starter chjm

    (@chjm)

    Hi YouON,
    I’ll try it out now. Would like to ask if it is loop.php or loop-page.php? Thanks for your help.

    There is no loop.php in theme files you put the code in every page you want/need

    Thread Starter chjm

    (@chjm)

    If I’m not wrong, you mean there is no loop.php. But I have these templates, loop.php, loop-page.php, loop-single.php etc. They are default templates created by WordPress. And as I want the excerpt to appear at my home page, I should place the codes you given at home.php?

    Probably the theme you are using have these files, but I’ve never used them.
    If you have an home.php, yes you have to put it there ??

    Thread Starter chjm

    (@chjm)

    Ok, in the WordPress Editor, the page title is News. From what I see in wordpress, they retireve the string through headings. Is it possible to retrieve the value by the page title?

    With “page title” do you mean the title in the <head> section?

    there is loop.php, and usually it appear when you use <?php get_template_part( 'loop' ); ?> in your index.php, page.php, single.php.

    so if you have loop.php, you must put your excerpt in the loop.php

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Page Excerpt’ is closed to new replies.