PHP to Show By Default (Call or array?)

2019-09-08 22:00发布

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();
} ?>

2条回答
Ridiculous、
2楼-- · 2019-09-08 22:24

This should probably work

if ( get_option('to_breadcrumbs') != 'No' ) {
查看更多
仙女界的扛把子
3楼-- · 2019-09-08 22:50

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');
查看更多
登录 后发表回答