WordPress.org

Ready to get started?Download WordPress

Forums

WP-Slimbox2 Plugin
Fallback if JavaScript is disabled and for mobile devices (2 posts)

  1. Bernhard
    Member
    Posted 1 year ago #

    Hey,

    I would like to have a fallback solution in case JavaScript is not enabled and for mobile devices.

    If JavaScript is enabled, I get the link by wp_get_attachment_url but if it's disabled and for mobile devices it should be get_permalink so it opens the attachment-page instead of only the image.

    Thanks in advance!
    Bernhard

    http://wordpress.org/extend/plugins/wp-slimbox2/

  2. Bernhard
    Member
    Posted 1 year ago #

    Hey,

    found a simple solution for a fallback in case JavaScript is not enabled as you can see at this gallery.

    Code in the gallery-template:

    <ul id="images">
    			<?php
    			$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ASC') );
    			foreach ( $attachments as $attachment_id => $attachment ) {
    				$image_attributes = wp_get_attachment_image_src( $attachment_id, 'medium' );
    				echo "<li class=\"thumb";
    				echo $image_attributes[1]; // width
    				echo "x";
    				echo $image_attributes[2]; // height
    				echo "\"><script type=\"text/javascript\">document.write('<a href=\"";
    				echo wp_get_attachment_url( $attachment_id );
    				echo "\" rel=\"lightbox\">";
    				echo wp_get_attachment_image( $attachment_id, 'medium' );
    				echo "</a>');</script>";
    				echo "<noscript><a href=\"";
    				echo get_permalink( $attachment_id );
    				echo "\">";
    				echo wp_get_attachment_image( $attachment_id, 'medium' );
    				echo "</a></noscript>";
    				echo "</li>
    			";
    			} ?></ul>

    Now it would be nice to find a solution for mobile devices.

    Bernhard

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic