PHP to Show By Default (Call or array?)

2019-09-08 22:36发布

问题:

This is more of a PHP question than a WordPress question, but I am using it in a WP theme.

In my options I am allowing users to show/hide breadcrumbs. However, when there are no preferences yet selected and saved (for example, if somebody were to install the theme) the breadcrumbs aren't displayed by default... and I would like them to be.

Below is my code. I'm confident I'm just missing a very small piece of code here...

Here is the array I am using:

array( "name" => "Display breadcrumbs on post pages?",
    "desc" => "Choose whether or not to display breadcrumbs, that is, the post trail.",
    "id" => $shortname."_breadcrumbs",
    "type" => "select",
    "options" => array("Yes", "No"),
    "std" => "Yes"),

Here is how I am calling the breadcrumbs in my posts:

<?php
if ( get_option('to_breadcrumbs') == 'Yes' ) {
     if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs();
} ?>

回答1:

This should probably work

if ( get_option('to_breadcrumbs') != 'No' ) {


回答2:

Try using a default value:

if ( get_option('to_breadcrumbs','Yes') == 'Yes' ) {

If that doesn't work, try putting this in and see what it prints:

echo get_option('to_breadcrumbs','Yes');