我有一个主题,我可以检索标题上的主题选项。php文件,并将选项保存在变量中。
<?php
global $options_name;
$options = get_option($options_name);
//$options returns the theme options when called on header.php but an empty array on index.php
?>
当我声明相同的全局变量并将选项存储在索引中的变量中时,返回一个空数组。主题文件的php。
如何在索引中检索主题选项。php文件,因为它在头文件中工作良好。php?
这是标题。php文件:
<?php global $option_name;
$options = get_option($option_name);
?>
<!DOCTYPE PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#" >
<head>
<meta charset="<?php bloginfo(\'charset\'); ?>" />
<meta name="viewport" content="width=device-width" />
<title><?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;
wp_title( \'|\', true, \'right\' );
// Add the blog name.
bloginfo( \'name\' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( \'description\', \'display\' );
if ( $site_description && ( is_home() || is_front_page() ) )
echo " | $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo \' | \' . sprintf( __( \'Page %s\', \'PuraVida\' ), max( $paged, $page ) );
?></title>
<link rel="stylesheet" type="text/css" href="<?php bloginfo(\'template_directory\'); ?>/style.css" />
<link href=\'http://fonts.googleapis.com/css?family=Oswald:400,700\' rel=\'stylesheet\' type=\'text/css\'>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="<?php bloginfo(\'template_directory\'); ?>/js/jquery-dropdown.js"></script>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header class="wrap">
<div class="logoarea">
<a href="<?php bloginfo(\'wpurl\'); ?>"><img src="<?php echo $options["logo"]; ?>" /></a>
</div>
<div class="navmenu">
<?php wp_nav_menu( array( \'container_class\' => \'menu-header\', \'theme_location\' => \'primary\', \'fallback_cb\' => FALSE ) ) ?>
</div>
</header>
这是索引。php文件:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div class="clear"></div>
<?php get_footer(); ?>
最合适的回答,由SO网友:Vinod Dalvi 整理而成
尝试直接传递“my\\u theme\\u options”以获取\\u option()函数,而不是将其存储在变量中,如下所示。
$options = get_option(\'my_theme_options\');
而不是
global $option_name;
$options = get_option($option_name);