-
Posts
4,035 -
Joined
-
Last visited
-
Days Won
66
Everything posted by Pete
-
Pretty sure it only accepts .jpg, .gif and .png - what file type did you try?
-
Returning articles with the same article, date, category, and tags
Pete replied to BeardedCanadian's topic in Getting Started
Hi there The search API is the API. It's all the same thing, so only one thing to learn. URL Segments are just a way of passing some additional things to the page so you can fine tune what you're displaying. If you had a page called "Articles" with a template "articles-home", what you might do is turn on URL segments and then do something like this, where urlSegment1 is what thing you want to filter by in terms of a and urlSegment2 is what you're matching against <?php if ($input->urlSegment1 == "author") { // Assumes there is a specific field in your article template called "author" and you would match by their name from a URL like www.yoursite.com/articles/author/ted-danson/ $articles = $pages->find("template=article, author.name=$input->urlSegment2"); // As you can see we matched urlSegment1 against the fictitious URL above and the above $articles variable will hold all the IDs for articles by the matched author, urlSegment2 /articles/ is a real page, /author/ is urlSegment1 and /ted-danson/ is urlSegment2 } elseif ($input->urlSegment1 == "category") { // Now imagine our URL is www.yoursite.com/articles/category/autobiographies $articles = $pages->find("template=article, category.name=$input->urlSegment2"); } elseif ($urlSegment1) { // If someone is still passing an URL segment and it's not one we recognise and have dealt with above, it would be best to throw an error. People could be typing in all sorts of rubbish otherwise like www.yoursite.com/articles/bunnies/ninja/ throw new Wire404Exception(); } else { // So in this very last one we've not got any URL segments at all, so we probably just want to list the last ten articles with no search parameters applied $articles = $pages->find("template=article, sort=-created"); // This lists all articles in reverse date order // You can also add ", limit=10" stragith after the word "created" in the selector above, or any of the ones above to just return a certain number of results and then look into pagination elsewhere on the site and forums to implement that rather than display potentially thousands of results on a page } // And now you have your $articles you can do something like this (I've assumed you've added a field to the article template called "date": foreach ($articles as $article) { echo "<h2>$article->title</h2> <p>Written: $article->date</p> <p>$article->summary;</p> <p><a href='$article->url'>Read More</a></p>"; } Now the only reason I could see for you matching articles on a specific date was if you were maybe reading articles on a busy site and at the end of a specific article you wanted to see a list of other articles on that date. Even so I can't think why you might want to do that, but here's some code that might help - remember you've now just read an article and at the bottom of the page we want to list other articles on that date: <?php // We're getting articles on the same DAY (the exact time as the current article would be a little pointless as you're down to matching the second in that case) // We'll assume that the date the article is saved in ProcessWire is the date you want to use to find other articles posted on the same day, however it could easily be your own date field - for the purpose of the example below this just means I'm matching against the "created" field in the database $startOfDay = date('j F Y', $page->created); // Since this will be a horrible timestamp to the SECOND that the article was published, we're turning it into something that reads like this: "12 September 2012" $startOfDay = strtotime($startOfDay); // Then we're turning that from a human readable string back to a timestamp, except now it is 0:00am on that day - the start of the day! $endOfDay = date('j F Y', $page->created) . " +1 day"; // Now we're doing the same again, but you can tag " +1 day" on the end of the string... $endOfDay = strtotime($endOfDay); ... and strtotime() is clever enough to add a full day onto the date $articles = $pages->find("template=article, created>$startOfDay, created<$endOfDay"); // Easy huh? Not if you don't know some of the above date functions obviously, but it's well worth looking on PHP.net as everything before the line directly above involves just some pure PHP to manipulate the date and is well worth spending a little time learning. Let us know if you need any more examples. The search functionality just uses the same functionality above from what I remember except it sends the search query to a specific search page and then matches the string the person entered against various fields like "body" and "summary". It's all the same sort of code behind the scenes. This is also the reason you won't see a generic example - they just don't make sense as everything uses selectors to find results (plus real-world examples are easier to understand for the most part): http://processwire.com/api/selectors/ -
I'm also interested as there is one scenario for an intranet that I've got in my head where it wouldn't be a bad idea to have the whole thing as Process modules in the backend and simply not have a frontend. The only problem there is that you still have to have the root page I guess, but it would be good to make something like /login/ the default page in this scenario and run the admin from just the root instead of /processwire/
-
Love it I was naughty and searched for cottages available in the past and it still returns results, but not sure if availability is linked in yet?
-
Top graph is posts made per month, bottom is cumulative over the same time period. Nice! It's not gone vertical on the cumulative posts, but that's fine as I'm still many pages of unread posts behind where I'd like to be
-
Over 45,000 posts now too folks
-
Just looked at the video for Scout App - works well for Windows or Mac and the video shows it as simple to use for those of us who don't see why we should be doing any command line stuff and installing Ruby when there's a simpler (lazier) solution Though I also like the look of the others - Codekit is especially interesting for its other features at a low price tag!
-
One thing to note with the new theme is that in one module I'm working on that uses jQuery to watch certain elements for changes it no longer works because I assume some of the elements' parent containers have changed. Not difficult to fix, but might break a few modules is all I'm thinking. EDIT: To fix mine all I had to do was change references for .ui-widget-content to .ui-widget-content, .InputfieldContent
-
Yep, basically what Martijn said. Go to Setup -> Fields -> Add New Field Add a name and label for your field and change the Type dropdown to File Under the Details tab you will see allowed filetypes and PDF is in the list - alter the list to suit you Change Maximum Files Allowed to however many you want - perhaps 1 in this case? Save your changes Add to your template That's it really.
-
Sounds like it could be useful for centrally storing images on a different server for multiple sites, but I have no idea what scenario that would be used in.
-
Wonder if this is of use for less tech savvy users: http://leafo.net/scssphp/ Theoretically something that could be bundled into a module
-
I meant to say "when time permits" and not sound like I think you actually have any spare time
-
Like it - nice additions One thing I was thinking about a while back was being able to maybe use a colorpicker to select 3-4 primary colours and have a module save those to a CSS file so the admin colours could be changed easily. Might be something worth considering time-permitting? Obviously you can end up with some pretty garish colour schemes that way so would be one for superusers to control I think.
-
You can do this on any PageArray: echo $yourresults->getArray(); Taken from here: http://cheatsheet.processwire.com/ (you'll need to click on "advanced" at the top to see this though.
-
You could do category.name=cat1name|cat2name|cat3name Basically the pipe character --> | <-- means OR, which should work for your case. The above is for the page name field, but you could just as easily do category=1027|1038|1057 if you want to match against the page ID
-
No worries, if you run into anything else then let us know. A really useful tool for the most common functions is the cheatsheet if you've not already seen it: http://cheatsheet.processwire.com/ Welcome to ProcessWire by the way, and have fun!
-
I'm confused - this would surely just echo the URL of that page: echo $header_page->url; ?? To render it you would want this instead: $header_page->render(); So in your other script, you could do this: // Include ProcessWire require("../index.php"); // Get header $header_page = wire()->pages->get("/external_head/"); $footer_page = wire()->pages->get("/external_foot/"); echo $header_page->render(); //.... the rest of your other script goes here echo $footer_page->render(); That should work I think, unless I've misunderstood what you're asking for. It also assumes that there will be no conflicts between variables in ProcessWire and your other script, but you would know if that's the case soon enough when it throws you errors I must admit, I do like the concept. I know of an intranet script I've worked on in the past where I tried to make ProcessWire work inside that script's header and footer for old pages, and new pages had the header and footer and the pages themselves in ProcessWire, but this would have been a better idea in terms of wrapping a consistent header and footer around both the old and the new pages until they're all ported over to ProcessWire.
-
I think the people are your starting point in this case, as each one that's added would relate to places and events and populate those sections. The trouble would be keeping track of which places and events have already been added and linking to them accordingly, but I suspect that you've got the perseverance to pull it off since it seems you've already collated this data yourself over a number of years
-
Now available in the modules directory: http://modules.processwire.com/modules/admin-template-columns/
-
Thinking about how you would use a person#s free-text search string (assuming you wanted to) like this: You would be wanting to look out for words like "born" first, and then look for a 4 digit number. More complex is this: as you would then have to look for both "born" and "died" and then the year, but that's not too difficult. Worse still is this nightmarish example: Nobody is likely to type that in, but your key words there would be birthday, born, died and posion with a date being harder to pull out depending on locality of the person searching (for example, I could have typed "October 1 1981" instead, so you would need some sort of regex to catch the most common of those if you wanted to). Once you have your result from that query though, you could weight (or just categories) the results by people who were born or died on that day, people that have birthdays on that day and people that were poisoned on that day. And now I'm getting a headache thinking about it all But I definitely think that if you allow search strings like this then matching against key search phrases (born, birth, birthday, died, dead, death, murdered etc) and then looking for some form of date is the way to go to work out what the user actually wants. I think you might give up at the point someone types "Who was born or died between October 1 1990 and 22 November 1990 and who was poisoned on 3 February 1700..." etc etc - more than one date might get tricky, but it feels like the best way to approach it is to assume people won't type in anything ridiculous as those who do will be in the minority (hopefully!) At any rate, I think you're going to have some fun (and headaches) with your search algorithm!
-
It sounds like you might be getting hung up on how to structure each entry - my advice would always be to treat people and categories separately where you need to place a person in more than one category. For example, all of your people would go under /people/ with a template called "person" and each category stored in a tree like /categories/deaths/, /categories/deaths/suicide/, /categories/deaths/murders/ with template called "category". That way you could create a Page field called "categories" (Page List Multi Select like this would be favourite: http://processwire.com/videos/page-fieldtype/ ) and add it to the "person" template so that you can tag multiple categories against the same person. This way, you can do some searches like this: $people = $pages->find('template=person, category=suicide|poison'); That will return a PageArray of all people who match categories of suicide or poison. You could also do some weighting of results so that the more categories they match the higher they come in the results, but I think your biggest hurdle will be turning your human-readable search string into something useful. Once you've done that though, you're simply matching the keywords against categories in ProcessWire and the rest is relatively easy Something like this as a quick example: <?php foreach ($people as $person) { echo "<h1>$person->title</h1>"; // Their name echo "Died of: "; echo "<ul>"; foreach ($person->categories->find('parent.name=deaths') as $death) { // Searching under a parent page name of deaths within this person's categories will return how they died - quite lengthy for some historical figures! echo "<li>$death->title</li>"; } echo "</ul>"; } Of course, you could have a whole separate categorisation system for deaths rather than lumping things together under categories like this, but since you're likely to have a great many categories and everything you would search for in this system is a means of categorisation I thought I'd do the example above.
-
Yep - I was just using it for debugging purposes to see if I could get it to dish out any data. When it fails it just 404's, so I suppose others are testing in browsers and getting errors maybe.
-
Something like... repeater field with only one entry allowed
Pete replied to benjaminE's topic in Getting Started
But you can create a fieldgroup in a template already I think we may need some visual drawings in Photoshop or on a piece of paper scanned in maybe to explain what's being asked here -
You could do: $config->var = array('item' => 'val', 'item2' => 'val2'); echo $config->var['item2']; Doesn't look as neat as you want, but should do the trick.
-
Will upload it to modules directory next week when I'm back home