how to add link to the post with an image

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
gizmotr
Regular
Posts: 6
Joined: Mon Mar 27, 2006 5:04 am

how to add link to the post with an image

Post by gizmotr »

Hey ,
I have an image for every single post I make and I would like to users be able to click on the image to read the details of the article. How can I do this ?

Thanks
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: how to add link to the post with an image

Post by garvinhicking »

Hi!

So you insert an image into the "body text" for your entry, and then insert the text you want your users to read into the "extended body"?

You can just wrap a link around an image (<a href...> or via the WYSIWYG editor), but first need to save the article to get it's future URL...?

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
gizmotr
Regular
Posts: 6
Joined: Mon Mar 27, 2006 5:04 am

Post by gizmotr »

hey garvin ,

Yeah that is my last resort but I was wondering if I can link it when I create it rather then saving first getting the url and editing it :)
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I use permalinks to know the URL of the article beforehand. Then the link is just <permalink>#extended.

If the image always goes in the same place, you might be able to do this with a few changes in the entries.tpl and an extended property to hold the image.

Finally, consider a simple Smarty bit in the entries.tpl. Find this bit:

Code: Select all

            <div class="serendipity_entry_body">
                {$entry.body}
            </div>
and replace it with:

Code: Select all

            <div class="serendipity_entry_body">
                {$entry.body|replace:'%extended%':"`$entry.link`#extended"}
            </div>
Be careful with the backticks and things; I haven't tried this yet myself, but the Smarty docs say it'll work.

Then you can just make your image with <a href="%extended%">, and it'll be replaced with the extended entry link. Only drawback is that %extended% will be replaced everywhere else in the body, too. Choose your marker wisely.
Judebert
---
Website | Wishlist | PayPal
gizmotr
Regular
Posts: 6
Joined: Mon Mar 27, 2006 5:04 am

Post by gizmotr »

oh makes a lot of sense ! I'll definetly try it tomorrow
Thanks a lot !
gizmotr
Regular
Posts: 6
Joined: Mon Mar 27, 2006 5:04 am

Post by gizmotr »

okay , I tried this but I'm using a different template and i have this :

Code: Select all

 
            <div class="serendipity_entry_body">
                <?php echo $this->_tpl_vars['entry']['body']; ?>

            </div>
what can I do ?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Are you sure you are editing *.tpl files and not *.tpl.php files? The output you relate to usually is only found in the templates_c folder. Do not touch these files. Only edit the files in templates/.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
clipmaster
Regular
Posts: 6
Joined: Wed Nov 08, 2006 7:12 pm

Post by clipmaster »

does this "%extended%" work? anyone tried it?

... cause i tried it and i had no success :cry:
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I haven't really tried it yet, but I realize that my instructions may have been non-intuitive. Here's the breakdown:

1) Edit entries.tpl (as described in previous post, such that any occurrence of "%extended%" is replaced by the URL of the extended body).

2) Create a new entry; this was stipulated in the question to be a single image.

3) Wrap the image in an anchor, thusly:

Code: Select all

<a href="%extended%">
<img blah blah blah />
</a>
4) Save the entry.

When you next look at the entry, Smarty should change the anchor hyperlink you just created with the actual URL of the extended body.

Which step is failing?
Judebert
---
Website | Wishlist | PayPal
Post Reply