Showing posts from the category "PHP" - page 2

  • Limit Items (e.g. News posts)

    Posted on 10th March 2011.

    If you would like to limit the amount of items coming out of an array (for example the first 5 news items), then before your loop (e.g. while), specify your start and finish points $A = array_slice($A, START, END); while $A { For example, if you did want to only pull out the…

  • Get an 'Even' Class

    Posted on 16th February 2011.

    This PHP statement applies class="even" to every other element when in a loop. Since this post was originally created, CSS has somewhat evolved, allowing you to do div:nth-child(even) to style every other element I often use this on tables to get an even class to help divide up the rows, but…

  • Giving something a 'Last' Class

    Posted on 14th February 2011.

    If you want to apply a different class to the last item in a list generated by PHP, start off with Setting the $lastOne variable to the end of your list <?php $lastOne = end($your_array); This stores the details of the last one in your list into the lastOne…

  • Using PHP to get the dimensions of an image

    Posted on 4th February 2011.

    The following code will get the dimensions of an image: <?php list($width, $height, $type, $attr) = getimagesize(PATH_TO_IMAGE); I found this useful when using a lightbox to load an image that I didn't initially know the size of, to ensure the lightbox positioned itself in the middle, based on the…