ThemeShaper Forums » Thematic

[closed]

js/php formatting issue

(2 posts)
  • Started 3 years ago by Manuel
  • Latest reply from Manuel
  • This topic is resolved
  1. Wheew, long time no see. :D

    I have a little js/php formatting issue in my functions.php file.

    I am trying to load this one script (to refresh a webcam image every 2 seconds) but only for category ID 45 — but I have no idea about the formatting.

    Here’s what I got so far:

    // Load the webcam script only for category 45
    function webcam_script() { if (is_category('45')) { ?>
    	<script type="text/javascript">
    	function holdUp()
    	{
    	refreshFreq=2;
    	setTimeout("freshPic()", refreshFreq*1000);
    	}
    	function freshPic()
    	{
    	var currentPath=document.campic.src;
    	var trimmedPath=new Array();
    	trimmedPath=currentPath.split("?");
    	document.campic.src = trimmedPath[0] + "?" + Math.random();
    	holdUp();
    	}
    	</script>
    <?php } }
    add_action('wp_head','webcam_script');

    Plus for the script to kick in I have to add onLoad="holdUp()" to the <body> but have no idea how to do that either.

    This is how it looks so far: http://ads-rantum.de/rantum-live-webcam/

    Posted 3 years ago #
  2. Ha, code is apparently working, just couldn’t verify because webcam was down and image wasn’t loading. :D

    Anyhow, I still have no idea how to add the onLoad="holdUp()" to the <body>, help please. :)

    PS: Added is_single to the code as well, so now the webcam script is loaded if we are in the webcam category or on the webcam post:

    // Load the webcam script if in category ID 45 or on single ID 914
    function webcam_script() { if (is_category('45') || is_single('914')) { ?>
    	<script type="text/javascript">
    	function holdUp()
    	{
    	refreshFreq=2;
    	setTimeout("freshPic()", refreshFreq*1000);
    	}
    	function freshPic()
    	{
    	var currentPath=document.campic.src;
    	var trimmedPath=new Array();
    	trimmedPath=currentPath.split("?");
    	document.campic.src = trimmedPath[0] + "?" + Math.random();
    	holdUp();
    	}
    	</script>
    <?php } }
    add_action('wp_head','webcam_script');
    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.