-
Posts
63 -
Joined
-
Last visited
Everything posted by Martinus
-
UrlSegments with Pagination is throwing blank page [SOLVED]
Martinus replied to Martinus's topic in API & Templates
My sorting is in the header. <form method="get"> <!-- // sort options --> <div class="dropdown-center me-2"> <button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Sort <?php echo $page->title;?> </button> <ul class="dropdown-menu small"> <li><a class="dropdown-item" href="name-asc">Name (A-Z)</a></li> <li><a class="dropdown-item" href="name-desc">Name (Z-A)</a></li> <li><a class="dropdown-item" href="old-new">Oldest first</a></li> <li><a class="dropdown-item" href="new-old">Newest first</a></li> </div> </form> -
UrlSegments with Pagination is throwing blank page [SOLVED]
Martinus replied to Martinus's topic in API & Templates
@Markus Thomas In the included file nothing fancy: <?php namespace ProcessWire; ?> <div class="row m-0"> <div class="d-flex justify-content-center align-items-center"> <?php echo $items->renderPager([ 'page' => wire('page'), 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", '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" ]); ?> </div> </div> <div class="row m-0"> <?php foreach($items as $item) { ?> <div class="col-md-3"> <div class="card g-0 border rounded mb-3"> <div class="p-1"> <img class="img-fluid" src="<?php echo $item->image->url ;?>"></img> </div> </div> </div> <?php } ?> </div> -
UrlSegments with Pagination is throwing blank page [SOLVED]
Martinus replied to Martinus's topic in API & Templates
Hi, what do you mean by output? -
I have my 'browse' template where I include one file for display. On my template I use urlsegments (only 1) for sorting, then the include file is called. Everything works fine for it. Yesterday I implemented pagination and it is working fine. On my browse template I have Allow on page numbers and url segments. But here comes my bug: If I sort and then try pagination the url looks like this and works just fine : website-name/products/old-new/page2/ But when I sort again after pagination, it looks like this and throws me a blank page : website-name/products/old-new/name-asc/ How can I correct this? The switch for sorting looks like this: if(strlen($input->urlSegment2)) throw new Wire404Exception(); switch($input->urlSegment1) { case '': // Segment 1 is empty so default sort: NEW-TO-OLD $order = "-date"; $sorted = "newest first"; break; case 'old-new': // DATE $order = "id"; $sorted = "oldest first"; break; default: // Anything else? Throw a 404 throw new Wire404Exception(); } The switch for including a file looks like this: <?php switch($page->name) { case "sellers": case "brands": case "categories": case "departments": // If this page is a Parent-page named 'sellers, vendors, categories or departments'. $items = $pages->find("parent={$page->name}, sort=$order"); $file = "_grid-view-parents.php"; break; case "products": // If this page is a Parent-page named 'products'. $items = $pages->find("parent=/products/, sort=$order, limit=4"); $file = "_grid-view-products.php"; break; } ?>
-
Never mind, I have change it to this code and now it works: <?php echo $items->renderPager([ 'page' => wire('page'), 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", '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" ]); ?> I think it was the 'currentLinkMarkup' that was actually missing ?
-
Hi, I am using Bootstrap 5.2 and so I was implementing the pagination using the 'pagerNav' I have found several names ... My code is as follows: <nav> <?php // pagination and styling echo $items->renderPager(array( 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", 'listMarkup' => "<ul class='pagination'>{out}</ul>", 'itemMarkup' => "<li class='page-item'>{out}</li>", 'linkMarkup' => "<a class='page-link' href='{url}'><span>{out}</span></a>", 'currentItemClass' => "active", )); ?> </nav> All is working, except the 'currentItemClass'. I am not able to style it although using the samples of bootstrap it all works fine. Am I doing something wrong???
-
Migrate PW website to Wordpress?
Martinus replied to orchardheightsdental's topic in General Support
I can only follow up on what I know of wordpress - 'out of the box' of what you are buying of course. But processwire has kept me going and going into depths of possibilities, freedom of what I need and want to do with a website, and so much more beyond that. I like the learning curve and anything involved in PW. I never did that with WP. I personally do not use Wordpress anymore because of the lack of support, the limits of what I need, and the ease of what I have with PW. But for whatever reason you desire to go to WP - I wish you the best of what you can get out of it and hope you succeed. -
Below I have the selector codes of 3 templates that are almost identical in Find and Display. If you are wondering, the sort=$order is an identical switch I use on all 3 templates to sort things I retrieve. But I think, since the code is almost identical, I can do with one template file, then, using a switch or an if-then-else statement to include the file I need (for display). In php I can do this of course, but I was wondering about the outcome in PW, since I use parent = page name, and 'something' = page, or simply nothing. Any advice is appreciated. <?php // parents = parent page from seller, vendor, category and department $items = $pages->find("parent={$page->name}, sort=$order"); ?> <div id="content"> <?php include '_grid-view-parents.php';?> </div> <?php // browse = child page from sellers, vendors, categories and departments, but NOT the products child pages) $items = $pages->find("parent=/products/, seller|vendor|department|category=$page, sort=$order"); ?> <div id="content"> <?php include '_grid-view-products.php'; ?> </div> <?php // products = parent page from all product child pages $items = $pages->find("parent=/products/, sort=$order"); ?> <div id="content"> <?php include '_grid-view-products.php';?> </div>
-
I was searching for 'update field' 'updating field values' etc. In my mind, I had to 'update' the field, since it was already there. But looking at $page->field and $page->save() - were it says: $pages->saveField($page, $field) was the only thing coming close. Maybe it just does not work ?
-
Thanks guys. It worked. I stick with @iank solution then. Just two lines of code. But I still think it is difficult to find information like this in the API, and although the forum people are friendly and all - searching in the forum is complicated.
-
Is there any information about updating a field value at viewing the page, with a name or number? I looked in the docs and cheatsheet and read about $page->set("field", $value); $field->save(); but have no clue on how to implement this. I cannot find any examples either. Found this code just now: echo "old" . $page->numbers; $p = $page->numbers; ++$p; echo "new " . $p; $numbers = $p; $page->save($numbers); But is not updating the field ?
-
Oh, thanks. I did not know that. Good advice!
-
Thankyou all. It worked. But now the question about ID or Name ... which is better to use? I know people will say ID because name can change but ID stay the same. It's just not explaining much in the template if one can see ID but have no clue what page it is, right?
-
What is the right way? In a template file I am trying to make a single link to a specific page. Within the <a href="">Products</a>. I know it's easy while looping by pages->find. But how do I manually do this the right way? /products/ does not work and 'products' is not working either. This gives trouble in the path. I am thinking this is asked so many times, but it's difficult to find in the forum. I was reading through the API too but could not find it.
-
[solved] Count total of field values from pages in selector
Martinus replied to Martinus's topic in General Support
Hi @AndZyk, Your code is what I needed. More small and easier to read. Thank you so much ? -
[solved] Count total of field values from pages in selector
Martinus replied to Martinus's topic in General Support
Oh thanks for that! I prefer not to install to much extra's though. I also came up with a solution: <?php $avg = $pages->find("parent=/products/, seller=amazon, rating>0"); $a = array(); // create new array foreach($avg as $nr) { // loop through items from selector $rating = $nr->rating; // place the found number in a variable array_push($a, $rating); // place the variable in the created array } print_r ($a); // check array echo array_sum($a); // sum of all values in array ?> -
I retieve my Products by $items as $item. Inside each $item-page is a $rating field. $item1 has $rating value 4 $item2 has $rating value 3 etc. I need to count the $rating field-value inside each $item-page that match my selector to get the average. To see how many $item each seller has, I used the code below. But I do not know how to proceed: <?php $qty = $pages->count("parent=/products/, seller=$item"); echo $qty; ?>
-
@DaveP Ooh, I see. My mistake. Could be, it did not work because of that ? But never mind. I dropped the Department already. Thanks anyway.
-
Hi DaveP, what do you mean by double quote on a line? $depts = $pages->find("parent=/departments/"); foreach($depts as $dept) { echo $dept->title; $cats = $pages->find("parent=/products/, department=$dept"); foreach($cats as $cat) { echo $dept->title; $cat->title; $total = $pages->count("parent=/products/, department=$dept, category=$cat"); echo $total; } } ;?> This is what I have so far.
-
How shall I explain ... I display products per child-page (from category or department or seller or vendor or anything else). I am using a browse.php template file for all. This works great. My first page is 'all-products' and inside the products I can click a category, department, seller, vendor, etc. This click, brings me to the child page, using the same template file. So far so good. The childs parent-page is a problem. It is actually using another template (name, let's say 'parent'). Another template, because I cannot display products where seller='seller': it would need to be seller=child-page-name. So, all works great for child pages, but not for parent pages. On the parent pages, let's say 'departments' I need to display the following... All departments on the website. I used this code: $depts = $pages->find("parent=/departments/"); foreach($depts as $dept) { echo $dept->department->title; Within all departments, the category (where there are products to find). I used this code: $cats = $pages->find("parent=/products", department=$dept"); foreach($cats as $cat){ echo $cat->category->title; Display the qty of products to find in this particular category. I used this code: $qty = $selector->count("parent="products", department=$dept, category=$cat"); But it's not working. I am really lost in this. Please, could someone give me a hand in this?
-
I understand if I want to find children of the page I am on I can do that. The API says: // Render navigation for all child pages below this one But in my case I am on one page and finding category pages (elsewhere) - then I display them one by one as $item: foreach($items as $item) { So now I have parent $item-1 and need it's children; I have parent $item-2 and need it's children; etc. $item->children->each( "<li><a href='{url}'>{title}</a></li>" ) works fine.... I think.
-
I have this selector: $items = $pages->find("parent=/categories/, sort=title"); foreach($items as $item) { echo <h4><a href=''>" . $item->title . "</a></h4> <ul>" . $item->children->each( "<li><a href='{url}'>{title}</a></li>" ) . "</ul> But, do I need to check with if($item->hasChildren ? Because the IF does not work.
-
With the ease of Processwire in my hands I feel I can almost do anything to make the website of my dreams ? It's actually getting easier by the day to just not rushing into things and start to think about structure first. Now I am focused what I want to display, later on how to make it look. But there are still some things I do not find with ease on the PW docs. For example, possibilities for sort. By mistake I found out sort=-title (minus sign), is actually sorting on title from Z to A. Another thing is, the difference between Finding and Getting pages it beyond me. Could not found it, did not get it ?. Right now, I am developing a website as affiliate. This means I display product redirecting to certain sellers. But my children have a large part in it: they enhance the look, improve images, test things, and give feedback. My steps to a professional website so far: Getting to know Processwire, so much information to grab. I now know, at install, the code on the pages are examples, not mandatory! Structure files in the root of the website first. Then templates, and pages - according to my idea (what is logic and what is not handy in my situation. Find a template to use with ease: I have found a great free HTML bootstrap 5 template that I use right now. Try behavior design: what would you do on this website you are looking at right now? Take regular breaks, don't try to push things in a limit time, do not make it difficult. But the main thing is: Processwire is so much fun to develop websites (no joke) 10+ for PW. Enjoy
- 1 reply
-
- 8
-
-
Limit characters or words of textarea on certain template
Martinus posted a topic in API & Templates
I searched the forums, API and Docs on Textarea field, but could not find how to limit characters or words in a certain template. I am wondering if there is such a thing in Processwire or do I need to use PHP functions? my code is <p>{item->summary}</p> -
Hi there. I have looked in themes profiles section, tutorials, and other parts of this forum but could not find anything regarding CSS for frontend display. For me, I don't think I have to re-invent the CSS wheel but like to attach a CSS sheet and adapt parts of it in my site. Any recommendations are welcome.