Jump to content

UrlSegment Not Working in Blog Profile


Recommended Posts

Dear all,

Newbie here :)

I've successfully installed the Blog Profile, and trying to modify the recent post widget. I use the $input->urlSegment1 to get the path of URL. But somehow it return nothing.

I've checked the site/config.php and enable the Setup->Templates->URLs->Allow URL Segments? but still the the syntax return nothing.

Is there something I missed here?

Thanks.

Link to comment
Share on other sites

Hi andy,

welcome to Pw :)

I don't understand what you want to do, can you post some example code?

It depends where you are calling $input->urlSegment1.

If this is on a template with urlSegments enabled and returns nothing, then there is no urlSegment available.

To get the url of the actual page viewing, use:

$page->url;

CHeers

  • Like 1
Link to comment
Share on other sites

Hi Wanze,

Thanks for the reply. What I'm trying to do is whenever I read the post with Title A, the widget of Recent Posts will list all the 5 most recent posts excluding the Title A.

In widget recent posts:

$posts = $pages->find("template=post, sort=-date, start=0, limit=$limit");	
$parent = null;
$out = '';

foreach($posts as $item) {
        if($input->urlSegment1 == $item->title) { continue; }
	$out .= "<li><a href='{$item->url}'>{$item->title}</a></li>";
	$parent = $item->parent; 
}

But the $input->urlSegment1 result nothing.

I'm thinking of using global variable, put the current read blog title there so I can read it in the widget. But I dont think it's the most efficient way.

Cheers.

Link to comment
Share on other sites

Ah!

Yeah urlSegment1 returns nothing, because there's no. When reading a post, you are on a page with template 'post'. The last segment in the url is the page's name. If you'd add after that another segment yourself, this would be the first urlSegment then.

But to solve your problem:

foreach ($posts as $item) {
  if ($item->id == $page->id) continue;
}

This will then result in $limit-1 posts, so you could also exclude the current page at db level:

$posts = $pages->find("template=post, sort=-date, start=0, limit=$limit, id!={$page->id}");
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...