$this->author() on article

Feed 19 posts, 4 voices

Avatar
14 posts

hi, i’ve recently set up Frog on my website, and made a new layout to it… which is working fine and all, but i want to have the article display the author’s username on the page.
i know how to do this (i think) by using:

$this->author();

i have achieved this on the parent page, “articles”, where it searches for the 5 latest news articles and lists them with their author, date created, and have wrote the layout to change if it does not have a side bar, as the article pages are the only ones without on my site.
i can get it to display other things, like the link, with $this->link(). but if i use $this->author(), nothing happens… what am i doing wrong?

 
Avatar
257 posts

Seems strange. I can get it to work as in this example:

<?php $last_articles = $this->children(array('limit'=>0, 'order'=>'page.created_on DESC')); ?>
<?php foreach ($last_articles as $article): ?>
<div id="blog_left">
<h3><?php echo $article->link($article->title); ?></h3>
<p>posted by <?php echo $article->author(); ?> on <?php echo $article->date(); ?></p>
</div>
<div id="blog_right">
<?php echo $article->content('introduction'); ?>
<a href="<?php echo BASE_URL ?>blog/<?php echo $article->slug(); ?>">Read more...</a>

</div>

<div id="clear"></div>
<?php endforeach; ?>

See this specific example at the hiddeninplainview site

 
Avatar
14 posts

so using

<?php $last_articles = $this->children(array('limit'=>0, 'order'=>'page.created_on DESC')); ?>

and a foreach loop makes $article refer to the current article?

 
Avatar
257 posts

Yeah seems to work ok in that form…

 
Avatar
14 posts

well, now my code says


<?php if (!$this->hasContent('sidebar')): ?>
<?php $last_articles = $this->children(array('limit'=>0, 'order'=>'page.created_on DESC')); ?>
<?php foreach ($last_articles as $article): ?>
<div class="full box">
<?php echo $article->link($article->title); ?>
posted by <?php echo $article->author(); ?> on <?php echo $article->date(); ?>
</div>
<?php endforeach; ?>
<?php endif; ?>

but it doesn’t echo anything at all!
it’s not the <?php if (!$this->hasContent(‘sidebar’)): ?> , because it’ll still do what i put before or after the foreach loop.
i’m guessing i got something wrong?

 
Avatar
1493 posts

So if sidebar is otherwise empty, then you want this recent article listing?

Does Frog know where to find the children for your $last_articles variable? You could try this to replace the first three lines of your code:

<?php if (!$this->hasContent('sidebar')): ?>
<?php $last_articles = $this->find('/articles/'); ?>
<?php foreach ($last_articles->children(array('limit' => 10, 'order' => 'page.created_on DESC')) as $article): ?>

And cross your fingers. :) Might work … might not… One lives in hope.

Update: I just noticed you have 'limit'=>0,, whereas I have 'limit' => 10,

 
Avatar
14 posts

er… what i was tryng to achieve was:
if the sidebar is empty (which only applies to the news articles themselves, all other pages have a sidebar) then show the article’s information, such as date published, author…

 
Avatar
1493 posts

then show the article’s information, such as date published, author…

Ah, o.k. So not a list of recent articles, but just the “meta” for the current article? I think all you need for that, is to put this in the sidebar DIV of your layout:

<?php if (!$this->hasContent('sidebar')): ?>
<div class="full box">
<?php echo $this->link(); ?> posted by
<?php echo $this->author(); ?> on <?php echo $this->date(); ?>
</div>
<?php endif; ?>

Does that do it??

 
Avatar
14 posts

that works, except it doesnt show the author for some reason…

 
Avatar
316 posts

What version are you using Cpt-Jim?

 
Avatar
1493 posts

Huh? (You edited that, didn’t you! Confess! :)

Just in case — in the backend, when you’re editing a page you’ll get a line underneath the editing area something like:

Last updated by Administrator on Fri, 26 Sep 2008

Could you check and ensure that you’re getting a name there?

 
Avatar
316 posts

I had the same problem when I was using 0.9.3, but it was fixed in 0.9.4 and I had to revert back to $this->author(). If you are using 0.9.3, I think I can find my solution in one of my old backup files.

EDIT: I found the backup. When I was using 0.9.3, I was using:

<?php echo $this->created_by_name; ?>

to display the author’s name. In 0.9.4, though, that line no longer works and I had to revert back to:

<?php echo $this->author(); ?>

Hope that works.

 
Avatar
14 posts

@david – yeah, sorry… wrote it and then changed my mind… my bad. but i am getting that line, it says

Last updated by Cpt-Jim on Sat, 4 Oct 2008

(as it should)
however, mtylerb may have the answer, it seems. i am on 0.9.3 , so if you’ve been having the same problem, i guess that’ll be it! buut… is it worth me upgrading? how easy is it to do so?

 
Avatar
316 posts

I’d upgrade. Just upload the new files to your server, then disable and re-enable your comment plugin. You’ll also need to run an INSERT on your database to insert the following values into your frog.settings table:

INSERT INTO setting (name, value) VALUES ('default_tab', '');
INSERT INTO setting (name, value) VALUES ('allow_html_title', 'off');

That’s it, you’ll be up to date with 0.9.4. I’m very happy with the changes from 0.9.3. I highly recommend the update.

 
Avatar
1493 posts

Well, there’s a poser and no mistake.

I never noticed this before, I suppose since things like $article->author(); work when dealing with arrays. But the simple $this->author(); and $this->updator(); do not work in 0.9.3!

Way back a number of versions ago, Philippe used to include a list of what things you could call where. I don’t know if that would have signalled this issue, or not!

Meanwhile mtylerb’s right – 0.9.4 is the way to go! (Be sure to read the “updating.txt” file in the Frog root dir, too, in addition to mtylerb’s instructions :)

 
Avatar
14 posts

thanks for your help, upgrading seems easy, so i’ll be on my way :)