SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    634
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    changing background images page to page w/jquery?

    Last post today I hope.
    I put this one up before, but going to try a simplified version.
    I have two pages. sharing the same css stylesheet but
    page one has
    <body id=''one">
    second page has
    <body id=''two">
    they both share the same header.php that only has the tag for <body id=''one">.

    In the shared stylesheet.
    #main{background: ulr('image1.png');}
    and
    #two{background: ulr('image2.png');}

    how can I use jquery to change the background image when the user goes to the second page?

    thank you
    D

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    Is this a WordPress site?

  3. #3
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    634
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    eventually yes.
    but if I can get it to work static even it'd be a start.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    If it's WP, then the $pagename variable holds the title of the current page.
    You can then query this to see where you are and set a different class accordingly.

    E.g.

    PHP Code:
    if($pagename == "page-one"){
      $class = "one";
    } else {
      $class="two";
    } ?>'

    <body class="<?php echo $class?>">

  5. #5
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    634
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thank you will try it. That would be nice it if worked.
    and does that code go into each page?

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    Hi there,

    No, it goes into your header file.
    Let me know how you get on.

  7. #7
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    634
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Pullo, could I get more advice on this...


    this is for my engSub.php it has a <body id="engBody"> the page is a subtemplate.

    In the main stylesheet it has the correspondent body tag info
    Code:
    #engBody{background info stuff...}
    Now...I put this in the header.php
    Code:
    <body <?php body_class(); ?> id="mainBody"> <!-- start body-->
    
    <?php if($pagename == "engSub"){
      $class = "#engBody"; (this doesn't seem correct)
    } else {
      $class="two"; () (don't think I need this...but i have at least three more subtemplates w/diff body tags)
    } ?>'
    
    <body class="<?php echo $class; ?>">
    Thx
    D

  8. #8
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    I was thinking more along the lines of this.
    This is what I use for my blog:

    header.php

    PHP Code:
    <?php 
      
    if($pagename == "page-one"){ 
        
    $class "one"
      } else { 
        
    $class="two"
      } 
    ?>
    ?>

    <!DOCTYPE HTML>
    <html <?php language_attributes(); ?>>
      <head>
        <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
      
        <title>
          <?php
        
    if(is_front_page()){ echo "Home"; }
              if (
    function_exists('is_tag') && is_tag()) {
                 
    single_tag_title("Tag Archive for &quot;"); echo '&quot; - '; }
              elseif (
    is_archive()) {
                 
    wp_title(''); echo ' Archive - '; }
              elseif (
    is_search()) {
                 echo 
    'Suche nach &quot;'.wp_specialchars($s).'&quot; - '; }
              elseif (!(
    is_404()) && (is_single()) || (is_page())) {
                 
    wp_title(''); echo ' - '; }
              elseif (
    is_404()) {
                 echo 
    'Nicht gefunden - '; }
              if (
    is_front_page()) {
                 
    bloginfo('name'); echo ' - 'bloginfo('description'); }
              else {
                  
    bloginfo('name'); }
              if (
    $paged>1) {
                 echo 
    ' - page '$paged; }
           
    ?>
        </title>
              
        <link href="<?php echo get_stylesheet_directory_uri(); ?>/style.css" rel="stylesheet" type="text/css">

        <?php if (is_search()) {?><meta name="robots" content="noindex, nofollow" /><?php ?>
        <?php wp_head(); ?>
      </head>

      <body class="<?php echo $class?>">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •