I need some help with how the setup for templates work for custom posts.
We have the following setup:
with Posts pointing to single.php which is fine. Then Services points to single-services.php and Stories points to single-stories.php.
I need to set up an Overseas Service custom post type which will have its own php file as the styling needs to be a specific way as it will incorporate a form that is only used here.
I duplicated the single-services.php file, as the base will look very similar to that, and called it single-overseas-service.php
I used the Toolset plugin to set up the new post type and the template is showing single.php and it can't be changed to a different file.
If someone could break down how best to do this, that would be great.
TIA,
Andy
This is caused by the - in your CPT's name. Change it to a _ or remove it altogether and you shouldn't have a problem.
eg, overseas_service and single-overseas_service.php
Related
I am running WordPress 4.5.2, Twentysixteen, and a plugin called 'Custom Fields Template'. I am looking to make the most of WordPress' custom fields but do not know how to make it do more than display a UL with some basic text data.
I would like to know how to:
display an image (from Media Library),
an active link, and
an active link to a media file (e.g. Download PDF Brochure).
I like the 'Custom Fields Template' plugin as it was super easy to install, set up with the variables I need, is clean and lightweight. Here are some screenshots of what I've got so far (for a racehorse syndication website - not live):
This is the Custom Fields Template within WordPress' page edit screen.
This is the resulting code - prints image ID only.
I am comfortable with modifying WordPress's .php files but am not fluent enough with PHP to write the necessary functions from scratch.
Any help would be greatly appreciated.
Since you don't provide enough specifics I can only write a very generic answer.
The function the_meta() you found does not belong to the theme, it is provided by the WordPress core and as you already noticed is not very customizable, it's output can only be styled with CSS.
I assume this is the plugin you are using: https://wordpress.org/plugins/custom-field-template/
Based on that assumption you have these possibilities:
The plugin provides the shortcode [cft] you can use in the content of the post itself. It's usage is described a little bit in the plugin description, but not much.
If know that you want to show this on every post or every certain post type you can create a template file for this and call the shortcode directly using do_shortcode().
echo do_shortcode( "[cft]" );
If you don't like the output of that shortcode either, you can address the custom fields directly.
It looks like the plugin doesn't show you the field names it actually uses, so you need to find them yourself. You can do this either by looking at the database, you'll find them in the table wp_postmeta, or you add some debug output to your template file, like this:
$meta = get_post_custom( $post->ID );
var_dump( $meta );
This will show you all custom fields from the current post. You can then either use this array to print your values, or you use get_post_meta() to retrieve specific field values.
Last, but not least: You stated that you are using the default theme Twentysixteen. You should NOT edit any of these theme files, or the files from the custom field plugin. The next time they are updated all your changes are going to be lost. Instead, create a child theme and add your post templates there.
I've just come across this very helpful article for beginners - it broke down the steps I needed to take to achieve what I was after:
https://perishablepress.com/wordpress-custom-fields-tutorial/
This is the Download & Print Brochure link I ended up with (using any custom field data i.e. with and without the plugin).
<?php $imageid = get_post_meta($post->ID, 'Brochure', true); ?>
Download & Print Brochure
I have been looking for a solution to display custom field tabs in the Joomla
front article edit page.
http://www.aixeena.org/extensions/aixeena-easy-cck
Aixeena Easy CCK
I installed the plugin of aixeena, two custom field tabs: the Extra content and Extra content 2 are displayed in the backend admin article edit page, which is great. But we also need to let regular edit their article and enter values in custom fields under those two tabs. Any idea how to achieve this?
I tried a couple of other sites posting the solution of adding custom fields in article, such as Rating region described in the site:
https://docs.joomla.org/Adding_custom_fields_to_the_article_component
I was not able to make the Rating tab displayed in the front end article edit page neither.
I tried the fieldattach, it does supports custom field tab ( which is the group name of custom field), the list field type only contains static values, we have to define fieldset and field type through xml file.
Any help is greatly appreciated.
I just finished writing a couple pluginsto do this similar thing. I wrote my own plugin to add the extra fields - but it looks like the one you've already used is very similar.
I had a really hard time figuring out how to add the fields for frontend editing as well. But I finally figured it out.
First, you're going to need to copy the com_content form edit.php into a template override (/templates/your_template_name/html/com_content/form/edit.php).
In that file, add the extra fields you have. You'll need the name of the field that you put in the xml file for your plugin you already have. Add them right before/after the fields that are already in the file, that you want your fields to appear before/after. Example:
<!-- CUSTOM begin custom fields -->
<?php echo $this->form->renderField('video_url', 'attribs'); ?>
add all your fields in there - replacing 'video_url' with your own field name. The plugin you already have already saved these fields to the 'attribs' part of the article, so you can leave that there.
The plugin that I used to create the fields for the backend is a really simple one based off of this tutorial https://zunostudios.com/blog/development/203-how-to-add-custom-fields-to-articles-in-joomla
What I'd suggest is to go ahead and create that plugin too. Except in the zfields.php file, change "$app->isAdmin()" to "$app->isSite()" - make sure the xml files have the same names as your other plugin xml files, so they save to the same place, and you're done. The fields will show up on the frontend edit form now.
What I'd really recommend is to get rid of the Aixeena plugin, and just make that easy plugin using the tutorial above - it's super easy. When you make it, duplicate the "if ($app->isAdmin())" section, copy it right below it, and change "isAdmin" to "isSite" - and now you've got the entire thing, all your custom fields, both frontend and backend, all in one place. Now just do the edit.php template override, and you'll have them displayed in both the front and backend. I hope that helps - if you need I can upload more example code.
Alright I am completely lost on how to do this so I am just going to throw the question out there and hope somebody can help me in some way or another.
WordPress offers the option to create custom Taxonomies so I got the idea of pulling something out of my hat and creating a custom content section apart from the content section wordpress currently offers.
The website shown above is the only website I have been able to find which currently does this and is on a WordPress platform, as you can see they have the SoundCloud audio player pushed over to one side with the actual content placed to the other side creating that flawless look.
I guess the question here is how can I turn <?php the_content(); ?> into something completely custom pulling from a completely different form in the back end so the same information is not shared.
There are numerous ways to achieve what you want.
Shortcodes
Custom page templates
Custom meta fields to store values like the soundcloud embed url, to afterwards use it in your code.
You can always also enter HTML in the page editor, but for obvious reasons not recommended.
Custom post types allow you to define a new type of content. It will have its own section in admin where you add and edit data separate from normal Wordpress posts. It can have its own templates allowing different layouts, and you can set up custom fields so that it can store different data.
I also recommend taking a look at the Pods Framework. This plugin allows you to define custom content types very easily in the admin interface. You can set up all your fields and data types from there. All that's required then is to create the templates to make it look nice.
The nice thing about these approaches is that while the data is kept separate from standard Wordpress posts, you still have the same familiar UI, so it's easy for none-technical users to update the content.
I am creating my first wordpress plugin. In it, the user will have the option to add new cities and view events on those cities.
My client requirement is that the URL must be like this
SITE_NAME/cities/NY
or
SITE_NAME/cities/Califonia
What is decided is that i will create a folder cities and If user tries to create a new city i will create a file in that folder with that city, Further more I will add the entry into the database as well.I will insert PHP code into the file as well.
Being new to WP plugins. Is my approach right (for creating files)? Is there any other way?
Your approach would work if you WEREN'T using Wordpress, but I would absolutely not advise doing what you're suggesting within the Wordpress Framework.
Rather than trying to reinvent the wheel, just about everything you want can be achieved with existing Plugins. I would absolutely suggest taking this route, especially if you don't have much experience with programming Wordpress Plugins.
Step 1:Install Wordpress
Self-explanatory. Can't do anything without this.
Step 2:Install Types
Installing the Types Plugin will give you a nice interface for registering your own Custom Post Types and many other features for extending Wordpress' core capabilities.
Step 3:Register your Custom Post Type
This is where things start to get complicated. Using Types, Register a Custom Post Type called Event. The reason why you want to have each event as its own Post is because each Event is unique. Cities are meant to encapsulate and define groups of events, which brings us to our next step:
Step 4:Register your Custom Taxonomy
Think of a Taxonomy as a way to classify things. Wordpress comes with two default Taxonomies: Categories (hierarchical) and Tags (non-hierarchical). In your case, you will want to define for your new Event Post Type a non-hierarchical Taxonomy called "Cities".
Step 5:Register your Custom Fields
Custom Fields are the easy part. What defines your event? Maybe some fields that define the start and end times of that particular event? A checkbox denoting free refreshments? The sky's the limit. What defining characteristics would all Events have that makes it an Event? Add those in the form of Custom Fields. These will show up on your Event Editor in the form of Meta Boxes. If you don't see the Meta Boxes on the Edit Page for a particular event, be sure to enable it by clicking Screen Options in the upper-right-hand corner of your screen and ticking the checkbox where your fields would be located.
Step 6:Configure your Permalinks
Much of this can be done either through Types itself (when configuring your Custom Taxonomy), or through .htaccess rewrites, or perhaps even through the Wordpress Permalinks Settings (though, it's fairly limited). My suggestion is to tweak your Custom Taxonomy and Permalink Settings first before messing with .htaccess.
And that's it! Hopefully this should be enough to get you started on everything you need.
maiorano84 wrote a fairly comprehensive guide to setting up the stuff you need, Rather than relying on plugins though, I prefer to show you how to write a plugin to register the custom post type and taxonomy. To that effect, I wrote a little plugin that should do everything you need and it has plenty of comments and links to the docs so that you can understand the Why of things.
Code
https://github.com/fyaconiello/WP_Cities_Events
This plugin does several things
Creates a custom post type Event
Creates a custom taxonomy City
Adds custom metaboxes to Event
Adds City taxonomy to Event
This plugin does not require any additional plugins to be installed, it is dependency free and only uses WP core.
URLS
As far as getting the correct URL Structure, I would suggest you read this thoroughly: http://codex.wordpress.org/Using_Permalinks.
I do not understand the structure you want
CITY is a single term w/i the taxonomy *cities*
EVENT is the post single
SITE_URL/cities/CITY would yield a page of all EVENT posts in that CITY
you need a url like: SITE_URL/cities/CITY/EVENT to read a specific event in a specific city
EDIT on how to urls:
In your Settings -> Permalinks administration panel select: "Post name" and save.
Then, go to your Ce Events -> Cities admin screen.
hover over one of your terms (in my case new york city) and click view.
it should open up that term(city)'s list view and the url structure looks like so: http://wp.local/city/new-york-city/
if you need city to read cities, modify line 102 of the main plugin file i shared with you:
'rewrite' => array('slug' => 'city'),
EDIT 2
Why not create City as a Custom Post Type? You can then define a slug 'cities' and get that result, and also add taxonomies like categories and tags to further aid navigation.
Don't do that. WordPress gives you a goog API for doing what you want to do: managing pretty URLs (slugs), database operations (you don't need to write/read files for that) and the right code workflow for registering and triggering actions.
So, I think you have to start reading the basics about WordPress plugins (its philosophy and API) and then just decide if you want to use its custom post types (ready to use) or if you want to create a specific content type.
yes this is fine approach.One more thing that you can do is that instead of adding the code inside the fie..Pick the code from DB.
Make a table in DB,create a column with varchar as datatype and insert the common code in it .
I trying to write a drupal module. I'm following book "Learning Drupal 6 Module Development ". I have created a new content type (mybio)in module. I'm able create new node and edit node for new content type , it works fine but I'm not able to see new fields for mybio content type when viewing node.
I have placed mybio_info.tpl.php file in module folder and theme folder but nothing works.
Have you implemented the load hook and view hook?
Whenever you create new content types, you need to provide all hooks for changing / loading nodes, such as hook_delete(), hook_insert(), hook_load(), hook_update(), hook_validate() and hook_view().
If that doesn't work, are you sure your template is being used? If not sure, replace all its contents by something simple like '1' and see if that's being shown. If you don't see that, then it's not being used at all; try renaming to node-mybio.tpl.php.
For template naming, take a look at the Core templates and suggestions handbook page.
It looks like you did not implement hook_theme, so the system has no idea you are providing it with a template for this content type.
You can check whether this is the problem by displaying the theme registry using devel.module, or go further and use theme_developer module to check which template is used for everything on-screen.