Support » Plugins and Hacks » [Resolved] [Plugin: WP Super Cache] Help with Javascript for dynamic content

[Resolved] [Plugin: WP Super Cache] Help with Javascript for dynamic content

  • Hi

    I’ve read the comments on using javascript to call random dynamic content. I searched Google for solutions like a random image rotator. I found one on codelifter.com that appeared pretty straightforward… I thought I could simply switch out a text quotation for a php include statement. But alas, the routine barfs on the <?php part. I’ve tried escaping, stringing, \’ing, to no avail.

    I am trying to dynamically show 1 of 4 sidebar blocks at random. Using a “We have nothing to fear but fear itself.” type quote this routine works fine. It does not like the beginning php statement code.

    Could I ask for tips, suggestions, another approach to accomplish a random block in javascript so WP Super Cache won’t cache it?

    Thanks in advance for looking at this.


    <div class="random sidebar_block">
    <!-- Randomly selecting which block to show -->
    <script language="JavaScript">
    // ==============================================
    // Copyright 2004 by CodeLifter.com
    // Free for all; but please leave in this header.
    // ==============================================
    var Quotation=new Array() // do not change this!
    // Set up the quotations to be shown, below.
    // To add more quotations, continue with the
    // pattern, adding to the array.  Remember
    // to increment the Quotation[x] index!
    Quotation[0] = "<?php include("sidebar_block1.php") ?> ";
    Quotation[1] = "<?php include("sidebar_block2.php") ?> ";
    Quotation[2] = "<?php include("sidebar_block3.php") ?> ";
    Quotation[3] = "<?php include("sidebar_block4.php") ?> ";
    // ======================================
    // Do not change anything below this line
    // ======================================
    var Q = Quotation.length;
    var whichQuotation=Math.round(Math.random()*(Q-1));
    function showQuotation(){document.write(Quotation[whichQuotation]);}

    This is what is in each of my sidebar_block php files. The H2 text, flv and jpg are different in each of the 4 php files. The name of the flv and jpg files will be the same in a given php file. The H2 text will be a simple statement but unique to each php file.

    <h2>Sidebar Block 1</h2>
        <div id="container">&nbsp;</div>
        <script type="text/javascript" src="/jwp/swfobject.js"></script>
        <script type="text/javascript">
            var s1 = new SWFObject("/jwp/player.swf","content1-flv","300","245","9","#FFFFFF");

Viewing 2 replies - 1 through 2 (of 2 total)
  • Note:

    Without WP Super Cache, this routine works:

    <?php   $randompick = mt_rand(1, 4);
        if ( $randompick == "1" ) {
            include("content1-flv.php"); }
        if ( $randompick == "2" ) {
            include("content2-flv.php"); }
        if ( $randompick == "3" ) {
            include("content3-flv.php"); }
        if ( $randompick == "4" ) {
            include("content4-flv.php"); }



    Here’s the solution I came up with pulling together a number of various elements including using BitsOnTheRun video hosting.

    <div class="video">
    <SCRIPT language=JavaScript>
    var htext=new Array()
    var flvid=new Array()
    //insert first variables here where htext[xy]
    htext[0]='More To The Show';
    htext[1]='Here's Today's Feature;
    htext[2]='Encore Presentation';
    htext[3]='That's All Folks';
    //insert second variables here where flvid[xy]
    var xy = Math.floor(Math.random()*4); ); //generates a random whole digit
    // test code
    // var xy= 1
    // document.write(' "'+[xy]+'" ' );
    // document.write(' "'+flvid[xy]+'" ' );
    document.write('<h2>'+htext[xy]+' </h2>');
    document.write('<embed src="http://content.bitsontherun.com/players/'+flvid[xy]+'.swf" wmode="transparent" width="300" height="245" />');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] [Plugin: WP Super Cache] Help with Javascript for dynamic content’ is closed to new replies.