Maxxius Posted December 9, 2019 Share Posted December 9, 2019 hi, could you help me on making such a custom field in pages. that custom field would be for inputting the news source url of the original article that I've posted. I wish to simply paste the url in the custom field area and I want the output to be shown under the article on the next line with url truncated so only domain name remain for example. if full url is https://invisioncommunity.com/forums/forum/497-peer-to-peer-technical-support/ then https://invisioncommunity.com/ would be shown, but when you click on the link it would take to the full url https://invisioncommunity.com/forums/forum/497-peer-to-peer-technical-support/ ? For now I made a much simpler version here with a custom display format: <i><a target="_blank" href="{$value}">Source</a></i> value being the URL of source article Link to comment Share on other sites More sharing options...
opentype Posted December 9, 2019 Share Posted December 9, 2019 Which field type is it? URL? Text? Assuming $value really only contains an URL as string, you could do: {{$urlhost=parse_url($value);}} <i><a target="_blank" href="{$value}">{$urlhost['host']}</a></i> Link to comment Share on other sites More sharing options...
Maxxius Posted December 9, 2019 Author Share Posted December 9, 2019 I used URL but your code did not work, so I changed to text and it worked perfectly! Thank you so much! You are the master of pages after all. 😉 By the way would you know any trick to remove the www. part from the {$urlhost['host']} @opentype Link to comment Share on other sites More sharing options...
Maxxius Posted December 10, 2019 Author Share Posted December 10, 2019 @opentype thanks again for providing with the code it works really well, I just wonder if you could answer is there a way to remove www. part from domain? I'm doubleposting hoping that you didn't see my previous reply 🙂 Link to comment Share on other sites More sharing options...
newbie LAC Posted December 10, 2019 Share Posted December 10, 2019 Hello, 18 hours ago, Maxxius said: I used URL but your code did not work, For URL you should to use $formValue $value return the formatted html 18 hours ago, Maxxius said: By the way would you know any trick to remove the www. part from the {{if mb_substr($urlhost['host'], 0, 4) === 'www.'}} {{$urlhost['host'] = mb_substr($urlhost['host'], 4);}} {{endif}} Link to comment Share on other sites More sharing options...
Maxxius Posted December 10, 2019 Author Share Posted December 10, 2019 2 hours ago, newbie LAC said: Hello, For URL you should to use $formValue $value return the formatted html {{if mb_substr($urlhost['host'], 0, 4) === 'www.'}} {{$urlhost['host'] = mb_substr($urlhost['host'], 4);}} {{endif}} Thanks but I'm unsure about $formValue part. My code now looks like this and it works, yay I added your change in " Display Custom Format " {{$urlhost=parse_url($value);}} {{if mb_substr($urlhost['host'], 0, 4) === 'www.'}} {{$urlhost['host'] = mb_substr($urlhost['host'], 4);}} {{endif}} <div class="ipsType_richText"><i>{$label}: <a target="_blank" href="{$value}">{$urlhost['host']}</a></i></div> Link to comment Share on other sites More sharing options...
newbie LAC Posted December 10, 2019 Share Posted December 10, 2019 1 minute ago, Maxxius said: Thanks but I'm unsure about $formValue part. 2 minutes ago, Maxxius said: I added your change in " Display Custom Format " Add my code after {{$urlhost=parse_url($value);}} {{$urlhost=parse_url($value);}} {{if mb_substr($urlhost['host'], 0, 4) === 'www.'}} {{$urlhost['host'] = mb_substr($urlhost['host'], 4);}} {{endif}} Link to comment Share on other sites More sharing options...
Maxxius Posted December 10, 2019 Author Share Posted December 10, 2019 oh right, thanks, I figured that out later where to put it 🙂 thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.