• Resolved zagreus

    (@zagreus)


    I want to create a template within my plugin which will display the entry in a certain way.

    I’ve added the template no problem:

    add_filter('single_template', 'mjt_class_single_templates');
    add_filter('archive_template', 'mjt_class_archive_templates');

    however within the template I still want to inherit the theme settings to some extent.

    So within my template file I need something like this:

    get_header();
    
    while (have_posts() ): the_post();
    
       <!-- inherit stuff from the theme to open the entry-->
       <!-- do my own formatting of title -->
        the_title();
       <!-- do my own formatting of content -->
        the_content();
       <!-- inherit stuff from the theme to close the entry-->
    endwhile;
    get_footer();

    I have a feeling I need to do something with get_template_part but … I can’t work out what.

    Any help much appreciated everyone.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I suspect there are too many variations amongst themes to reliably get template parts.

    I’d consider filtering ‘the_title’ and ‘the_content’ if I were you. Then you can wrap the elements in your own div. If your div contains a style attribute, that should override any styling from the theme.

    Thread Starter zagreus

    (@zagreus)

    Hmmm, I was afraid of that but thanks for your response.

    Do you know of any design practices / structures that would allow my template to fit in with most themes? I’m sure I’m not the only one to try to tackle this.

    Moderator bcworkz

    (@bcworkz)

    Well, the various twenty* themes shipped with WP (going back to even those no longer shipped) are considered model themes by many. Many theme devs try to emulate the basic structures used by these themes. But many do not, and even those that do make significant departures for their own purposes.

    The minimum requirements seen in all themes in the repository are very minimal, then there are all the themes people use that are not even in the repository.

    Perhaps others have tackled this problem, but I suspect they either gave up or resigned themselves to be happy with the results of get_header() and get_footer(). Even those calls are not 100% reliable.

    Thread Starter zagreus

    (@zagreus)

    Thanks bcworkz. I appreciate your response.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Post Type Templates’ is closed to new replies.