Advertisement:

Author Topic: [Tutorial] Making website url clickable on item page.  (Read 9575 times)

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
[Tutorial] Making website url clickable on item page.
« on: February 21, 2012, 01:11:55 pm »
Hi, everyone this a simple tutorial to make website url  clickable on item page. I done it for myself and thought that it would be worth to share with everyone here. If someone is interested can follow these easy steps. I assuming that you have some basic experience with Osclass.
It will work on all custom field with any name.

 

1. Now open your theme's 'function.php' file and add this function in the end.

Code: [Select]
function  osc_make_clickable($text) {
    //Convert all urls to links
    $text = preg_replace('#([\s|^])(www)#i', '$1http://$2', $message);
    $pattern = '#((http|https|ftp|telnet|news|gopher|file|wais):\/\/[^\s]+)#i';
    $replacement = '<a href="$1" target="_blank" rel="nofollow">$1</a>';
    $text = preg_replace($pattern, $replacement, $text);

    /* Convert all E-mail matches to appropriate HTML links */
    $pattern = '#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.';
    $pattern .= '[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i';
    $replacement = '<a href="mailto:\\1">\\1</a>';
    $text = preg_replace($pattern, $replacement, $text);
    return $text;}


2. Ok now open your 'item.php' file you can find in your default theme folder at line '96'  and replace below code

Code: [Select]
<strong><?php echo osc_item_meta_name(); ?>:</strong> <?php echo osc_item_meta_value(); ?>
with this one

 
Code: [Select]
<strong><?php echo osc_item_meta_name(); ?>:</strong>
                                               
<?php  $text=osc_item_meta_value();
       echo 
osc_make_clickable($text); 
       
       
?>

       
         

Thats it !
It is working fine with my installation but i can't not bet that it will work for you too . Please backup you files before any modification.



« Last Edit: April 24, 2013, 10:28:02 am by navjottomer »

BuySellAndSwap

  • Sr. Member
  • ****
  • Posts: 389
Re: [Tutorial] Making website url clickable on item page.
« Reply #1 on: February 24, 2012, 01:46:46 am »
I have tried this and it didn't work i created a advert to test it at http://buysellandswap.co.uk/stuff4sale/tickets/your-stuff4sale-here-free_283 and it didn't appear to work i'm using the twitter theme if that helps

Thank you

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Re: [Tutorial] Making website url clickable on item page.
« Reply #2 on: February 24, 2012, 05:54:32 am »
can you post your item.php and functions.php code here

BuySellAndSwap

  • Sr. Member
  • ****
  • Posts: 389
Re: [Tutorial] Making website url clickable on item page.
« Reply #3 on: February 24, 2012, 12:33:41 pm »
I will do it later on today as not on laptop at the min thank you

FREELANCE GROUP LTD

  • Full Member
  • ***
  • Posts: 122
  • FREELANCE GROUP LTD
Re: [Tutorial] Making website url clickable on item page.
« Reply #4 on: February 24, 2012, 01:29:24 pm »
Works just fine. How about for Email?

Luca

  • Hero Member
  • *****
  • Posts: 584
  • CentOs 6.4 - Virtualmin - OSC 3.0 - Custom Theme
Re: [Tutorial] Making website url clickable on item page.
« Reply #5 on: February 24, 2012, 02:08:57 pm »
 :) Thank you, it's working good

BuySellAndSwap

  • Sr. Member
  • ****
  • Posts: 389
Re: [Tutorial] Making website url clickable on item page.
« Reply #6 on: February 25, 2012, 12:42:30 am »
I have attached into a zip file thanks for your help

Luca

  • Hero Member
  • *****
  • Posts: 584
  • CentOs 6.4 - Virtualmin - OSC 3.0 - Custom Theme
Re: [Tutorial] Making website url clickable on item page.
« Reply #7 on: February 25, 2012, 12:47:43 am »
@BuySellAndSwap
The functions.php file to modify is the one in the "themes" folder  ;)

BuySellAndSwap

  • Sr. Member
  • ****
  • Posts: 389
Re: [Tutorial] Making website url clickable on item page.
« Reply #8 on: February 25, 2012, 02:00:21 am »
thats the 1 i did modify... thank you
« Last Edit: February 25, 2012, 02:03:27 am by BuySellAndSwap »

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Re: [Tutorial] Making website url clickable on item page.
« Reply #9 on: February 25, 2012, 06:14:42 am »
You have added my code something like this
Code: [Select]

                                <strong><?php echo osc_item_meta_name() ; ?>:</strong> <?php echo osc_item_meta_value() ; echo osc_make_clickable($text);  ?>
                           

This is the right way
Code: [Select]
<strong><?php echo osc_item_meta_name(); ?>:</strong><?php  $text=osc_item_meta_value();
 echo 
osc_make_clickable($text); ?>

FREELANCE GROUP LTD

  • Full Member
  • ***
  • Posts: 122
  • FREELANCE GROUP LTD
Re: [Tutorial] Making website url clickable on item page.
« Reply #10 on: February 25, 2012, 09:35:51 am »
@buysellsandwap
Check this if it makes sense. your own function.php and item.php

Luca

  • Hero Member
  • *****
  • Posts: 584
  • CentOs 6.4 - Virtualmin - OSC 3.0 - Custom Theme
Re: [Tutorial] Making website url clickable on item page.
« Reply #11 on: February 25, 2012, 11:48:57 pm »
You ought to fill in your url as

Code: [Select]
http://url.tld
note: http://

seton

  • Newbie
  • *
  • Posts: 10
Re: [Tutorial] Making website url clickable on item page.
« Reply #12 on: March 28, 2013, 01:23:59 pm »
 ;)
Nice,
function is excelent, only one think, I replaced  osc_item_description()

$text=osc_item_description(); echo osc_make_clickable($text);

works fine, thank you.
Tony

Legion

  • Hero Member
  • *****
  • Posts: 622
  • I am founder of top20remedies.com buyeradvise.com
Re: [Tutorial] Making website url clickable on item page.
« Reply #13 on: April 24, 2013, 02:22:59 am »
i was looking for it thanks dear

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Re: [Tutorial] Making website url clickable on item page.
« Reply #14 on: April 24, 2013, 10:30:24 am »
update function to include email and better handling of url.