Forums

Page Excerpt (9 posts)

  1. chjm
    Member
    Posted 5 months ago #

    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.

  2. YouON
    Member
    Posted 5 months ago #

    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; ?>
  3. chjm
    Member
    Posted 5 months ago #

    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.

  4. YouON
    Member
    Posted 5 months ago #

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

  5. chjm
    Member
    Posted 5 months ago #

    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?

  6. YouON
    Member
    Posted 5 months ago #

    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 ;)

  7. chjm
    Member
    Posted 5 months ago #

    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?

  8. YouON
    Member
    Posted 5 months ago #

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

  9. faugro
    Member
    Posted 4 months ago #

    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

Reply

You must log in to post.

About this Topic