Recent Topics

1 May 04, 2005 19:05    

Hi.

I'm trying to store the permalink of an Item into a varible:
-----------------------------------
if (isset($MainList))
while ($Item = $MainList->get_item())
{
$permalink = $Item->permalink;
$title = $Item->title;
print "<li>$permalink - $title\n";
}
------------------------------------

But only 'title' is showed, but not 'permalink'

Any suggestion? Thx

2 May 06, 2005 16:00

Must I modify _class_item.php ???

3 May 07, 2005 01:05

guarriman,

I haven't answered, because I don't know. I can only share your pain, as I've run into similar problems when assigning variables.

Why is it that one can post the title using

$Item->title();

and assign it to a variable using

$whatever=$Item->title;

but the same doesn't work for $Item->permalink() and $Item->permalink ?

It's beyond me.

Maybe you can construct the thing from parts - $baseurl, which will get the http://sitename.com/dir/to/blogs if you can find something that holds the actual entry name? (just an off-the-top-of-my-head suggestion).

I'd like to know the answer to this question too.

-Scott

4 May 07, 2005 09:01

$permLink= $baseurl.'/?blog='.$blog.'&amp;p='.$Item->ID.'&amp;more=1&amp;c=1&amp;tb=1&amp;ph=1';

¥

5 Feb 14, 2006 03:44

I realize that the reply is a wee bit late, but just in case someone has a similar problem to this like I did...

Guarriman, stk, it looks very much like the reason you can store the value of the title in a variable with something like

$variable = $Item->title;


and you can't store the value of the permalink with a similar bit of code

$variable = $Item->permalink;


seems to be that, though both statements are referencing a variable in the Item class (would that be what you'd call it?), only one of them, $title, is actually declared in the class base while $permalink seems to be unique to the gen_permalink() function. That being said, if you want to store the value of a post's permalink in a variable, just store the value returned by the gen_permalink() function (which happens to be its $permalink variable), like so:

$variable = $Item->gen_permalink();


It seems that you would have to use gen_permalink() to do so as opposed to to just permalink() even though permalink() calls gen_permalink(), because gen_permalink() is the only one of the two that actually returns a value; permalink() merely outputs the value returned by gen_permalink() with the echo command.

Were there a declaration such as

var $permalink = '';

at the beginning of the Item class definition in _class_item.php, then you would have no trouble whatsoever with the expression

$variable = $Item->permalink;

to store its value in a variable, however, there isn't, so I suppose we'll all just have to make due with the value(s) returned by the gen_permalink() function.

On a side note, if you're a complete newbie like I am, and the problem that led you to this post was the same as mine - you were just tring to make a hyperlink with the value returned from $Item->permalink() and concatenate a string to the end of it like '#top' for an internal anchor reference - then you'll have to create two separate expressions to let permalink() echo its value and then echo your additional string instead of using the concatenation operator to try and just stick them both together because the browser will only have what permalink() echoes output to it and php will just ignore your second string and your pathetic dot operator:

<a href="<?php $Item->permalink(); echo '#top' ?>">Link text</a>


and not

<a href="<?php $Item->permalink().'#top' ?>">Link text</a>

I felt a little dumb after having to learn all of the above before I realized that was the only mistake I was making. :roll:


Form is loading...