Pull in an "Include" file based on a WordPress Category ID

Here's what I am trying to achieve: when a category page is loaded then, based upn the ID of that category, an include file is loaded.

I believe that the below would work for some limited text, but I would prefer to load an include file b/c it will have multiple paragraphs and I feel it is better to manage that way.

   ?php
    $catarray = get_the_category( $post-ID );
    foreach ($catarray as $cat) {
        $catid = $cat-term_id;

        if ($catid == 10) {
          echo 'TEXT HERE'; // I prefer a PHP Include File 
        }
        if ($catid == 7) {
          echo 'ANOTHER TEXT';
        }

    }
    ?

So, my question would be - what would I need to do to replace the echo string? Would it be simply:

include get_theme_file_path( '/subdir/text-to-enter-in-the-category-10.php' );

Thanks for all help

Topic template-include include categories Wordpress

Category Web


I don't quite understand what you mean but this might work get_template_part()

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.