Tag: php

  • Lightbox 2 and XHTML 1.1 validation

    I recently started using the Lightbox 2 WordPress plugin on my Marbella news site to automatically add the zooming overlay effect to certain images. It is really plug & play and works out of the box.

    I did encounter however that my pages stopped validating as XHTML 1.1 which is the standard doctype on all sites I develop.

    The error in question is due to the square brackets (“[” and “]”) being used to link individual images in one single post together as a gallery under the “rel” attribute. The square brackets are not permitted characters and therefore the W3 Validator spits out the following error message:

    character "[" is not allowed in the value of attribute "rel"
    It is possible that you violated the naming convention for this attribute. For example, id and name attributes must begin with a letter, not a digit.

    To avoid this XHTML 1.1 validation problem simply edit the following line in the Lightbox 2 plugin file named lightbox2.php under the “autoexpand_rel_wlightbox” function:

    from:

    $replacement    = '$1 rel="lightbox['.$post->ID.']">';

    to:

    $replacement    = '$1 rel="lightbox_'.$post->ID.'">';
    

    You should now be able to validate that plugin’s output as XHTML 1.1 with no issues.

  • Upload & Insert images as a WordPress contributor

    For my Marbella news site I recently hired an excellent free-lance writer on Elance to assist me in composing quality articles. As the site is also powered by WordPress I added him as a contributor to start of with. He explained he had some trouble adding images per the guide I sent him. The “Upload/Insert” image button was simply not there.

    So to summarise, the WordPress contributor role apparently lacks this permission. There are a few plugins around that can let you tweak those permissions with more granularity, but I just needed that single change.

    A bit of searching revealed exactly what I needed. One minor change in the theme’s functions file was sufficient to upload & insert images as a WordPress contributor:

    if ( current_user_can('contributor') && !current_user_can('upload_files') )
    	add_action('admin_init', 'allow_contributor_uploads');
     
    function allow_contributor_uploads() {
    	$contributor = get_role('contributor');
    	$contributor->add_cap('upload_files');
    }
    

    This also keeps the core clean for changes which makes upgrading WordPress later on less time consuming.

  • Tags vs. Categories, my ontological classification

    When writing something I usually have a hard time categorising the content as very seldom it will fit into one single category. The solution to this may simply be adding it to more categories instead but then the category hierarchy actually breaks. Instead I definitely prefer to assign tags to content which is much more specific and does not limit you in any way, as there is really no predefined containers but instead any word in the vocabulary can be used to tag your content. During my research determining if WordPress actually had improved the categorisation system I came across an interesting piece of writing about ontology on the web which I recommend you to read through in its full length.

    The latest version of WordPress does seem to handle tags fine although there is some misconception between the tag and category idea. It is somehow mingled together to actually overlap each other although still not the same. I guess the WordPress developers are worried about legacy installations and possible issues during an upgrade path, so they keep things backwards compatible somehow.

    As you can see on this site I make no use of the categories whatsoever. I am forced by WordPress to assign any content to at least one category which I left as the default “Uncategorized”. The name is really irrelevant as I make no use of categories in the display. You may notice the tags assigned to each post just below the title where before the category was displayed.

    To make this little change depending on your theme you may have to edit a couple of files. In my own case I edited three files:

    1. page.php
    2. index.php
    3. single.php

    The change required is the same in all three files, namely replace the following snippet:

    <?php the_category(',') ?>

    with this one:

    <?php /*the_category(',')*/ the_tags( ' ', ', ', ''); ?>

    That is all. Now you will have a nice list of tags instead of the irrational categories list which does not really suit written content.