Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Filling a external file with code and pulling it into the <head> of another page

Options
  • 14-06-2010 8:39pm
    #1
    Registered Users Posts: 203 ✭✭


    Hey,

    I am trying to move a site over to Wordpress, but one page has a massive amount of code in the head tag from a price generator script to work. It works fine on the old HTML site, but even when I copy this code in as a custom field in wordpress it just wont work.

    It might be because the script is so long, so what I am wondering is can I paste it all into another file, and then just link to this as a custom field?

    What would I insert in Wordpress to load this file? And what would I call it etc? And is it even possible?


Comments

  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    You could call it using the PHP include_once() function.

    <?php include_once "yourheader.php"; ?>

    I'm just wondering why you tried put it into a custom field. Can you paste or include the code in the theme header.php in the head section? You can put your include_once() in there if you really need it to be in a separate file.

    Give more info if this doesn't help and we'll try and sort you.


  • Registered Users Posts: 203 ✭✭AMPSound


    I didnt want to put it into header.php as it is huge, and will only be used on 3 or 4 pages. Does that make sense, or should I just put it in there?

    Here is the old one (which is working):
    http://ampsoundsystems.com/quote/quote.html

    And here is the new one: (dont mind the layout, just want to get it working first)
    http://ampsoundsystems.com/site/quote

    If you take a look at the source of the new one, the script for the price thing is a mess! Probably because its in a custom field.

    What would you recommend I do?


  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    Ye gods. I thought I'd seen the last of the dreaded mm_menus...

    First a disclaimer - I'm not a JavaScript guy, I usually hack it or go find an expert. Ok, so this is your code (from the working page - the WP install looks garbled and is probably broken due to formatting):
    <SCRIPT LANGUAGE="JavaScript">
    var called=false;	
    var T_Price=0;
    var Line1_flag;
    var Line1_print="";
    var Line2_flag;
    var Line2_print;
    var Line3_flag;
    var Line3_print;
    var Line4_flag;
    var Line4_print;
    var Line5_flag;
    var Line5_print;
    var Line6_flag;
    var Line6_print;
    function compute(form){
    called=true;
    //-------Productline 1----------
    
    if (form.Productline1[0].selected){
    	Line1_flag =80;
    	Line1_print="PA-800";
    }
    else if (form.Productline1[1].selected){
    	Line1_flag =120;
    Line1_print="PA-1600";
    }
    else if (form.Productline1[2].selected){
    	Line1_flag =200;
    	Line1_print="PA-2400";
    }
    else if (form.Productline1[3].selected){
    	Line1_flag =250;
    	Line1_print="PA-3200";
    }
    else if (form.Productline1[4].selected){
    	Line1_flag =280;
    	Line1_print="PA-4000";
    }
    else if (form.Productline1[5].selected){
    	Line1_flag =350;
    	Line1_print="PA-4800";
    }
    //-------Monitors Required----------
    if (form.Productline2[0].selected){
    	Line2_flag=0;
    	Line2_print="None";
    }
    if (form.Productline2[1].selected){
    	Line2_flag=20;
    Line2_print="One";
    }
    if (form.Productline2[2].selected){
    	Line2_flag=40;
    Line2_print="Two";
    }
    if (form.Productline2[3].selected){
    	Line2_flag=60;
    Line2_print="Three";
    }
    if (form.Productline2[4].selected){
    	Line2_flag=80;
    Line2_print="Four";
    }
    //-------Engineer Required?-----------
    if (form.Productline3[0].selected){
    	Line3_flag=0;
    	Line3_print="None";
    }
    if (form.Productline3[1].selected){
    	Line3_flag=60;
    Line3_print="Setup Only";
    }
    if (form.Productline3[2].selected){
    	Line3_flag=100;
    Line3_print="Basic";
    }
    if (form.Productline3[3].selected){
    	Line3_flag=100;
    Line3_print="Single Band";
    }
    if (form.Productline3[4].selected){
    	Line3_flag=150;
    Line3_print="Multiple Bands";
    }
    
    //------ Recording-------
    if (form.Productline4[0].selected){
    	Line4_flag=250;
    Line4_print="Yes";
    }
    if (form.Productline4[1].selected){
    	Line4_flag=0;
    Line4_print="No";
    }
    //-------Transport-------
    if (form.Productline5[0].selected){
    	Line5_flag=0;
    	Line5_print="Collection";
    	}
    if (form.Productline5[1].selected){
    	Line5_flag=250;
    	Line5_print="Antrim";
    	}
    if (form.Productline5[2].selected){
    	Line5_flag=215;
    	Line5_print="Armagh";
    	}
    if (form.Productline5[3].selected){
    	Line5_flag=100;
    	Line5_print="Carlow";
    	}
    	if (form.Productline5[4].selected){
    	Line5_flag=180;
    	Line5_print="Cavan";
    	}
    	if (form.Productline5[5].selected){
    	Line5_flag=215;
    	Line5_print="Clare";
    	}
    	if (form.Productline5[6].selected){
    	Line5_flag=230;
    	Line5_print="Cork";
    	}
    	if (form.Productline5[7].selected){
    	Line5_flag=315;
    	Line5_print="Derry";
    	}
    	if (form.Productline5[8].selected){
    	Line5_flag=240;
    	Line5_print="Down";
    	}
    	if (form.Productline5[9].selected){
    	Line5_flag=40;
    	Line5_print="Dublin";
    	}
    	if (form.Productline5[10].selected){
    	Line5_flag=230;
    	Line5_print="Fermanagh";
    	}
    	if (form.Productline5[11].selected){
    	Line5_flag=280;
    	Line5_print="Galway";
    	}
    	if (form.Productline5[12].selected){
    	Line5_flag=340;
    	Line5_print="Kerry";
    	}
    	if (form.Productline5[13].selected){
    	Line5_flag=115;
    	Line5_print="Kildare";
    	}
    	if (form.Productline5[14].selected){
    	Line5_flag=125;
    	Line5_print="Kilkenny";
    	}
    	if (form.Productline5[15].selected){
    	Line5_flag=150;
    	Line5_print="Laois";
    	}
    	if (form.Productline5[16].selected){
    	Line5_flag=220;
    	Line5_print="Leitrim";
    	}
    	if (form.Productline5[17].selected){
    	Line5_flag=250;
    	Line5_print="Limerick";
    	}
    	if (form.Productline5[18].selected){
    	Line5_flag=180;
    	Line5_print="Longford";
    	}
    	if (form.Productline5[19].selected){
    	Line5_flag=160;
    	Line5_print="Louth";
    	}
    	if (form.Productline5[20].selected){
    	Line5_flag=300;
    	Line5_print="Mayo";
    	}
    	if (form.Productline5[21].selected){
    	Line5_flag=160;
    	Line5_print="Meath";
    	}
    	if (form.Productline5[22].selected){
    	Line5_flag=200;
    	Line5_print="Monaghan";
    	}
    	if (form.Productline5[23].selected){
    	Line5_flag=165;
    	Line5_print="Offaly";
    	}
    	if (form.Productline5[24].selected){
    	Line5_flag=220;
    	Line5_print="Roscommon";
    	}
    	if (form.Productline5[25].selected){
    	Line5_flag=270;
    	Line5_print="Sligo";
    	}
    	if (form.Productline5[26].selected){
    	Line5_flag=240;
    	Line5_print="Tipperary";
    	}
    	if (form.Productline5[27].selected){
    	Line5_flag=70;
    	Line5_print="Tyrone";
    	}
    	if (form.Productline5[28].selected){
    	Line5_flag=70;
    	Line5_print="Waterford";
    	}
    	if (form.Productline5[29].selected){
    	Line5_flag=70;
    	Line5_print="Westmeath";
    	}
    	if (form.Productline5[30].selected){
    	Line5_flag=70;
    	Line5_print="Wexford";
    	}
    	if (form.Productline5[31].selected){
    	Line5_flag=70;
    	Line5_print="Wicklow";
    	}
    
    	
    	
    //-------Accessory Pack-------
    if (form.Productline6[0].selected){
    	Line6_flag=0;
    	Line6_print="PA Only";
    	}
    if (form.Productline6[1].selected){
    	Line6_flag=45;
    Line6_print="DJ";
    	}
    if (form.Productline6[2].selected){
    	Line6_flag=20;
    	Line6_print="Singer/Songwriter";
    	}
    if (form.Productline6[3].selected){
    	Line6_flag=40;
    	Line6_print="Band (up to 12 Channels)";
    	}
    	if (form.Productline6[4].selected){
    	Line6_flag=60;
    	Line6_print="Band (up to 24 Channels)";
    	}
    T_Price=Line1_flag+Line2_flag+Line3_flag+Line4_flag+Line5_flag+Line6_flag;
    form.T_Price.value="  &#8364; "+ T_Price;
    }
    function print(form){
    if(!called){
    	compute(form);
    }
    text = ("<HEAD><TITLE>'AMP Sound Systems'</TITLE></HEAD>");
    text = (text +"<BODY BGCOLOR =  '#FFFFFF' ><CENTER><B><FONT SIZE = 3><FONT COLOR=BLUE>AMP Sound Systems Quote</FONT></FONT></B>");
    text= (text +"<br></CENTER>");
    text=(text+"<hr>");
    text=(text+"<TABLE BORDER =0><TR VALIGN=Top><TD VALIGN=Top>");
    text=(text+"<B>Productline1: <BR>Productline2: <BR>Productline3: <BR>Productline4: <BR>Productline5: <BR>Productline6:");
    text=(text+"</B></TD><TD>")
    text=(text+"<B>"+ Line1_print+"<BR>"+ Line2_print+"<BR>"+ Line3_print+"<BR>");
    text=(text+ Line4_print+"<BR>"+ Line5_print+"<BR>"+ Line6_print+"<BR>");
    text=(text+"<TD></TR></TABLE><hr>");
    text=(text+"<B><FONT COLOR=RED>Total Cost:</FONT>"+"       &#8364;"+T_Price);
    text=(text+"<BR><BR><FONT SIZE=-1><FONT COLOR=Gray>To print, right click and press Print. Or press Ctrl-P.</FONT></FONT>");
    text=(text+"</body></html>");
                    msgWindow=window.open("","displayWindow","toolbar=no,width=375,height=250,directories=no,status=yes,scrollbars=yes,resize=no,menubar=yes")
                    msgWindow.document.write(text)
                    msgWindow.document.close()
    }
    </SCRIPT>
    


    Back to your question - yep, you can still put it into the header, but just call it if the page id is one of the pages you want it to show on. You need to figure out the (numeric) post id for the page you want it on (the Quote page). To get that, go into wp-admin and hover over the edit page link for that page. Note the number - that's the post ID. Replace XYZ below with this numeric value.
    <?php 
    global $wp_query;
    $thePostID = $wp_query->post->ID;
    if ($wp_query->post->ID == XYZ) { ?>
    
    /* Enter Your JavaScript Code Here
    (either as an include & function call, or paste the code) */
    
    <?php } /* endif ($post->ID == x)  */ ?>  
    </head>
    

    That will only include your Javascript on the page with the ID from the if statement.

    Post up here if you have any problems.


  • Registered Users Posts: 203 ✭✭AMPSound


    You actually are a legend! Thanks so much for spending the time to answer that for me!

    I will let you know how I get on.

    Thanks again.


  • Registered Users Posts: 203 ✭✭AMPSound


    Oh my god that worked! :cool: :D

    Thank you so much for such an easy to follow walk-through.

    I owe you many pints!! :)

    Thanks again.
    Eoin


  • Advertisement
  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    AMPSound wrote: »
    I owe you many pints!! :)

    Music to my ears :)

    Glad it worked - one other thing that might be useful for you - if you need the quote to work on multiple pages then you can modify the if condition as follows:

    if ( ($wp_query->post->ID == XYZ) || ($wp_query->post->ID == ABC) || ($wp_query->post->ID == DEF) )

    ABC/DEF being the page ids for the other pages it's needed on, and || is "OR".


  • Registered Users Posts: 203 ✭✭AMPSound


    I just popped on to ask that very question! You are way ahead of me!

    Cant thank you enough!


Advertisement