Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJerry Schrader
4,396 PointsMaybe I am mistaken, but it seems like steps were skipped, where html was added for the form
In stage 2 there is html added to your presentation that I did not see added, unless I missed something.
3 Answers
Patrick O'Dacre
15,471 PointsYou are correct. I noticed the same thing.
Here's the code as best I can make it out:
Placed in the checkbox callback function:
$option = get_option( 'wpt_show_slideshow' );
$html = '<input type="checkbox" id="wpt_show_slideshow" name="wpt_show_slideshow" value="1"' . checked( 1, $option, false ) . '/>';
$html .= '<label for="wpt_show_slideshow">Check to enable slideshow on the homepage</label>';
echo $html;
Patrick O'Dacre
15,471 Points// get_option is the WordPress function to grab a value from the WordPress options table in the database.
// 'wpt_show_slideshow' is the specific database key we're using to grab our specific option value.
$option = get_option( 'wpt_show_slideshow' );
// Setting up our form field referencing wp_show_slideshow key, ensures the value being submitted from this field is stored in the wp_show_slideshow row in the options table.
// Here we're creating a variable called 'html' and we're adding a long string of html code to that variable.
$html = '<input type="checkbox" id="wpt_show_slideshow" name="wpt_show_slideshow" value="1"' . checked( 1, $option, false ) . '/>';
// here the 'period' before the 'equals' sign adds this new string to the previous one.
$html .= '<label for="wpt_show_slideshow">Check to enable slideshow on the homepage</label>';
// here we echo out the combined strings of html.
echo $html;
As you play with the options table, I recommend you open the database in your IDE (like PhpStorm) or with a program meant for browsing databases (phpMyAdmin works just fine) to see how your code is actually affecting the database. You can view the options table in the WordPress database and see your key 'wpt_show_slideshow' there with your values in it.
Jon Sonneborn
322 PointsBut there is no explanation about this code.
$option = get_option( 'wpt_show_slideshow' );
$html = '<input type="checkbox" id="wpt_show_slideshow" name="wpt_show_slideshow" value="1"' . checked( 1, $option, false ) . '/>';
$html .= '<label for="wpt_show_slideshow">Check to enable slideshow on the homepage</label>';
echo $html;