WordPress.org

Ready to get started?Download WordPress

Forums

Template Part Shortcode
[resolved] Screenshots? (4 posts)

  1. Stacy (non coder)
    Member
    Posted 5 months ago #

    "Template parts must be stored in a "parts" folder within your theme directory"
    Would like to see a code example of the parts. A real world example might be to display a post's published date in a different location correct?

    https://wordpress.org/plugins/template-part-shortcode/

  2. Stacy (non coder)
    Member
    Posted 5 months ago #

    Did you mean the get_template_part() functions have to all be placed in the same "parts" folder for every theme or just that these functions need to be present somewhere and they are pulled.

    What about getting template parts from plugins?

  3. Marty Spellerberg
    Member
    Plugin Author

    Posted 1 month ago #

    Hi Stacy

    I'm so sorry about not responding sooner -- I only just released there's no email notifications of new topics. Thank you for your questions! Let me see if I can explain what this does in a clearer way. It's not a very visual thing, which is why there's no screenshots.

    First I'll explain what WordPress does natively: Sometimes there are pieces of code that appear again and again on a theme's templates. An example might be the markup for a bunch of social sharing links, which you'd want to appear on both your Single template and your Page template. Instead of just having a bunch of repetitive code in your theme, you can make a file in your theme directory called, say, "sociallinks.php" and put the code in there. Then, in your template files, you can use "get_template_part('sociallinks');" to output that code.

    Now, what this plugin does: I found, in addition to referencing these snippets of code from the template files, I sometimes also wanted to be able to reference them from within posts. An example from my own work is that I often have to thank sponsors/funders in a very specific way. I want to do this the same way every time, using specific language, their logo and link.

    The plugin creates a shortcode to which you can pass the name of a template part you have created. It will then run "get_template_part()", outputting the code from that part.

    The only stylistic piece I added is the requirement for a "/parts" folder within the theme. WordPress will let you put your template parts anywhere in your theme, but I find that too messy. I like to put them all in a folder together and have built that convention into the plugin.

    So if you were to create a snippet of code in the following location: "/wp-content/themes/mytheme/parts/thankyou.php", you would be able to include it in a post using: [template part="thankyou"].

    Please let me know if this helps to clarify the matter!

    Marty

  4. Marty Spellerberg
    Member
    Plugin Author

    Posted 3 weeks ago #

    Marking as resolved.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.