So I’m creating a plugin to create buildings that list condos for sale. The simplest way to do this was to just create a custom post type for the buildings and then the listings but I’m now stuck on how to display them in an archive. I’ve done something similar while developing themes where I would just create a archive-my_post_type.php and single-my_post_type.php but I don’t know how to anticipate how themes could be developed.
I found an answer on stack overflow that allows you to hijack the chosen template but I’m afraid template files might be more than just get_header() and the_content() etc…
What is considered best practice for this sort of thing? Do I just grab get_template_part_content and replace it with my custom loop? Or hijack the chosen template like the answer above and hope for the best?
Include your template files in your plugin. I stick mine in /plugin/templates.
You need to hook into template location for that template:
Rinse and repeat with the appropriate checks for each template you want to implement (single, taxonomy etc).
Doing it this way means that WP will look in the theme first for your templates, but will fall back to the plugin’s templates folder if not found in your theme. If users want to modify the templates to fit their theme, they can simply copy them to their theme’s folder.
If you want to be really clever about it, you can force a check for the templates in their theme folder and load some default styles if they’re using the plugin’s copy of the templates: