TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,230
  • Total Topics: 21,353
  • Online today: 446
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 104
  • Total: 104

Display frontpage article URL?

Started by fallen, September 10, 2013, 11:33:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fallen

Hi!
I'm trying to customize my frontpage article template.
All I want to do is just get the URL of an article/thread without the HTML code.
For example,  {article_title}  returns
<a href="ARTICLE URL">ARTICLE TITLE</a>
I only need the article URL without the html code, because I have to use it in a plugin, but I can't find a way to use it.
Any help?
Thank you

IchBin

Not sure I understand how you are using this. Are you only wanting the URL while visiting the article page? Do you need to grab this URL and do something with it in PHP?

Sounds like you are trying to use custom code or something outside of the article?

If you are trying to only do this in the article output itself, you will have to write a custom function to do what you want. In the Themes/default/TPsubs.template.php file you will find a bunch of similarly named functions like article_title() or article_views(). You only need to create an function named article_url() and return the data you need. Then in your custom template code you can put {article_url}. It will automatically call your function and return the URL assuming you did the fuction right. :) Hope that makes sense.

Let me know exactly what you're trying to do.

fallen

Yes I think you got my point.
I'm trying to use the facebook comments plugin for every post on the frontpage, which uses this code:
<div class="fb-comments" data-href="ARTICLE URL" data-width="470"></div>
So I have to get the simple article URL in order to put it in "data-href".

Thanks for the hint then, I will try to make that function and will let you know if I get it working. I'll post the code for whoever may need it in the future if it works.

fallen

Thank you, it was so easy :)

This is the code for whoever may need it
function article_url($render = true)
{
   global $scripturl, $context;
   
   if(in_array('title',$context['TPortal']['article']['visual_options']))
   {
      if(isset($context['TPortal']['article']['boardnews']))
$code = '' . $scripturl . '?topic=' . $context['TPortal']['article']['id'] . '';
      else
$code = '' . $scripturl . '?page=' . (!empty($context['TPortal']['article']['shortname']) ? $context['TPortal']['article']['shortname'] : $context['TPortal']['article']['id']) . '';
}
   else
      $code='';

   if($render)
      echo $code;
   else
      return $code;
}


p.s. did you look at this bug?

IchBin

I had forgot about that. Thanks for the reminder. I'll reply to that article with my thoughts.

This website is proudly hosted on Crocweb Cloud Website Hosting.