Jump to content

Alt-tags in slider images


Ramon
 Share

Recommended Posts

Yes you can

There is a module for this somewhere that extends the images field functions.

But the easiest and fastest way is to use the Processwire api together with the php explode function for this.

I have a snippet for this somewhere but cannot find it right now.

I will post back when I find it.

  • Like 1
Link to comment
Share on other sites

Here is the snippet

<?php
        $intro = $pages->get('/intro/');
        foreach($intro->images as $image) {
        $image = $image->size(500, 350);
        $lines = $image->description;
        $words = explode(",", $lines);
        echo "<div class=" . '"da-slide"' . ">" . "\n";
        echo "<h2>" . $words[0] . "</h2>" . "\n";
        echo "<p>" . $words[1] . "</p>" . "\n";
        echo "<a href=" . '"#"' . " class=" . '"da-link"' .">" . $words[2] . "</a>" . "\n";
        echo "<div class=" . '"da-img"' . ">" . "<img src=" . '"' . $image->url . '"' . " alt=" . '""' . ">" . "</div>" . "\n";
        echo "</div>" . "\n";
        }
        ?>   

 

In my above example I used php explode for a title, a paragraph and links, but as you see it, you will get the idea.

Simply add your alt description as a second word in your image description field and use php explode to echo it inside alt=" . . . "

Your image description field will then look like this:        image description, alt description, other description, . . . . .

Use a comma as a separator

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...