I trying to include two theme template files into a wp plugin that deals with custom post types and for the life of me cant figure out a way to do it, I have searched extensively and believe posting here is the best option if I am to find an answer.
The custom post type is videos which is using single-video.php as the single template and category-253.php for the category and am wanting to move them from the child theme into the plugin/includes/templates directory so the plugin is independent.
Anyone have any ideas ?
this should cover what you are looking for
http://tommcfarlin.com/page-template-in-plugin/
but as far as plugin integration, you can try the shortcode method to display template codes from plugins
[myshortcode parm=1 parm=2 parm=3]
to do something in a plugin like for example list your custom post with different options
Related
Can someone please point me in the right direction regarding the location of the template file that contains the blogs posts loop I’m using the blog element.
I've tried multiple files but it does not work, Would ideally like to add a link after the meta information
Any help would be greatly appreciated.
Kind redards
Check index.php,archive.php,search.php files, find function method that used here to display posts, search for this method (or use IDE to find it fast) in theme directory files, in this method you will find how theme load template files. Avada is a complex theme with a lot of settings and different templates files for loop, that can load different templates dynamically depended on your current theme settings for design and layouts.
I'm using different page-templates this for pages.
Now I need the same for posts.
Since 4.7 this should be a core functionality.
So I pretty much followed this quick tutorial and added a custom single-duplicate.php in my theme folder and added this code at the top:
<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/
However upon creating a new post I dont see the "Post Attributes" Box with the Template-dropdown. What do I do now? Is it possible that my theme somehow prevents that?
Here's my themes functions.php as a gist, if that helps.
I think you are a bit confused as to what Page Attributes will give you access to. To the best of my knowledge, you do not get a drop down to choose a template (as you do on Pages) as an automatic function on posts/custom post types.
you need to create a single-{POSTTYPE}.php in your theme directory and need to add/follow the HTML structure of your page template.
For more information,
Custom Post Type page template doesn't show up
Post Template Files
Hope this will helps you.
Okay, so I am completely lost on how to display a custom post. I've looked everywhere and can't seem to wrap my mind around it.
So, I downloaded the plugin Custom Post Type UI to create a custom post. Here are the parameters of my custom post type:
Name: discount
Label: Discount
Supports:
title,
excerpt,
thumbnail,
author
Then, I downloaded Advanced Custom Fields to give my custom post types some custom fields for users to edit.
I didn't have any problems with that. My problem is that I have no idea how to implement this into my site. I would like it to act exactly like a blog post and also implement a masonry for it - just like my blog posts (I'm using the dante theme (I can't post any more links)).
If anybody could help me out with this, or send me in the right direction, I would be so greatful. Thanks!
Your custom post type's theme template would be called "single-[post type name].php".
So for your example, you would want to create single-discount.php if your theme's root directory. Then you can start pulling your data from the posts through that.
For Advanced Custom Fields, you'll want to get familiar with get_field() and the_field(). ACF has great documentation on their site for how to use the various field types (http://www.advancedcustomfields.com/resources/)
To answer your questions in a general way, you could start by:
Theme Development. To understand how a WP theme works
Template Hierarchy. To understand what are the template files and how they are managed by WP
The Loop. To understand how WP shows the post
WP Query Class. To understand how to manage the posts, perhaps in the case of custom post type
For the custom fields, #Joe has pointed you in the right direction.
Hope it helps!
Is there any way we can assign a shortcode to already created widget and later use that
shortcode in our specific posts and pages to show that widget instead of trivial method of
showing widgets in sidebar ? I googled about this stuff didn't find anything relative.
Any suggestion would be welcome!
Yes, You can call widget in Post/Page using shortcode. Follow this link to establish a system like that.
http://digwp.com/2010/04/call-widget-with-shortcode/
This might be relevant.
Widgets on Pages
https://wordpress.org/plugins/widgets-on-pages/
Observations and two questions:
This plugin allows insertion of 1 or "sets" of widgets via shortcode into pages, posts, (and Custom post types?) and it will also save a list of configured shortcodes~sets. VERY handy!
When comparing its features to the plugin Widgets Shortcode, that plugin does not provide a means to save "sets" of plugins, rather it seems to focus on inserting widgets individually. In fact, it inserts the shortcode for each widget in the bottom edge of each widget and it assigns different shortcodes to each instance of a widget. Also nice.
https://wordpress.org/plugins/widget-shortcode/
I like the granularity Widgets Shortcode provides with an individual shortcode for every instance of every widget. When running it and your plugin simultaneously even widgets saved in your plugin's "sets" are still assigned individual shortcodes. Those individual shortcodes allow using a specific widget out of a "set" in a different location without needing to create an additional instance of the widget as it appears would be required with your plugin.
Incidently, for anyone who wants both of these features, these two plugins play very nicely together on one of our WP 4.0 Multisite installations with 50+ sites and even on a site using the theme Make.
FYI: We also tested amr shortcode any widget, but had some issues with it and rather than troubleshoot it we moved on. To be fair, we were testing quickly on a site with over 160 plugins active. Yes, 160 plugins. I know, I know, but think about it for a minute. Any plugin that you can activate into that mix of 160 plugins and it does not break things or introduce issues, then it suggests a good probability of it being troublefree to use.... well at least until the next round of WP updates. :)
We also tested Widgetize Pages Light and its pro version Sidebar & Widget Manager and had no issues with either. However, if only seeking to insert widgets into pages and posts these plugins seem like overkill as they provide additional page layout functions that may duplicate theme functions and/or other plugin functions.
I was looking for a "widgets in pages" plugin that provides a TinyMCE button to insert the widget shortcodes.
Can anyone recommend one that has a TinyMCE button to insert the widget shortcodes in pages, posts and CPTs?
Ultimately I selected Widgets On Pages as having the best combination of features for this application. Its simple to understand, easy to use, versatile and has worked flawlessly for us, even along side Widgets Shortcode.
You can do it by wordpress WordPress Widgets Shortcode plugin, you can Embed any widget area/dynamic sidebar to your pages/posts using this plugin as a shortcode
edit widgets in wp :
file in # wp-includes/widgets.php: register_widget()
in source view sample :
public function register( $widget_class ) {
$this->widgets[$widget_class] = new $widget_class();
}
i'm doing a gallery plugin for joomla, someone told me to use template overrides, i really don't know what the hell is this, and why i need to use it for my gallery plugin? i did googling and found this article useful Joomla template override , but still i am not able understand why i need this, and how to do this for my gallery plugin 'cause the example i found is for modules, your help will be much appreciated.
If you are simply trying to insert some content (a gallery) into the output via a plugin, template overrides are not what you need. Template overrides would allow you to modify the output of a component or a module, but not to insert a functionality like a gallery. You simply want to create a plugin that acts on onContentPrepare.