Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Including extra CSS/JS to header page level instead of new template
#5
I needed a way to load predefined scripts and css into the header and footer on a per page basis;

to make it easy, first i setup each set of scripts and css as unique components;

for example this component is called "prettyphoto-header":

Code:
<link rel="stylesheet" media="all" href="<?php get_theme_url(); ?>/style/css/prettyPhoto.css" />
    <script type="text/javascript" src="<?php get_theme_url(); ?>/style/js/quicksand.js"></script>
    <script type="text/javascript" src="<?php get_theme_url(); ?>/style/js/portfolio.js"></script>
    <script type="text/javascript" src="<?php get_theme_url(); ?>/style/js/jquery.prettyPhoto.js"></script>

then i created custom fields called "headercomp" and "footercomp" both as type dropdown box, and then listed all of the relevant components (leaving the first line blank so it defaults to nul);

then in each page, you can select any of the header/footer code (in the components) to load;

in the theme file, i put this in the head:

Code:
<?php $headercomp = return_custom_field('headercomp'); ?>
<?php get_component($headercomp); echo"\n" ?>

and this in the footer

Code:
<?php $footercomp = return_custom_field('footercomp'); ?>
<?php get_component($footercomp); ?>

it works great...!

Only issue is that i'm not sure if the php code is optimal; it does work, but if any php gurus out there know of a better way to code those tags, let me know!

-marc
Reply


Messages In This Thread
Including extra CSS/JS to header page level instead of new template - by alienee2 - 2012-04-19, 02:55:05



Users browsing this thread: 1 Guest(s)