• Hello, I built a site for a client recently, but they just ask me to add a body_class tag that would say: <body class=”custom navy-seaport-e” onload=”setSPETODate()”>. They gave me a script for the head tag, but this was easy to add and is done. This would be breeze for me with regular html. But can anyone tell me how to do this in PHP? (please be thorough as I dont know how to write PHP) Also I am using Thesis the latest version. So if anyone can help through:

    • Thesis
    • WP
    • plugin or widget

    That would be great!
    Thanks in advance

Viewing 13 replies - 46 through 58 (of 58 total)
  • I meant on the actual page’s HTML code, not the JS or PHP codes I provided. You can probably modify it from WP Admin –> Pages.

    Thread Starter zadok22

    (@zadok22)

    Ok I changed it to this:

    <select id=”listSeaPorteTaskOrders” name=”listSeaPorteTaskOrders”> <option value=”0″> (SeaPort-e Task Orders – Click to Select) </option> <option value=”1″> (No Task Orders as of May 24, 2012) </option> </select>

    but still nothing has changed

    I copy/pasted all the HTML code from your Navy Seaport-e page into a JSFiddle and it is working perfectly.
    In your site, the JS script is being included correctly but the onload function call is not being added, so you might have a problem with jQuery.
    Try to replace the PHP code I posted earlier with this one:

    function sr_add_onload_attr() {
        wp_register_script('sr-add-onload-attr', get_bloginfo('stylesheet_directory').'/custom/custom.js', array('jquery'), '1.0', false);
        wp_enqueue_script('sr-add-onload-attr');
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', false, '1.7.2', false)
    }
    add_action('wp_enqueue_scripts', 'sr_add_onload_attr');

    Thread Starter zadok22

    (@zadok22)

    Ok I will. I see that your test is good on js.fiddle except even there it is not showing the correct date.

    Also do I need to add JQuery into WP or is automatically linked to it?

    Thread Starter zadok22

    (@zadok22)

    I tried putting that last code in twice but it crashed the site both times.

    Yeah, that was my bad. I forgot to close the last line in the function. Try with this version:

    function sr_add_onload_attr() {
        wp_register_script('sr-add-onload-attr', get_bloginfo('stylesheet_directory').'/custom/custom.js', array('jquery'), '1.0', false);
        wp_enqueue_script('sr-add-onload-attr');
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', false, '1.7.2', false);
    }
    add_action('wp_enqueue_scripts', 'sr_add_onload_attr');

    Thread Starter zadok22

    (@zadok22)

    Were getting warmer. It looks like your demo script now from js fiddle, but how do we show the current date if no task orders exist?

    how do we show the current date if no task orders exist?

    That is not so much of a problem. Right now, the way the JS script works is that it tests whether or not the options variable is empty. In the current version, I am manually assigning an object to that variable, which is where Order 1, Order 2, and Order 3 come from.
    What you would need to do instead is retrieve that information from wherever it’s stored: Database, external file, etc and assign it to the options variable. That way, if no info is stored, it means no task orders are available, so the function will return the default message. If there are task orders, they will appear listed in the drop-down.

    Thread Starter zadok22

    (@zadok22)

    I see what you are saying. But I think the client thought it could be coded to say “No Task Orders as of July 26, 2012″(or the current date). He is somewhat of back-end .asp guy himself, but dose not know the WP or Thesis Framework. But is that possible? Not sure, but I believe he will send new code when the Task orders do become available.

    Everything is possible, but I guess it depends on what your client has in mind. To force the code to display the default message, simply change this line in the JS code:

    var options = {1 : 'Order 1', 2 : 'Order 2', 3 : 'Order 3'};

    to

    var options;

    That would render the options variable empty, which will force the code to run the else chunk of the if statement (default message).

    Thread Starter zadok22

    (@zadok22)

    That’s exactly what I want, but, it still shows the other date. But that must be written in the html. I guess i can remove that from the html itself since i can get at it in admin pages

    Thread Starter zadok22

    (@zadok22)

    Ah!! That’s perfect. Can we actually close this now? I am sure I gave you some gray hairs through all of this. I am greatly indebted to you Marventus. GREAT WORK!!!

    PS: I will probably need your help once they start giving me the task orders.

    Thanks Again

    Joel M.

    Thanks. You are welcome. If you are gonna need help later on the same thread, you should probably not mark it as resolved just yet, since it will be closed for furrther answers after a certain time (don’t really know how long it takes).
    Cheers!

Viewing 13 replies - 46 through 58 (of 58 total)
  • The topic ‘Adding body_class for just one page’ is closed to new replies.