Jump to content

Liam88

Members
  • Posts

    17
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Liam88's Achievements

Jr. Member

Jr. Member (3/6)

1

Reputation

  1. Amazing, thank you. I noticed that when I first did it and changed it to check if count was > etc. Now changed to the above.
  2. Hey, thank you for the reply and direction. I'm going to take a moment to digest the ajax part. In the meantime I did update the input part to the below just after doing this post. It would be good to get your view whether this is a better way. //Default selector to get ALL products $baseSelector = "template='adbank_pages',sort=-created,include=all,limit=12"; $selector = "template='adbank_pages',sort=-created,include=all,limit=12"; // Get the inputs, sanitize and whitelist. Then create an array, then replace _ for | in array for selector filter. Output selector if($input->get->channel){ $channel = $input->get->text('channel'); $input->whitelist('channel', $channel); $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } if($input->get->content){ $content = $input->get->text('content'); $input->whitelist('content', $content); $contArray = explode("_", $content); $cont = $content = str_replace('_', '|', $content); $selector = $selector .= ",ab_content=$cont"; } if($input->get->brand){ $brands = $input->get->text('brand'); $input->whitelist('brand', $brands); $brandArray = explode("_", $brands); $brand = $brands = str_replace('_', '|', $brands); $selector = $selector .= ",ab_brand=$brand"; }
  3. SOLVED: So I added in the whitelisting just after the $input get. if($input->get->channel){ $channel = $input->get->text('channel'); $input->whitelist('channel', $channel);// This is what I was missing. $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } I had the whitelist but needed to add it after the $input->get. I also added $input->get->text('') to help sanitize according to the docs.
  4. Hi, After years of just playing around with Processwire I have asked 3 q's in the same week. It's all about working with forms, parameters etc and so I'm hoping this ordeal is nearly over! I currently have a checkbox filter: <form id="abFilter" method="get" role="form" action="'.$page->url().'"> <div class="list-group"> <h3>Content Type</h3>'; $cont = $fields->get('ab_content'); $contents = $cont->type->getOptions($cont); foreach($contents as $ab_cont){ echo' <div class="list-group-item checkbox"> <input type="checkbox" class="" id="'.$ab_cont->title.'" name="content" value="'.$ab_cont->title.'"'; if (in_array($ab_cont->title, $contArray)){ echo "checked"; } echo'> <label for="'.$ab_cont->title.'">'.$ab_cont->title.'</label> </div>'; } echo' </div>'; //end of filter 1 //start of filter 2 echo' <div class="list-group"> <h3>Channels</h3>'; $chan = $fields->get('ab_channels'); $channel = $chan->type->getOptions($chan); foreach($channel as $ab_chan){ echo' <div class="list-group-item checkbox"> <input type="checkbox" class="" id="'.$ab_chan->title.'" name="channel" value="'.$ab_chan->title.'"'; if (in_array($ab_chan->title, $chanArray)){ echo "checked"; } echo'> <label for="'.$ab_chan->title.'">'.$ab_chan->title.'</label> </div>'; } echo' </div>'; ?> <button id="select">Get Checked Checkboxes</button> </form><!-- end of form --> I also have a piece of script which selects all the checkboxes and then outputs them into readable parameters for the URL which then passes into the $inputs. The reason for the script is to not have duplicate filters like ?ab=1&ab=2 and the script changes it to ab=1_2 which on the input gets exploded into an array. document.querySelector("form").onsubmit=ev=>{ ev.preventDefault(); let o={}; ev.target.querySelectorAll("[name]:checked").forEach(el=>{ (o[el.name]=o[el.name]||[]).push(el.value)}) console.log(location.pathname+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&")); document.location.href = location.pathname+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&"); } Here is $inputs and so on on the page: //Default selector to get ALL products $baseSelector = "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2"; $selector = "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2"; $input->whitelist('channel',explode("_", $channel)); // Use this to append to the $items filter if($channel){ $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } $test = $pages->find($selector); // This is just testing if the $selector choise returns and if not use page filter without filters. if(count($test) > 0){ $items = $pages->find($selector); // $items with the parameter filter // Example - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads" // Example (multi choice) - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads|instagram-ads" // Example (with other filters) - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads,ab_content=video|static" }else{ $items = $pages->find($baseSelector); // Example - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2" } $total = $items->getTotal(); I have stripped out a few of the other filters from the above to try keep it a little more concise (haha). Now I appreciate the post may be long but here we are at the end! The URL I get on page 1 of the filter results would look like: example.com/blog/?channel=facebook-ads_instagram-ads If I click page 2 the url changes to - example.com/blog/page2/?channel= If I then click back to page 1 it changes to - example.com/blog/?channel= So I'm hoping you can see my problem and hoping someone can assist. I need to work out how to keep the parameters in the url but also if I remove that filter for that parameter to remove. This whole process works without pagination but with pagination it has a different behaviour. Thank you in advance
  5. SORTED: So I changed item's to be the first query which featured then works off and now the pagination renders and works.
  6. Just to add that no pagination renders which is odd. I have read many posts that have the render but have URL issues.
  7. Hi, Thank you for the reply I get what you are thinking but I have the $all rule to then push into the two queries and neither $featured or $items reference each other. The pagination is only referencing the $items which are the main posts below. I have put an image below to show the layout which may help. Also, just to say I have removed the $featured query and the block above the breadcrumb and pagination still doesn't work. I have also removed the limit on $featured and use a count instead. Above the breadcrumb is $featured and below is $items
  8. Hoping someone can help. I have pagination all set up with the usual steps: Make sure "markuppagernav" is installed Allow page numbers on the template Create a page query that selects a limited number of items. renderpager the items query. <?php namespace ProcessWire; $all = $page->children("template='blog-post', sort=-published"); $featured = $all->find("limit=4, check_featured!={$page->check_featured}"); $items = $all->find("limit=6"); ?> I have more than 6 posts to ensure it would show. <?php echo $items->renderPager([ 'listMarkup' => '<nav aria-label="navigation"><ul class="pagination">{out}</ul></nav>', 'itemMarkup' => '<li class="page-item {class}">{out}</li>', 'linkMarkup' => '<a class="page-link" href="{url}">{out}</a>', 'currentLinkMarkup' => '<a class="page-link" href="{url}">{out}</a>', 'currentItemClass' => "active" ]); ?> Then the above at the bottom of the page. As mentioned the page numbers are enabled: If I manually add in example.com/blog/page2/ then I just get the same output like example.com/blog/ Where am I going wrong? TIA
  9. Hi, I'm really struggling with this as it's something not in my wheelhouse. I'm creating a blog style page (a grid of cards) which has attributes. I have a snip of javascript which grabs values from checkboxes which are put into a value like the below: ?content=static_video&channel=facebook-ads_instagram-ads document.querySelector("form").onsubmit=ev=>{ ev.preventDefault(); let o={}; ev.target.querySelectorAll("[name]:checked").forEach(el=>{ (o[el.name]=o[el.name]||[]).push(el.value)}) console.log(location.pathname+"?"+ Object.entries(o).map(([v,f])=> v+"="+f.join("_")).join("&") ); document.location.href = location.pathname+"?"+ Object.entries(o).map(([v,f])=> v+"="+f.join("_")).join("&"); } As I'm currently refeshing the page on button click with those values the end result includes the location but can easily remove this. I then use this value in "input->get" to get the values which I then append to a find() rule. See code below: $selector = "template='adbank_pages',sort=published,include=all,status!=hidden"; // Get the channel and content inputs $channel = $input->get->channel; $content = $input->get->content; if($channel){ // Grab the channel string, explode into an array for checkbox checking and then replace _ with | to create or rules in the selector. $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } if($content){ // Grab the content string, explode into an array for checkbox checking and then replace _ with | to create or rules in the selector. $contArray = explode("_", $content); $cont = $content = str_replace('_', '|', $content); $selector = $selector .= ",ab_content=$cont"; } if($input->get){ // If a valid input result $all = $pages->find($selector); } }else{ // If no input show them all $all = $page->children("template='adbank_pages',sort=-published,include=all,status!=hidden"); } $items = $all->find("limit=12"); // Limit the output and use pagination As mentioned above I currently refresh the page to adjust the $selector filter within the $all with a fallback $all if there are no results. I know I need to use AJAX to filter the content without refresh but I am really struggling with the set up. I have read multiple posts including the original by Ryan but still confused. If anyone can direct/help on this it would be appreciated. Thank you
  10. Just an update to this post. it seems I had a missing </div> which caused the error.
  11. Hey, yes all the same setup. it's a wierd one as it never used to flag up with this before.
  12. Hey all, Hoping someone may be able to advise why. I noticed recently that my doctype is not rendering when checking in inspect element. This is only happening on certain sub pages like blog whilst shows on home. I have it within my main doc with all other needed bits, but this just isn't showing. Thank you in advance.
  13. Hi all, Quick question as I haven't found anything from my Googling. I have a blog on the site which utilises pagination. On the standard blog page I have a custom header which has featured posts. Below that I then have recent posts like mosts blogs. Now if i click to page two or three I want the header to disappear and just show a continuation of the standard posts. I'm not sure how to go about this so any direction would be helpful. Thanks
  14. Just to say huge thanks and your version worked. Really enjoying learning this CMS!
×
×
  • Create New...