WordPress.org

Ready to get started?Download WordPress

Forums

Show posts which get by custom page in excerpt (25 posts)

  1. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    Hello there,
    I create a custom page that show all posts from defined category
    (http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates)

    I use similar index.php template uses the_content(' …');
    In home page shows post excerpt, but in my custom page, it shows full post.

    I want to show excerpt like home page.
    What is wrong?

  2. Oleg Dudkin
    Member
    Posted 2 years ago #

    Try to use the_excerpt() instead.

  3. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    I know, but I want to keep styled post (break lines, bold text...)

  4. Oleg Dudkin
    Member
    Posted 2 years ago #

    Does it works on homepage the way you expect? I mean formatting in excerpts.

  5. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    Yes, I use more tag /*<!--more-->*/ while publishing post,
    so, on homepage has /.../ at end with more link.

    But on my custom page, it shows full post :(

  6. Oleg Dudkin
    Member
    Posted 2 years ago #

    What have you changed in main loop in your template?
    Can you post template code here?

  7. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    My custom page

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thanks for support!

  8. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    I think I need add some parameters to wp_query to get post like homepage, but I don't know what parameters :(

  9. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    My custom code was pasted here http://pastebin.com/XNbAw59J
    Thanks

  10. Oleg Dudkin
    Member
    Posted 2 years ago #

    I can't see code...
    Try next:
    Create sample post with 2 short parts divided by --more--.

    use next code in the loop.

    the_content();
    the_content('blah_blah');
    echo get_the_content();
    global $post;
    echo $post->post_content;
    echo apply_filters('the_content', $post->post_content);

    And post what it shows.

  11. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    My code was pasted here, please :)
    http://pastebin.com/XNbAw59J
    Ok, I'll try!

  12. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    Hello there again,
    All of above codes show the same result: full post :(

  13. Oleg Dudkin
    Member
    Posted 2 years ago #

    does shortcodes work in post content for this template?

  14. esmi
    Forum Moderator
    Posted 2 years ago #

    Try replacing <?php the_content(' &hellip;'); ?> with <?php the_excerpt(); ?> near the bottom of the file.

  15. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    @Oleg Dudkin: I just tried some shortcodes, it works fine.
    @esmi: I want to keep post formatting :) so, I can't use the_excerpt :)

  16. Oleg Dudkin
    Member
    Posted 2 years ago #

    try
    echo array_shift(explode('<!--more-->', $post->post_content));
    instead of the_content();

  17. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    Wow, now, it works fine!!
    Thank you so much, Mr. Oleg Dudkin!
    Have a nice day!

  18. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    Opps, there's other problem,
    with short post (so I don't use <!--more--> tag), the result is exactly same the_excerpt();
    How can resolve this problem?
    I think should use a if, but I don't really know :(
    I also want to know why the_content(); on custom page not shows same hompage.

  19. Oleg Dudkin
    Member
    Posted 2 years ago #

    you are welcome ))
    to avoid future possible problems with shortcodes you can use
    echo apply_filters('the_content', array_shift(explode('<!--more-->', $post->post_content)));

  20. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    Oh god, your new code works fine even if there's no <!--more--> tag on post.
    Thank you so much :)

  21. Oleg Dudkin
    Member
    Posted 2 years ago #

    I'm not sure what is wrong with the_content();
    possibly it is result of reseting wp_query
    maybe you can replace

    $temp = $wp_query;  // assign orginal query to temp variable for later use
              $wp_query = null;
              $wp_query = new WP_Query($args);

    with
    $new_query = new WP_Query($args);

    and then
    while ($wp_query->have_posts()) : $wp_query->the_post();
    with
    while ($new_query->have_posts()) : $new_query->the_post();

  22. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    I followed your instruction, but the_content('..'); still shows fullpost.
    I think when retrieve new query, it returns not same wordpress original, so I also think there are some parameter that allow keep the original. But I don't know clearly :)

  23. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    It seems there's no parameters as I think :)
    http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

  24. Oleg Dudkin
    Member
    Posted 2 years ago #

    maybe you just need to get rid of $wp_query and $new_query at all.
    Just use
    query_posts($args);
    instead of
    $new_query = new WP_Query($args);
    and remove other references to $new_query from code.

  25. Tran Dinh Khanh
    Member
    Posted 2 years ago #

    Sorry for late response.
    I just tried query_post, no varied things was shown :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.