• I am working on a new theme with a custom theme options page (theme-options.php). I have the function set up within theme-options.php so that the options page is working, but I am struggling with setting up header.php correctly.

    Here is my code for theme-options.php to list the Cufon fonts:

    //Automatically List Cufon fonts in Folder
    
    $alt_cufon_path = TEMPLATEPATH . '/scripts/';
    $alt_cufon = array();
    
    if ( is_dir($alt_cufon_path) ) {
        if ($alt_cufon_dir = opendir($alt_cufon_path) ) {
            while ( ($alt_cufon_file = readdir($alt_cufon_dir)) !== false ) {
                if((stristr($alt_cufon_file, ".font.js") !== false) && (stristr($alt_cufon_file, "RTS") == false)){
                    $alt_cufon[] = $alt_cufon_file;
                }
            }
        }
    }
    array_unshift($alt_cufon, "RTS.font.js");

    And here is my code for the Cufon section of theme-options.php:

    array("name" => __('Cufon Fonts','V20'),
    		"type" => "section"),
    
    array("name" => __('Choose a different Cufon font.','V20'),
    		"type" => "section-desc"),
    
    array("type" => "open"),
    
    array( "name" => "Cufon Fonts",
    	"desc" => "Select the Cufon font you would like to use for V20.",
    	"id" => "alt_cufon",
    	"type" => "select",
    	"options" => $alt_cufon,
    	"std" => "default"),
    
    array("type" => "close"),

    And here is what I have so far in `header.php’ at the top of the page:

    <?php //Retrieve Theme Options Data
    global $options;
    $options = get_option('v20_theme_options');?>

    And this is within the <head> tag, after <?php wp_head(); ?>:

    <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/cufon-yui.js"></script>
    <script type="text/javascript"  src="<?php bloginfo('template_directory'); ?>/scripts/PS.font.js"></script>
    <script type="text/javascript"  src="<?php bloginfo('template_directory'); ?>/scripts/Tenderness.font.js"></script>
    <script type="text/javascript"  src="<?php bloginfo('template_directory'); ?>/scripts/Gotham-Lt.font.js"></script>
    <script type="text/javascript"  src="<?php bloginfo('template_directory'); ?>/scripts/RTS.font.js"></script>
    
    <?php //Custon Cufon Fonts
    switch ($options['alt_cufon']) {
    		 case "default.font.js":?>
    		<link rel="index" href="<?php bloginfo('template_directory'); ?>/scripts/default.font.js" type="text/javascript" media="screen" />
    	<?php break; ?>
    	<?php case "Tenderness.font.js":?>
    		<link rel="index" href="<?php bloginfo('template_directory'); ?>/scripts/Tenderness.font.js" type="text/javascript" media="screen" />
    	<?php break; ?>
    	<?php case "PS.font.js":?>
    		<link rel="index" href="<?php bloginfo('template_directory'); ?>/scripts/PS.font.js" type="text/javascript" media="screen" />
    	<?php break; ?>
    	<?php }?>
    
    <script type="text/javascript"> <?php echo get_option("alt_cufon"); ?>
        Cufon.replace('h1, h2, .widget-title, #access, .date-home, #site-title, #site-description');
    </script>

    The default Cufon font is showing up and working, but when I select a different font in theme-options.php, nothing changes.

    Should I not use get_option for this? Or am I not echoing it out correctly? Any help or feedback would be greatly appreciated.

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter deewilcox

    (@deewilcox)

    I decided a better route might be just to have users upload their own fonts and specify only the font family name (per this Github wiki ).

    So here is a different option for theme-options.php:

    array("type" => "open"),
    
    array( "name" => "Cufon Fonts",
    	"desc" => "To replace the default Cufon font included with this theme, remove font family name 'RTS' below and replace it with the font family name of your new font. <br><br>To add new fonts, visit https://cufon.shoqolate.com/generate/ to generate a font. Then, follow the documentation to upload it to your 'scripts' folder. Intermediate programming skills are required.",
    	"id" => "alt_cufon",
    	"type" => "textarea",
    	"std" => "RTS"),
    
    array("type" => "close"),

    Here is the new code for header.php, placed just before the closing </head> tag:

    <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/cufon-yui.js"></script>
    <script type="text/javascript"  src="<?php bloginfo('template_directory'); ?>/scripts/PS.font.js"></script>
    <script type="text/javascript"  src="<?php bloginfo('template_directory'); ?>/scripts/RTS.font.js"></script>
    
    <script type="text/javascript">
        Cufon.replace('h1, h2, .widget-title, #access, .date-home, #site-title, #site-description', { fontFamily: '<?php echo get_option("alt_cufon"); ?>' });
    </script>

    Unfortunately, this is still not working. Feedback would be appreciated!

Viewing 1 replies (of 1 total)
  • The topic ‘Problem calling Cufon option from theme-options.php’ is closed to new replies.