adrianmak Posted January 24, 2015 Share Posted January 24, 2015 By no doubt, wordpress is the greatest blogging platform. The auto archive feature is good for a blog site. How to implement in processwire, such that the page's (blog post) url is something like in wordpress, prefix by date for instance, http://mysite/2015/01/05/page-title-name Link to comment Share on other sites More sharing options...
Joss Posted January 24, 2015 Share Posted January 24, 2015 The easiest way is to actually structure your site like that, to be honest. Or any other way you feel is right for a particular blog or site. That is what makes PW so powerful. Link to comment Share on other sites More sharing options...
adrianmak Posted January 24, 2015 Author Share Posted January 24, 2015 The easiest way is to actually structure your site like that, to be honest. Or any other way you feel is right for a particular blog or site. That is what makes PW so powerful. could u give some direction on how to structure pages like that ? Link to comment Share on other sites More sharing options...
Nicolas Posted January 25, 2015 Share Posted January 25, 2015 could u give some direction on how to structure pages like that ? The first (maybe naive) structure that come my ming is as seen on the screenshot below You may also want to look at the blog module here. 2 Link to comment Share on other sites More sharing options...
Pierre-Luc Posted January 25, 2015 Share Posted January 25, 2015 You would use url segments on your home page. Then from the segments, build a query using $pages->get("selectors") to return a page from this. You'd probably want to use /2015/01/05/ to select the page by date using the "created" field, and page-title-name to select the page by the "name" field, which is used for urls. It would probably look something like that (note that I didn't test this): $year = $urlSegment1; $month = $urlSegment2; $day = $urlSegment3; $name = $urlSegment4; # Assuming your blog posts use a template called "post"... # You need to do >= and < on created because it's using timestamps, # so you're looking for something in a range $page = $pages->get("template=post, created>={$year}-{$month}-{$day}, created<{$year}-{$month}-{$day+1}, name={$name}"); if(!page) { // redirect to 404 or another page or do something else } . . . I personally wouldn't use a directory structure for this, it just makes moving things harder. In WP, these folders don't really exist really either. Also note that you could probably just skip checking the creation date, since page names (url, not to be confused with the title field) are already unique by default. But you might want it anyway for some reason. 2 Link to comment Share on other sites More sharing options...
adrianmak Posted January 25, 2015 Author Share Posted January 25, 2015 The first (maybe naive) structure that come my ming is as seen on the screenshot below You may also want to look at the blog module here. I'm wondering this method is not quit user friendly, user have to create month, day page before create a blog post. I think Pierre-Luc way is the right direction instead. Link to comment Share on other sites More sharing options...
adrianmak Posted January 25, 2015 Author Share Posted January 25, 2015 I just read thru the url segments documentation. It given example of url segments are appended on actual url. My case is opposite. url segments is prepended of a actual url. Link to comment Share on other sites More sharing options...
diogo Posted January 25, 2015 Share Posted January 25, 2015 I agree, this would be a mess for the user Link to comment Share on other sites More sharing options...
diogo Posted January 25, 2015 Share Posted January 25, 2015 I just read thru the url segments documentation. It given example of url segments are appended on actual url. My case is opposite. url segments is prepended of a actual url. Not a problem in this case. You would use the template of the parent page, "posts" in this example: Posts post1 post2 post3 The post pages themselves wouldn't need a template, since they wouldn't be shown directly. The only problem I see with this approach is that you wouldn't be able to use the $page->url method for getting this pages, but create your own method to generate the new urls Anyway, I'm not sure that these WP urls are really better than mysite.com/posts/post-name 3 Link to comment Share on other sites More sharing options...
adrianmak Posted January 25, 2015 Author Share Posted January 25, 2015 could I use by year in selecting pages? For example, to get all post of year 2014 $page = $pages->get("template=post, created=2014, name={$name}"); Link to comment Share on other sites More sharing options...
Pierre-Luc Posted January 25, 2015 Share Posted January 25, 2015 As I explained earlier, you will need to use a range (min and max values) on created because it uses timestamps to match dates. That would look like created>=2014-01-01, created<2015-01-01. PW doesn't understand only years, you'll need to use properly formatted dates. Link to comment Share on other sites More sharing options...
adrianmak Posted January 25, 2015 Author Share Posted January 25, 2015 For testing my code, is it possible to alter post's date to older date ? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 25, 2015 Share Posted January 25, 2015 Date archiver automatically archives pages based on a Datetime field (e.g. /news/2013/01/03/some-news-item/). 2 Link to comment Share on other sites More sharing options...
adrianmak Posted January 25, 2015 Author Share Posted January 25, 2015 For learning purpose, I will try to write my own code Link to comment Share on other sites More sharing options...
Nicolas Posted January 25, 2015 Share Posted January 25, 2015 Having to create month and days beforehand sure is not as user friendly as one can imagine i agree with that. You can explorer Pierre-Luc's or Diogo's solution as with Processwire there's more than one way to do it. You can also get great insights on the process of migrating a site from Wordpress to Processwire exposed by Ryan himself. Link to comment Share on other sites More sharing options...
diogo Posted January 25, 2015 Share Posted January 25, 2015 I think a balanced solution would be staying in the middle of both solutions discussed. Create pages for the years and use the url segments on those pages instead of the parent "posts" page: posts 2015 <-url segments would be used on the template for these pages post5 post4 post3 2014 post2 post1 This would make it easier to use the "posts" for listing the posts and use the year pages only for the purpose of displaying the individual post pages. Also, you could reduce the url segments to 3 (the default) instead of 4. You don't really need to use a range of timestamps to decode the url. All you need for getting the right post is the last segment (the name), and you can use the day and month to validate the page, by confirming that they match the post's date and throwing a 404 when it doesn't. The reverse (creating the urls) is just as easy. You can, for instance, display the parent's url (mysite.com/2015/), add the month and day using the posts date and PHP's time function and add the post's name in the end. I'm not giving code examples because you said you would like to write your own code for learning purposes Link to comment Share on other sites More sharing options...
adrianmak Posted January 25, 2015 Author Share Posted January 25, 2015 My code (very rough) is almost done. But I have to need more posts in different date & time for testing. Any how to alter posts date ? Link to comment Share on other sites More sharing options...
renobird Posted January 25, 2015 Share Posted January 25, 2015 For dates I would suggest adding a date/time field to your template. Call it "post_date" for example. Have it default to today's date. That way you don't have to set it, but you can adjust it if needed. This lets you pre/post date your entries easily. Now instead of using "created" in your selector, use the name of your new date/time field "post_date". 1 Link to comment Share on other sites More sharing options...
adrianmak Posted January 25, 2015 Author Share Posted January 25, 2015 For dates I would suggest adding a date/time field to your template. Call it "post_date" for example. Have it default to today's date. That way you don't have to set it, but you can adjust it if needed. This lets you pre/post date your entries easily. Now instead of using "created" in your selector, use the name of your new date/time field "post_date". As you suggested, I added a post date on blog post template. However, the default value only show the date, how to default both date with time ? Link to comment Share on other sites More sharing options...
diogo Posted January 25, 2015 Share Posted January 25, 2015 It's all on the field's settings. Go through them and you'll find it. 1 Link to comment Share on other sites More sharing options...
kongondo Posted January 25, 2015 Share Posted January 25, 2015 (edited) @adrianmak, for all Fieldtypes (page fields, date/time field, colour picker, etc, etc...both custom and core) if you want to check if they have settings that can be configured by the user, edit that field and check out their 'Details' and 'Input' tabs. Please try that and let us know if you still can't get time to display in your 'Post Date'. Edit: Beaten by Diogo Edited January 25, 2015 by kongondo Link to comment Share on other sites More sharing options...
Soma Posted January 25, 2015 Share Posted January 25, 2015 It's also easy to create a hook that creates folder automaticLy and put post there or move it if date changes. 1 Link to comment Share on other sites More sharing options...
adrianmak Posted January 25, 2015 Author Share Posted January 25, 2015 It's all on the field's settings. Go through them and you'll find it. I'm sorry. I tried all possible field settings, but the default value still only show a date only. Link to comment Share on other sites More sharing options...
kongondo Posted January 25, 2015 Share Posted January 25, 2015 4 Link to comment Share on other sites More sharing options...
adrianmak Posted January 26, 2015 Author Share Posted January 26, 2015 date-time-input.png I have this field set. But when add a new page, the post_date field populated from today date is still shown date only, no time Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now