Page 1 of 1
Tag that produces link to a blog article?
Posted: Tue May 09, 2017 10:50 am
by postiffm
Is there is a tag like {cms_selflink..." but that works with cgblog articles?" I'd like something like {cgbloglink page="blah" text="blah blah"} and it would produce a link like this:
Re: Tag that produces link to a blog article?
Posted: Tue May 09, 2017 11:18 am
by rotezecke
I think the idea is to create a simple detailtemplate and call it with the articleid switch. a few years back i ran into a problem where i wanted to control the link text, hence i made this UDT I named BlogLink which I call like this
{BlogLink id=23 text='optional alternative text'}
. it may not follow best practice but hasnt failed yet
Code: Select all
if (isset($params['id'])) {
$blog_ID = trim($params['id']);
$blog_text = trim($params['text']);
$db = cmsms()->GetDb();
$query1 = "SELECT url,cgblog_title,status FROM ".cms_db_prefix()."module_cgblog WHERE cgblog_id = '$blog_ID'";
$result1 = $db->Execute($query1);
while ($result1 && $row = $result1->FetchRow()) {
$url = $row['url'];
$title = $row['cgblog_title'];
$status = $row['status'];
}
//load config data
$config = cmsms()->GetConfig();
//build the link how you like
$url = $config['root_url'].'/my-cgblog-prefix/'.$blog_ID.'/'.$url.$config['page_extension'];
if($blog_text =='') {
$blog_text = $title;
}
//if article is active ->publish link, else text only.
if($status =='published') { echo "<a href='$url'>$blog_text</a>"; }
else { echo $blog_text; }
}
Re: Tag that produces link to a blog article?
Posted: Tue May 09, 2017 11:37 am
by calguy1000
{cms_action_url module=CGBlog action=detail articleid=5}
will generate a URL to the specified blog article.
Re: Tag that produces link to a blog article?
Posted: Tue May 09, 2017 11:41 am
by Rolf
calguy1000 wrote:{cms_action_url module=CGBlog action=detail articleid=5}
will generate a URL to the specified blog article.
And you can simplify it for the editors with:
https://www.cmscanbesimple.org/blog/cal ... from-a-udt