• Resolved Mohit

    (@themohityadav)


    I want to show description instead of full article, on category or tag page urls or archive pages, using wpcore taxonomies, from the first paragraph of post body.

    • This topic was modified 1 year, 9 months ago by Mohit.
    • This topic was modified 1 year, 9 months ago by Mohit.
    • This topic was modified 1 year, 9 months ago by Mohit.
    • This topic was modified 1 year, 9 months ago by Mohit.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You’ll need to modify your active theme’s template files to use the_excerpt() instead of the_content() in the appropriate places. We don’t have anything in CPTUI that dictates that.

    Thread Starter Mohit

    (@themohityadav)

    But you can see in the screenshot, we are using  the_excerpt() and that is working, see the second post in screenshot,

    But CPTUI post named “Testing” is not working in my instance.

    Note: This problem is only when i am not filling the excerpt box, but i am using yoast seo for descriptions not default excerpt box. Description is not taken from the first lines of the post body by plugin automatically.

    You can understand what I’m trying to say, right?

    • This reply was modified 1 year, 9 months ago by Mohit.
    • This reply was modified 1 year, 9 months ago by Mohit.
    • This reply was modified 1 year, 9 months ago by Mohit.
    • This reply was modified 1 year, 9 months ago by Mohit.
    Thread Starter Mohit

    (@themohityadav)

    i also try this but applied on default posts not on cptui posts

    function get_first_paragraph($post_id, $num_words) {
        $str = wpautop(get_post_field('post_content', $post_id));
        $str = substr($str, 0, strpos($str, '</p>') + 4);
        $str = strip_tags($str, '<a><strong><em>');
        $str = wp_trim_words($str, $num_words);
        return $str;
    }
    
    function custom_archive_description($description) {
        if (is_category() || is_tag()) {
            global $wp_query;
            $term = $wp_query->get_queried_object();
            $description = get_first_paragraph($term->description, 20); // Change "20" to the desired word limit
        }
        return $description;
    }
    
    add_filter('get_the_archive_description', 'custom_archive_description');
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    From my understanding, the_excerpt() will display the content from the excerpt field first, if it exists, otherwise it’ll grab the first X amount of words from the_content(). However, you’re also tinkering with description fields filled in from Yoast’s UI.

    I’m sure there’s ways to fetch Yoast’s fields via code, but I don’t know the function names offhand.

    That said, it should be totally possible to customize your template files to pull Yoast first if desired, otherwise use the_excerpt() and whatnot. I’m not sure what the desired priority will be here.

    For what it’s worth, these are all details that CPTUI’s code does not have any influence on still, but more how to display post content in general.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is any way to show description in archive pages instead of full article?’ is closed to new replies.