Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

codetempo on "PHP Variable with Theme Customization API"

$
0
0

Is it possible that i can make a live view on PHP Variable with Theme Customization API? Thanks!

from header.php

<div id="number"><?php echo get_theme_mod( 'numberInput' ); ?></div>

above is working fine on live preview but below code is not appearing on live

<?php
$mynumber = get_theme_mod( 'numberInput' );
$cars=array("Nothing","Volvo","BMW","Toyota");
echo $cars[$mynumber];
?>

from function.php (add control)

$wp_customize->add_control(
		'numberInput',
		array(
			'section'  => 'number_options',
			'label'    => 'Number',
			'type'     => 'select',
			'choices'  => array(
				'1'     => 'One',
				'2'     => 'Two',
				'3'   => 'Three'
			)
		)
	);

from theme-customizer.js

(function( $ ) {
	wp.customize( 'numberInput', function( value ) {
		value.bind( function( to ) {
			$( '#number' ).text( to );
		});
	});
})( jQuery );

directly link for the screenshot of code Screenshot


Viewing all articles
Browse latest Browse all 8245

Trending Articles