andy.aristiyanto Posted May 20, 2013 Share Posted May 20, 2013 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 More sharing options...
Wanze Posted May 20, 2013 Share Posted May 20, 2013 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 1 Link to comment Share on other sites More sharing options...
andy.aristiyanto Posted May 21, 2013 Author Share Posted May 21, 2013 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 More sharing options...
Wanze Posted May 22, 2013 Share Posted May 22, 2013 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}"); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now