WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: WP Super Cache] Help with Javascript for dynamic content (3 posts)

  1. boots
    Member
    Posted 5 years ago #

    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.

    -Boots

    <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]);}
    showQuotation();
    </script>
    
    </div>

    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");
            s1.addParam("allowfullscreen","true");
            s1.addParam("wmode","transparent");
            s1.addParam("allowscriptaccess","always");
            s1.addParam("flashvars","file=/jwp/content1.flv&image=/jwp/content1.jpg");
            s1.write("container");
        </script>
  2. boots
    Member
    Posted 5 years ago #

    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"); }
    ?>

    Thanks

    -Boots

  3. boots
    Member
    Posted 5 years ago #

    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]
    
    flvid[0]='jTKE0HYF-9572';
    flvid[1]='FsgRMDZ2-9572';
    flvid[2]='YeONpx87-9572';
    flvid[3]='SZgxeJnD-9572';
    
    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" />');
    
    </SCRIPT>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic