• Hi,

    I created a recipe costing plugin that simply adds up the cost of ingredients in a recipe.

    It has 2 custom post types, Recipes and Ingredients. It uses the Posts to Posts plugin to make the connection and store ingredient qty for each recipe.

    I then created a theme to display this content and in the single-recipe.php file i have performed all the calculations on the recipe and ingredient data.

    So i have two folders, a plugin and a theme folder. I want to be able to display all my recipe and cost data just with the plugin and no theme, because it makes more sense to have just 1 file to install.

    Im confused about custom post type templates, im looking at WooCommerce products as an example and ‘products’ post types do not have the option to change the template, this makes sense because a product template needs to do some special querys and calculations to display the data.

    Im new to all this and i think what im asking is, how can i create a single-recipe.php file in my Plugin folder and have WordPress know that is the file i want to use as my default theme/template file?

    I have read the codex on CPTs and Templates but i haven’t seen anything that talks about this grey area, any help/links would be appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    After doing more research i might be able to articulate this question better.

    How can i get a custom post type to output its content and meta data without creating a theme template so the user can still switch themes if they wish?

    You can create a shortcode, with arguments if needed, that could be embedded on any page and output your desired content.

    To take it a step further, you can add a custom button to the WYSIWYG editor in WordPress and provide a GUI for adding that shortcode, much like how a gallery works.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    Thanks for the suggestion – I would rather make it easy for the user by not making them use shortcodes but this may have to do for now.

    I like in WooCommerce and some other plugins that register custom post types how they provide a template with the plugin so that no short code is necessary. In WooCommerce the checkout and my account page both use shortcodes, but the product post type definitely doesn’t use short codes and that’s what I’m trying to do.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    I think maybe this is where WordPress is limited and where other CMSs like Drupal take over.

    There is obviously no default or native way to do this thy I can see in the codex, and iv read that WooCommerce ‘tricks’ WordPress into thinking there is a product post type template in the WooCommerce folder.

    The codex encourages one to use build CPTs into a plugin, but then u can’t make a wp_query on the admin post edit screen, well at least when I try it, nothing appears in my meta box but when I use that code in a theme template as per the codex all the calcs work and the tables render perfectly

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    I’ll have to make a theme for this plugin, really wanted it to work like WooCommerce tho. If anyone knows how I can get WordPress to use a template from within my plugin folder kindly link to a tutorial or let me know how it’s done – the WooCommerce code is a little help but super super complicated

    The codex encourages one to use build CPTs into a plugin, but then u can’t make a wp_query on the admin post edit screen, well at least when I try it, nothing appears in my meta box but when I use that code in a theme template as per the codex all the calcs work and the tables render perfectly

    Can you show us the code you wrote that didn’t work? Anything you can do in something like functions.php, you should be able to do in a plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘I created a CPT plugin, how can i display the content without a theme?’ is closed to new replies.