Linking author of the post to its blog

Linking author of the post to its blog

Postby easyexpat on Wed Apr 23, 2008 9:14 am

Hi,
I have a blog that host posts from several users.
At the top of the post, I display the username of the author.
I would like to link the name with the personal blog of the user (also on Lifetype). How do I do that?

In my template I assume that I have to change post.template
Code: Select all
{assign var="postOwner" value=$post->getUserInfo()}
<a href="????????WHAT-DO-I-PUT-HERE??????">{$postOwner->getUsername()}</a>

Thanks in advance for the help
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Linking author of the post to its blog

Postby jondaley on Wed Apr 23, 2008 10:45 am

You can use $postOwner->getOwnBlogs(), but that will return an array, since a person might own more than one blog. If you know there is one and only one (not zero) blogs that they own, you could simply use $postOwner->getOwnBlogs()[0], otherwise, you should use a foreach loop to go through the array that is returned and decide which blog to post (or nothing if the user happens to not own their own blog).
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Linking author of the post to its blog

Postby easyexpat on Wed Apr 23, 2008 11:19 am

Thanks jondaley,
However when I am using
Code: Select all
{assign var="postOwner" value=$post->getUserInfo()}
<a href="{$postOwner->getOwnBlogs()[0]}">{$postOwner->getUsername()}</a>

I get this error:
Exception message: Smarty error: [in ./templates/blog_1/easyexpat_xiti/post.template line 5]: syntax error: unrecognized tag: $postOwner->getOwnBlogs()[0] (Smarty_Compiler.class.php, line 446)
Error code: 256
-- Backtrace --
/home/blogexpat/class/template/smarty/Smarty.class.php(1095): trigger_error
/home/blogexpat/class/template/smarty/Smarty.class.php(1817): smarty_compiler.trigger_error
/home/blogexpat/class/template/smarty/Smarty_Compiler.class.php(2218): smarty_compiler._trigger_fatal_error

:?:
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Linking author of the post to its blog

Postby jondaley on Thu Apr 24, 2008 12:37 pm

Hrm, that was just a guess. Try assigning the value of getOwnBlogs to a variable, and then do $var[0] Maybe smarty doesn't support that syntax, and you'll need another foreach loop to get the values.

{foreach $postOwner->getOwnBlogs() as $ownedBlogs}
{assign var="generator" value="$ownedBlogs->getBlogRequestGenerator()"}
<a href="{$generator->blogLink()}">my blog</a>
{/foreach}

I forget if you need to do an assign for the postOwner->getOwnBlogs to another variable before it will let you put it in the foreach statement.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Linking author of the post to its blog

Postby easyexpat on Thu Apr 24, 2008 1:15 pm

Hi Jondaley,

I tried
Code: Select all
{assign var="getOwnBlogs" value=$postOwner->getOwnBlogs()}
{foreach $getOwnBlogs as $ownedBlogs}
{assign var="generator" value="$ownedBlogs->getBlogRequestGenerator()"}
<a href="{$generator->blogLink()}">{$postOwner->getUsername()}</a>


And also
Code: Select all
{assign var="var" value=$postOwner->getOwnBlogs()}
<a href="{$var[0]}">{$postOwner->getUsername()}</a>


And... no success... :(

Any other idea? Not to familiar with smarty... :?
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Linking author of the post to its blog

Postby jondaley on Thu Apr 24, 2008 5:12 pm

Sorry, I am switching languages multiple times a day (C, Bash, tcsh, and PHP) so I mixed up the syntax.

The smarty manual is pretty helpful if you know what functions you are looking for. Your first attempt is pretty close.

http://www.smarty.net/manual/en/languag ... oreach.php
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Linking author of the post to its blog

Postby easyexpat on Fri Apr 25, 2008 9:38 am

Hi Jondaley,

I had a look at the smarty guidelines... indead the foreach script needed to be modified and the code below does not generate error anymore... BUT it does not show anything :cry: Even for the owner of the blog, ot does not show the blog (there is obviously something in the array, it should display).
Please help... :-(

Code: Select all
{assign var="$posterBlog" value=$postOwner->getOwnBlogs()}
{foreach from=$posterBlog item=myBlog}
   {assign var="generator" value="$myBlog->getBlogRequestGenerator()"}
   <a href="{$generator->blogLink()}"><b>{$postOwner->getUsername()}</b></a>
{/foreach}
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Linking author of the post to its blog

Postby jondaley on Fri Apr 25, 2008 12:27 pm

Can you post a URL that has your code in it? It looks alright to me.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Linking author of the post to its blog

Postby easyexpat on Fri Apr 25, 2008 12:56 pm

jondaley wrote:Can you post a URL that has your code in it? It looks alright to me.


For example in this page:
http://easyexpat.blogexpat.com/blog/exp ... -of-expats

At the top of the article there is the name:
easyexpat | 10 April, 2008 17:45

Currently, as the other method does not work, I put the following:
Code: Select all
<a href=""><b>{$postOwner->getUsername()}</b></a>
{assign var="$posterBlog" value=$postOwner->getOwnBlogs()}
{foreach from=$posterBlog item=myBlog}
   {assign var="generator" value="$myBlog->getBlogRequestGenerator()"}
   <a href="{$generator->blogLink()}"><b>{$postOwner->getUsername()}</b></a>
{/foreach}


But only the first <a href... is showing, the second one in the foreach loop does not show. However there is a blog for this owner: http://easyexpat.blogexpat.com/

It should show:
easyexpateasyexpat | 10 April, 2008 17:45
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Linking author of the post to its blog

Postby jondaley on Mon Apr 28, 2008 7:52 am

Code: Select all
{assign var="posterBlog" value=$postOwner->getOwnBlogs()}


Ah, I didn't see this typo before. No $. in the var attribute of an assign statement.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Linking author of the post to its blog

Postby easyexpat on Mon Apr 28, 2008 9:32 am

Indeed, a typo...

But I still needed to change the code a bit and hoooora I managed to have it working like this:
Code: Select all
{assign var="posterBlog" value=$postOwner->getOwnBlogs()}
{foreach from=$posterBlog item=blog}
   {assign var="url" value=$blog->getBlogRequestGenerator()}
      <a href="{$url->blogLink()}"><b>{$postOwner->getUsername()|strip_tags}</b></a>
{/foreach}


(removing the " " for value= ...aargh, smarty is sooo sensitive!)

Thanks for your help :-)
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Linking author of the post to its blog

Postby jondaley on Tue Apr 29, 2008 7:28 am

I'd avoid using the variable name "url" since LT sets that and templates generally expect that to be set to something else. When making up names for my templates, I try making them pretty unique, so there won't ever be any collisions.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Linking author of the post to its blog

Postby easyexpat on Tue Apr 29, 2008 7:41 am

jondaley wrote:I'd avoid using the variable name "url" since LT sets that and templates generally expect that to be set to something else. When making up names for my templates, I try making them pretty unique, so there won't ever be any collisions.

You're right... I will change it to blogGenerator
Thx
:)
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Re: Linking author of the post to its blog

Postby Logan on Tue Jun 03, 2008 1:24 pm

Hello, I Searching similar Solution, but I need to LINK in COMMENT Post , the Link to BLOG USER who Post Comment, where appear his name and Photo.-

Have an Idea, what CODE I need to Insert in "comments.template "??

THE CODE of comments.template:::

<ol class="commentlist"> {assign var="counter" value=1} {foreach from=$comments item=comment} {assign var=commentText value=$comment->getText()} {assign var=commentDate value=$comment->getDateObject()} {assign var=blogOwner value=$blog->getOwnerInfo()} {if $counter%2!=0} <li class="alt" id="comment-{$comment->getId()}"> {else} <li class="" id="comment-{$comment->getId()}"> {/if} {if $comment->IsPosterAuthenticated()} {assign var=poster value=$comment->getUser()} {if $poster->hasPicture()} {assign var=posterimg value=$poster->getPicture()} {assign var=commenter value=$comment->getUser()} <img src="{$posterimg->getPreviewLink()}" alt="{$commenter->getUserName()}" style="width:40px;height:40px" /> {/if} {/if} <cite>{$locale->tr("posted_by")} {$comment->getUsername()}</cite>: <br /> <small class="commentmetadata"><a href="#comment-{$comment->getId()}" title="">{$locale->formatDate($commentDate, "%d %B %Y, %H:%M")}</a></small> {$commentText} </li> {assign var="counter" value="`$counter+1`"} {/foreach} </ol> <div class="navigation">{pager style="links"}</div>
Logan
 
Posts: 8
Joined: Sun May 11, 2008 8:23 pm
LifeType Version: 1.28

Re: Linking author of the post to its blog

Postby easyexpat on Tue Jun 03, 2008 1:39 pm

Logan wrote:Hello, I Searching similar Solution, but I need to LINK in COMMENT Post , the Link to BLOG USER who Post Comment, where appear his name and Photo.-

I assume that you need to apply the same piece of code within:
Code: Select all
{if $comment->IsPosterAuthenticated()} {assign var=poster value=$comment->getUser()} {if $poster->hasPicture()} {assign var=posterimg value=$poster->getPicture()} {assign var=commenter value=$comment->getUser()} <img src="{$posterimg->getPreviewLink()}" alt="{$commenter->getUserName()}" style="width:40px;height:40px" /> {/if} {/if}


However I don't understand really: does that mean that the only people able to post comments will be other users of lifetype with a blog??? You then miss the porpose of commenting blogs...
easyexpat
 
Posts: 136
Joined: Mon Jun 13, 2005 4:39 pm

Next

Return to Templates

cron