• Resolved Christian

    (@clandsberg)


    Hi,

    I’m using WordPress Popular Posts on my homepage. Using custom HTML markup I creaded some nice looking teaser.

    Headline, categories and thumbnails working fine. I also use {summary} to show the beginning of the content.

    In every post a <!–more–>-tag is set. So I want to show the content until more-tag also for popular posts.

    I googelt a lot but did not find the answer yet. Do you have an idea how I can change this?

    Thx,
    Christian

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @clandsberg,

    For this you’ll need to create a custom Content Tag as currently there’s no way to customize what the content tag {summary} returns.

    Using this SO Answer as a starting point, you’ll want to use the wpp_parse_custom_content_tags filter hook to create a custom content tag -as mentioned before- that outputs exactly what you want. For example, let’s say that our new custom content tag is called {content_before_more_tag}:

    /**
     * Parses custom content tags in WordPress Popular Posts.
     *
     * @param  string  $html    The HTML markup from the plugin.
     * @param  integer $post_id The post/page ID.
     * @return string
     */
    function wpp_parse_tags_in_popular_posts($html, $post_id){
        // Replace custom content tag {content_before_more_tag} 
        // with the actual content
        if ( false !== strpos($html, '{content_before_more_tag}') ) {
            // Get the post content
            $content = get_post_field('post_content', $post_id);
            // Retrieve content parts
            $content_parts = get_extended($content);
            // Get content before the <!--more--> tag
            $content_before_more_tag = $content_parts['main'];
    
            // Replace {content_before_more_tag} with our content
            $html = str_replace(
                '{content_before_more_tag}',
                $content_before_more_tag,
                $html
            );
        }
    
        return $html;
    }
    add_filter("wpp_parse_custom_content_tags", "wpp_parse_tags_in_popular_posts", 10, 2);

    Once you add the above snippet to your theme’s functions.php file, replace {summary} with {content_before_more_tag} and you should be good to go.

    Thread Starter Christian

    (@clandsberg)

    Thanks a lot. It works really well.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Showing Content until -Tag instead of Excerpt/Summary’ is closed to new replies.