Jump to content

Articles custom field for news source URL (truncated)


Maxxius

Recommended Posts

Posted

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

 

Posted

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>

 

Posted

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

Posted

@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 🙂

Posted

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}}

 

Posted
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>

 

Posted
1 minute ago, Maxxius said:

Thanks but I'm unsure about $formValue part.

format.thumb.jpg.3225c2edfa8535fd1c45dd90a6495457.jpg

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}}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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