I'm working on a custom WP theme that displays all "pages" as sections in a one page layout.
What I would like to do is add a color chooser to the page designer, so that the user can choose a color to be the background color of that section.
I'm totally new to wordpress so I don't even know what files or functions to look at to add this behavior.
Is there perhaps a prebuilt plugin to do something like this?
Four options:
use a plugin like Advanced Custom Fields or Custom Content Type Manager
ACF has a Lite version to add the meta box programmatically
a helper script like Custom Metaboxes and Fields for WordPress
do it yourself, using this Q&A as example: Add a checkbox to post screen that adds a class to the title
Probably, you'd want to change the visibility of the meta box according to the chosen page template, refer to this Q&A: Custom meta box shown when template is chosen
Related
Is there a simple class or function to extend the WordPress default menu items with new custom fields?
For example, when you go to Appearance - Menus, add a new menu and drag/drop an item to your menu, that actual item has few hidden fields that can be enabled from Screen Options:
Title Attribute
Description
My question is: how to add another custom field there? Like a background field to write the text there and output it in my custom theme like we output the title and description:
<?php echo $navItem->description; ?>
Changed the html code live on the admin page, so you can catch my idea on what I want to do.
Thanks!
ACF is the plugin just what you looking for. Create as many fields as your want, assign it to manu form and you are done.
For more information follow this URL,
https://www.advancedcustomfields.com/resources/adding-fields-menu-items/
Hope this helps.
follow this URL may help you
Adding custom Fields to WordPress Navigation Menu Items
http://jafty.com/blog/how-to-add-custom-fields-to-wordpress-navigation-menu-items/
New to WordPress theme design, and my google searching is not returning what I am after.
I have a theme I have created and its fine, but the text is all hardcoded into the theme.
I want there to be options in the theme appearance settings? (right place?) where a user can e.g. enter their 'about us' text.
But I have no idea what I should be searching or how to pull in that information into my theme.
Im no a beginner to PHP, but just the way WordPress works itself.
A link, search term or quick start is all I need.
I think you might find the (Free) Advanced Custom Fields plugin useful: http://www.advancedcustomfields.com/
You can add unlimited custom fields and create user interfaces for non-technical people to add content to your theme without them touching any code.
If you set up a field named 'about_text', calling it in your theme would look like this:
<?php the_field('about_text'); ?>
First, you should learn how wordpress is working to display the content. In back office, under Settings > Reading you'll find an option that let you tell how you want Wordpress to deal with the front page : is it a listing of the posts, or a static page?
If you choose the first options, it will use the index.php template from your theme folder. If it's a static page, you'll have to select which page to use for displaying the home (a page you created under the Menu page). The template that will be use then is front-page.php.
For every post / page (page is a post_type, just a variation of post) there will be a title field, a wysiwyg content and a featured image which will be displayed in a template. That's all you can manage by default. To display the title you can use the_title, the content the_content and for the featured image you will need the_post_thumbnail - note that those functions will need to be used inside the loop.
In order to display some more fun, you have many tools at your disposal:
Widgets : widgets are displayed in a sidebar - don't take it literally, it's just a zone of your template. You can register a sidebar with register_sidebar (use this inside your functions.php file, within an init hook). Then in your template you can display the sidebar with dynamic_sidebar.
In WP back office, go then under Appearence > Widgets. You will find your brand new sidebar where you can put any kind of widget you want. If you need a wysiwyg widget, I recommend you to install the Black Studio TinyMCE widget.
Custom fields : any post_type (a post type is an entry in wp_posts) in Wordpress have some associated metas store in wp_postmeta. A meta is defined by a key and a value - it's like any post have an associated array that you can customize.
There is two ways to work with custom fields. First, you can use the default Wordpress feature: when editing a page, click on the screen options button on the top right and enable "custom fields". You will now have a new area to work with on the bottom of the page : you can add fields by name (by default it will list the existing fields names but you can add your own) and value. It's good enough to simple text fields. Then in your template, you can get that value with the get_post_meta function.
The other way is to use a custom fields plugin, which allow you to have wysiwyg fields, loops, media uploader, datepicker... Two popular plugins are Advanced Custom Fields and Custom Field Suite. They both allow you to easily create set of fields for any page / post_type from the back office, and provide their own functions to manipulate fields in templates (but you can still use the WP functions if you want). For example, to get a custom field with Custom Field Suite you do: CFS()->get('my_custom_field').
Custom Post Types : sometimes, custom fields and widgets are not really convenient when you deal with a lot of data with possibly associated pages. In that cases, you can create your own post types just like posts or pages, but you can define which capabilities they have. Use register_post_type to define your new post type (still in init hook), that will make a new section available in your back office, just like posts. Then in your template you can query them with get_posts, the WP function that you will probably the most use when you'll start to play with Wordpress. I suggest you to read the WP_Query documentation in order to learn more about it.
And, at last but not least, you can create your own template that you can associate with any pages. For that, create a php file named whatever you want in your theme folder, paste into it the content from page.php and add this PHP comment on top :
/*
Template Name: My Template
*/
Then choose this template in the dropdown when you edit a page (on the right sidebar).
I think you will have enough to play with, but if you want learn more I recommend you to read about Wordpress hooks and the Widget API to create your own widgets.
Have fun with Wordpress!
I am trying to develop one page portfolio wordpress theme .I have a custom post type, called "portfolio". Every posts from portfolio will be displayed in a custom template name portfolio-tempalte. Its my psd of the template.
http://s29.postimg.org/g4g7pr307/ask.png
1st post from custom post type will be displayed at the top, then 2nd post will be displayed at the bottom of 1st post. And it will be going on like this way. But the problem is, if you see my psd template there are completely different background color in different posts . I want to be able to define background color based on users hex color code input.
To do this I have decided to use custom field. Although I dont have enough knowledge about custom field.
So I need help , how to add custom field to custom post type in wordpress. If it is not possible with custom field then please suggest me how to do that.
Try this ,
http://wordpress.org/plugins/advanced-custom-fields/
Advanced custom fields. Hope this helps you
I have recently built a plugin for Wordpress sort of Special Events & News listing. I have a listing page and then a detailed page for every news item. Now in the database I have set up 3 columns named meta_title, meta_description and meta_keywords. I also have All in one SEO plugin installed.
Is there a way how from within the plugin (from the loop where I am showing the content), I can say for example wp_page_meta = $meta_title or something similar?
As I found some tricks on how to do this by hacking the functions.php and header.php for the theme but this is not the right way.
You may want to check out the get_post_meta function in the codex and create custom meta boxes for each event, instead of dealing with the database directly.
http://codex.wordpress.org/Function_Reference/get_post_meta
To add a meta box:
http://codex.wordpress.org/Function_Reference/add_meta_box
I'm trying to find the proper way to add a custom widget to the sidebar on the post/page editor page, specifically, in the sidebar under the 'Page Attributes' section. I've been searching various keywords and coming up short. The Wordpress codex docs are limited, so I'm having any luck there either.
If there is a hook that can be used, what is it?
Else, the Wordpress functions needed to add the new control.
I'm guessing that the meta boxes are only displayed under the post section, so that wouldn't be the area I'm looking to edit.
Also, would using the Widget class be the wrong thing to do?
I'm developing for version 2.8 or higher.
You should pose that question on https://wordpress.stackexchange.com/
In short: Widgets on the editor pages are not widgets, don't use the frontend widget class for them. They are functions (callbacks) you need to register for the editor pages. You can differ between post and page and in later WP versions between the post type as well.
The function to add the meta box to the editor pages is: add_meta_box