Jump to content

Liam88

Members
  • Posts

    52
  • Joined

  • Last visited

Everything posted by Liam88

  1. Hello all, Ended my hosting and want to move my site back to local. I have downloaded my DB and relevant folders. I'm just using Xampp for this which is up and running correctly. Tested with a fresh install of PW. Done the following process: installed fresh PW with created DB Replaced folder items with existing website dropped installation DB tables Imported website DB Adjusted config DB credentials to match. Any direction on what these are? Unfortunately, little knowledge on these elements so direction is much appreciated. TIA
  2. Hello, I have a separate sort dropdown and filter section. This is very similar to the processwire demo - https://demo.processwire.com/search/?sort=parent.name I also have the same "issue" if you would call it that where i can sort or I can filter, but I can not do both. This is because the url changes. So a sort URL may look like: website.com/subpage/?sort=random and a filter like: website.com/subpage/?placement=x&channel=y_z I'm looking to be able to sort and filter. So if I change the sort, it won't remove the current filter and vice versa. I have the sort dropdown running off one bit of JS and the filter on another with examples of both below: This is sort JS $(document).ready(function() { $(".sort-select").on("change", function() { document.location.href = location.pathname+"?sort="+$(this).val(); //console.log(location.pathname+"?sort="+$(this).val()) //console.log(location.search) }); }); This is filter JS document.querySelector("form").onsubmit=ev=>{ ev.preventDefault(); let o={}; let noPage = window.location.pathname.split("/").slice(0,-2).join("/") + "/"; ev.target.querySelectorAll("[name]:checked").forEach(el=>{ (o[el.name]=o[el.name]||[]).push(el.value)}) if(noPage.length > 1){ document.location.href = noPage+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&"); }else{ document.location.href = location.pathname+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&"); } } This is my input build within the func.php doc: $selector = ''; // Get the inputs, sanitize and whitelist. Then create an array, then replace _ for | in array for selector filter. Output selector if($input->get->sort){ $sorted = $input->get->text('sort'); $input->whitelist('sort', $sorted); //$selector = $selector .= ",sort=$sorted"; } 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"; } if($input->get->style){ $styles = $input->get->text('style'); $input->whitelist('style', $styles); $styleArray = explode("_", $styles); $style = $styles = str_replace('_', '|', $styles); $selector = $selector .= ",ab_creative_style=$style"; } if($input->get->ugc){ $ugcs = $input->get->text('ugc'); $input->whitelist('ugc', $ugcs); $ugcArray = explode("_", $ugcs); $ugc = $ugcs = str_replace('_', '|', $ugcs); $selector = $selector .= ",ab_influencer=$ugc"; } if($input->get->place){ $placement = $input->get->text('place'); $input->whitelist('place', $placement); $placeArray = explode("_", $placement); $place = $placement = str_replace('_', '|', $placement); $selector = $selector .= ",ab_placement=$place"; } if($page->template == 'adbank_brand_page'){ $brand = $page->title; $selector = $selector .= ",adbank_brands=$brand"; } $selector = "template='adbank_pages',limit=12,sort={$sorted} " . trim($selector, ", "); Any direction on how to combine these would be really appreciate. I know AJAX may be the best route overall but I don't know how to action that and for time sake trying to get these to both work with page refresh feels more accessible... TIA
  3. 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.
  4. 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"; }
  5. 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.
  6. 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
  7. SORTED: So I changed item's to be the first query which featured then works off and now the pagination renders and works.
  8. Just to add that no pagination renders which is odd. I have read many posts that have the render but have URL issues.
  9. 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
  10. 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
  11. 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
  12. Just an update to this post. it seems I had a missing </div> which caused the error.
  13. Hey, yes all the same setup. it's a wierd one as it never used to flag up with this before.
  14. 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.
  15. 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
  16. Just to say huge thanks and your version worked. Really enjoying learning this CMS!
  17. Thanks for the reply. Within the page template I have a ref_6 which selects the tag for that page. Then the aim is to have tag content which can then be pulled into sections and place the associated posts beneath. I did try find yesterday but I'll give that route another go today. Thanks
  18. Hi All, New user over at Processwire and have been rebuilding my site based on this CMS. I have been able to find so many answers through Google but I'm a little stuck on this one. I have my services page -> services categories -> category children. An example of those would be - domain -> services -> ppc -> management I also have a set of tags which have different names - services-tag -> grow-your-traffic Under these tags I would have multiple links to pages such as ppc, seo, social media and so on. A second example would be - services-tag -> convert-your-traffic Under here i would have multiple links to pages such as CRO Now the set of tags are not visible on-site as they are only created to give overview content to the main services categories. Using the categories and the tags I am looking to produce a layout such as (i have also attached an image as an example: Tag_1 headline Pull all services categories linking to Tag_1 Tag_1 snippet Tag_2 headline Pull all services categories linking to Tag_2 Tag_2 snippet So far I have this snippet which is pulling in the tag content but unable to get the posts to show under each of the tags. If i change the if and statement to "tags" instead of "tag" then all posts show under all tags. Where as i want it to show only the posts which are linked to that tag. <?php namespace ProcessWire; $tags = $pages->get("/categories-services/")->children(); // Gets the tags $posts = $pages->get("/services/")->children(); // Gets the services categories $link = $tags->ref_6; // Gets the tags and services categories link - under here you have pages_id (services cat id) and data (tags id) // Tag header and summary foreach($tags as $tag) { // This breaks down the tags into sections echo '<section id="services"> <div class="container"> <div class="row"> <h2 class="heading-1"><span>'. $tag->headline.'</span></h2> <p class="mb-5">'. $tag->summary.'</p> </div> <div class="row justify-content-around services">'; // Main services categories that link to the above tags if ($posts->id === $link->pages_id && $tag->id === $link->data){ foreach($posts as $service){ // This pulls in the services categories under the tag header. echo '<div class="card flex-card" id=""> <div class="card-img"> <a href="/'. $service->name.'" title="'. $service->name .'"> <img class="card-img-top" src="../assets/files/'. $service->id.'/'. $service->img_1.'" alt="'. $service->img_1.'" title="'. $service->img_1.'"></a> </div> <div class="card-body"> <h3 class="card-title">'. $service->headline.'</h3> <p class="card-text">'. $service->summary .'</p> <div class="card-action"> <a href="" title="'. $service->name .'" role="link" class="link">View service<span></span></a> </div> </div> </div> '; } } // Grey snippet text echo '</div> </div> </section> <div class="snip-2 light-grey"> <div class="container"> <div class="row text-center">'. $tag->get('grey') .'</div> </div> </div>'; } ?> I appreciate this is a long post but i'm trying to be clear as I appreciate everyone's time. Any insight into where I am going wrong is greatly appreciated. Liam
×
×
  • Create New...