Skip current page in page list
Permalink
Hello,
I've been looking around to see if I could find any way to solve this jigsaw by myself, but I think I'm stuck.
So, here's the setup : I have some pages which detail a work, and on each of them, there is a Page List that fetches and displays two "related work" pages according to a matching meta-tag and displaying them with the newest first. This part works just fine, but then, it gets tricky.
Obviously, I don't want the current page to be shown in its own "related" section. So, in my custom template, I automatically exclude the current page by adding this line :
And there is my problem. As this page list is not fetching all pages but only two of them, even if it skips the current page, it is counted in the loop. So either case, I have a blank because the current page is the newest. So I thought, instead of displaying two pages I'll make it three, but then, if I'm no longer on the two most recent pages I have three related pages and the layout is messed up. And I don't want to start playing with overflow in this div...
Can anyone help me with this ? I'm getting mad...
Attached is the custom template I'm using
and the website is the following :http://www.quentindelattre.ch/_new/jobs/milan...
And the other placeholder "Jobs" pages.
Thank you very much for your help.
I've been looking around to see if I could find any way to solve this jigsaw by myself, but I think I'm stuck.
So, here's the setup : I have some pages which detail a work, and on each of them, there is a Page List that fetches and displays two "related work" pages according to a matching meta-tag and displaying them with the newest first. This part works just fine, but then, it gets tricky.
Obviously, I don't want the current page to be shown in its own "related" section. So, in my custom template, I automatically exclude the current page by adding this line :
if ($page->getCollectionID() == Page::getCurrentPage()->getCollectionID()) { continue; }
And there is my problem. As this page list is not fetching all pages but only two of them, even if it skips the current page, it is counted in the loop. So either case, I have a blank because the current page is the newest. So I thought, instead of displaying two pages I'll make it three, but then, if I'm no longer on the two most recent pages I have three related pages and the layout is messed up. And I don't want to start playing with overflow in this div...
Can anyone help me with this ? I'm getting mad...
Attached is the custom template I'm using
and the website is the following :http://www.quentindelattre.ch/_new/jobs/milan...
And the other placeholder "Jobs" pages.
Thank you very much for your help.
Thank you very much for your reply.
Indeed it looks tough. Yet, I tried something but I lack the syntax and the understanding of some parts of the PageList helper.
Here's what I've been up to :
But it appears that, the attribute Meta Keywords is wrong for this purpose because I get a "AN UNEXPECTED ERROR OCCURRED.
mysql error: [1054: Unknown column 'Array' in 'where clause'] in EXECUTE("select * from FileSets where fsName = Array") " error.
I know I'm not doing anything yet with this Page List, but if it can't filter the pages as I want it to, it is no use to code further is it.
Do you have any idea on how I could filter my page list by Meta Keywords ?
Thanks again.
Indeed it looks tough. Yet, I tried something but I lack the syntax and the understanding of some parts of the PageList helper.
Here's what I've been up to :
Loader::model('page_list'); $pl = new PageList(); $current_page = Page::getCurrentPage(); // current page $current_tag = $current_page->getAttribute('meta_keywords'); //getting current's job category $pl->filterByAttribute('meta_keywords, '%'.$current_tag.'%', 'like'); $pl->setItemsPerPage($num); $pl->sortByPublicDate();
But it appears that, the attribute Meta Keywords is wrong for this purpose because I get a "AN UNEXPECTED ERROR OCCURRED.
mysql error: [1054: Unknown column 'Array' in 'where clause'] in EXECUTE("select * from FileSets where fsName = Array") " error.
I know I'm not doing anything yet with this Page List, but if it can't filter the pages as I want it to, it is no use to code further is it.
Do you have any idea on how I could filter my page list by Meta Keywords ?
Thanks again.
try this maybe.
you may find this helpful too.
http://www.concrete5.org/community/forums/customizing_c5/pagelist_f...
Loader::model('page_list'); $pl = new PageList(); $current_page = Page::getCurrentPage(); // current page $current_tag = $current_page->getAttribute('meta_keywords'); //getting current's job category $pl->filterByAttribute('meta_keywords, $current_tag); $pl->setItemsPerPage($num); $pl->sortByPublicDate();
you may find this helpful too.
http://www.concrete5.org/community/forums/customizing_c5/pagelist_f...
Thank you very much for your help, I kept on browsing and found something I thought might do the trick, but it just got weirder.
Here's what I've come up with courtesy of Nostroom's help :
I really think it could do the trick, but anytime I try to apply this custom template, I don't what happens but the block just ignores that and applies the standard concrete template...
Do you have any idea of what's happening ? Is there a mistake in my template making it impossible to apply ?
Thanks for your help
///////////////////////////////////////////////////
EDIT :
It's taking the template in account, I just need to debug a small bug with outputThumbnail function, and I think it is going to be fine.
Multiple edits on this one, I kept debugging, I can now display the thumbnails, but it is the filtering option which causes me trouble.
Ignore the bit of code a the top of this post, here are my corrections :
My problem is that I don't know how to filter the pages being listed to match the current attribute "job_tag". This attribute is a type select and only allows one value to be checked at a time. moreover, I dont know where to indicate that if the current page is being listed it has to ignore it and get one more page...
I'm desperate
///////////////////////////////////////////////////
Here's what I've come up with courtesy of Nostroom's help :
<div class="related_thumbnails"> <div class="thumbs_wrapper"> <?php defined('C5_EXECUTE') or die("Access Denied."); $imgHelper = Loader::Helper('image'); Loader::model('page_list'); Loader::model('file_set'); Loader::model('file_list'); $pl = new PageList(); $ak = 'job_cat'; $av = $_GET['cat']; $pl->filterByAttribute($ak, '%'.$av.'%', 'like'); $pl->setItemsPerPage($num); // get the numbers of items/page from edit dialog switch($orderBy) { // get sort order from edit dialog case 'display_asc': $pl->sortByDisplayOrder(); break;
Viewing 15 lines of 37 lines. View entire code block.
I really think it could do the trick, but anytime I try to apply this custom template, I don't what happens but the block just ignores that and applies the standard concrete template...
Do you have any idea of what's happening ? Is there a mistake in my template making it impossible to apply ?
Thanks for your help
///////////////////////////////////////////////////
EDIT :
It's taking the template in account, I just need to debug a small bug with outputThumbnail function, and I think it is going to be fine.
Multiple edits on this one, I kept debugging, I can now display the thumbnails, but it is the filtering option which causes me trouble.
Ignore the bit of code a the top of this post, here are my corrections :
<div class="related_thumbnails"> <div class="thumbs_wrapper"> <?php defined('C5_EXECUTE') or die("Access Denied."); $imgHelper = Loader::Helper('image'); $nh = Loader::Helper('navigation'); $textHelper = Loader::Helper('text'); Loader::model('page_list'); Loader::model('file_set'); Loader::model('file_list'); $pl = new PageList(); $ak = 'job_cat'; $av = $_GET['job_cat']; $pl->filterByAttribute($ak, '%'.$av.'%', 'like'); $pl->setItemsPerPage($num); // get the numbers of items/page from edit dialog
Viewing 15 lines of 41 lines. View entire code block.
My problem is that I don't know how to filter the pages being listed to match the current attribute "job_tag". This attribute is a type select and only allows one value to be checked at a time. moreover, I dont know where to indicate that if the current page is being listed it has to ignore it and get one more page...
I'm desperate
///////////////////////////////////////////////////
Working pays off.
I've managed almost avery part of what I want to achieve. The only bit left, is the part where I want it to skip the current page if it has to be displayed but still display 2 thumbnails...
I'll submit my template once it is done.
I've managed almost avery part of what I want to achieve. The only bit left, is the part where I want it to skip the current page if it has to be displayed but still display 2 thumbnails...
I'll submit my template once it is done.
I finally got it working well !!!
Took me some time but it works !
Here's my code :
Thank you very much for your help !
Took me some time but it works !
Here's my code :
<div class="related_thumbnails"> <div class="thumbs_wrapper"> <?php defined('C5_EXECUTE') or die("Access Denied."); $imgHelper = Loader::Helper('image'); $textHelper = Loader::Helper('text'); Loader::model('page_list'); Loader::model('file_set'); Loader::model('file_list'); $pl = new PageList(); $ak = 'job_cat'; $av = $page->getAttribute('job_cat'); $pl->filterByAttribute($ak, '%'.$av.'%', 'like'); $pl->setItemsPerPage($num); // get the numbers of items/page from edit dialog switch($orderBy) { // get sort order from edit dialog
Viewing 15 lines of 55 lines. View entire code block.
Thank you very much for your help !
looks likehttp://www.concrete5.org/documentation/developers/pages/searching-a...
has a section on doing something like this
Advanced users:
Passes a fliter directly to the "WHERE" clause. The value of $column must be a valid database column that's referenced in the PageList query. Setting the value of $column to false will allow you to pass complex SQL into the $value field ex:
where 'age' would be the handle of a numeric page attribute
so you could try something like
though im not sure if that will work since i haven't really had to use it.
Couple more options.
or
or really try filtering by any/all of those options on the page list page.
one that I know would work would also take the most time- set and unset a custom attribute
good luck!