SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A List Apart (ALA) script tip implementation

    I successfully implemented my first php script (I say mine but I just copied the example one). I was pretty pleased about the results too.

    Then, as you do, I read through the comments and saw a comment about inserting a caption.

    Unfortunately all the caption modification did was prove 2 things to me:

    1. that I know absolutely nothing about php

    2. that copying something in real life is the same as copying something in school ie. you don't really learn anything.

    Consequently I'm hoping that someone can let me look over their metaphorical shoulder and copy where to put these statements in the script.

    The script

    The caption script mod suggestion

    On the other hand please feel free to put on your best teacher voice and tell me that I should stop copying and figure it out for myself.

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I had a quick glance and here's my best guess.
    In your images ini file add a caption property to the images, for example:
    Code:
    [FOO]
      src   = img/foo.jpg
      alt   = Foo Image
      url   = http://foobar.com/
      title = Some Foo
      caption = Foo Caption Here
    Then in the rotator script you should be able to add this code where you want the caption to appear, for the example below I've added it onto the end of the script:
    PHP Code:
    # if an url was specified, output the closing A HREF tag
        
    if ( $images[$img]['url'] ) {
          echo(
    '</a>');
        }
        
    //THIS IS THE NEW CODE
        
    if(isset($images[$img]['caption'])) {
            echo 
    '<p>'.$images[$img]['caption'].'</p>';
        }
      }


    ?> 

  3. #3
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked a treat. Thanks.

    Of course that now leads to another question... how do I make the caption a link also?

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add caption_link = http://caplink.com to the .ini file for each image. Then the code to:
    PHP Code:
    # if an url was specified, output the closing A HREF tag
        
    if ( $images[$img]['url'] ) {
          echo(
    '</a>');
        }
        
    //THIS IS THE NEW CODE WITH LINKED CAPTIONS
        
    if(isset($images[$img]['caption'])) {
            if(isset(
    $images[$img]['caption_link']))
               echo 
    '<p><a href='.$images[$img]['caption_link'].'">'.$images[$img]['caption'].'</a></p>';
            else
               echo 
    '<p>'.$images[$img]['caption'].'</p>';
        }
      }
    ?> 
    That should also give you the option of not linking some captions if you want, if you don't want one to be a link just leave the caption_link out of it's ini setting.

  5. #5
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent stuff.

    I think that there is an extra pair of speech marks in the code for the link.

    echo '<p><a href='.$images[$img]['caption_link'].'"> but maybe it isn't.

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I missed one off:
    <a href='

    Should be:
    <a href="'


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
  •