customization - Can WP Customizer work with single pages or posts?

admin2025-06-03  3

Theme Customization API has been added in WP 3.4 and is described here:

It makes it easy to add options such as "change background color" for themes. Such options will be stored in the database (in wp_options) with a name of your choice. You can then retrieve your value with get_option( 'field-name' );.

I'm wondering though if this works also with single posts or pages? So, is it possible to set different custom background color for each page with this tool and retrieve values using get_post_meta($id_of_the_current_post, 'field-name');?

Theme Customization API has been added in WP 3.4 and is described here: https://codex.wordpress/Theme_Customization_API

It makes it easy to add options such as "change background color" for themes. Such options will be stored in the database (in wp_options) with a name of your choice. You can then retrieve your value with get_option( 'field-name' );.

I'm wondering though if this works also with single posts or pages? So, is it possible to set different custom background color for each page with this tool and retrieve values using get_post_meta($id_of_the_current_post, 'field-name');?

Share Improve this question asked Jun 26, 2013 at 9:59 AtadjAtadj 2,1828 gold badges29 silver badges40 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 4

That's not exactly what the theme customizer is for. The theme customizer should be reserved for big (global) items. Like the background color of every page, not just a single page. There isn't a way (that I know of) to change things on a per page basis.

For things that are page specific to the page/post, I'd recommend using the custom post meta. Here's a pretty good example: http://wp.smashingmagazine/2011/10/04/create-custom-post-meta-boxes-wordpress/

You can do this, though it may not be rich in documentation. The WP Customize control comes with WP_Customize_Control::active_callback(). On active callback, you can create an option that will only appear if you are in a post or a page or custom post type, etc...

Read the sectionon "Contextual Controls" here. I apologize for not writting on a specific demo, but the author of this given post appears to be much better at demonstrating this.

Eric Lewis just presented an idea that might make it possible. Check out Custom CSS per post in WordPress.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748959977a315172.html

最新回复(0)