kyle Posted July 23, 2013 Share Posted July 23, 2013 I want to start using ProcessWire on larger projects, so I was going to start with a little personal project. I am going to attempt to make a Craigslist clone, but I am not sure the best way to structure the site. There will be cities and within the cities there will be ads. My original idea was this:Main Ad Pages -- Electronics -- Furniture -- etc.. If you are a registered user you have a city associated with your username. When you visit one of the categories it gets your city and finds all of the ads from the same city. I just don't know how scalable this would be. ------------------ Alternatively, my other idea was this: City 1 -- Electronics -- Furniture -- etc... City 2 -- Electronics -- Furniture -- etc.. Which idea would be the best? Or is there a different way to do this? Ideally, I am looking for the most scalable solution. Link to comment Share on other sites More sharing options...
diogo Posted July 23, 2013 Share Posted July 23, 2013 I think this tutorial by @kongondo will be very usefull to you http://processwire.com/talk/topic/3579-tutorial-approaches-to-categorising-site-content/ Link to comment Share on other sites More sharing options...
kyle Posted July 23, 2013 Author Share Posted July 23, 2013 @diogo Thanks for the link. I wasn't sure if it was applicable to my situation, because I am not sure if this would be a good use case for pagefields. Do you think pagefields would work well with what I'm trying to accomplish? My main concern is that different ad types have different fields associated with them. Link to comment Share on other sites More sharing options...
kongondo Posted July 23, 2013 Share Posted July 23, 2013 @Kyle, The principle is the same. Basic questions to ask yourself: Can an Ad belong to more than one type (e.g. electronic, furniture, etc.) Can an Ad apply to more than one City? Remember, page fields give you access to ALL information about pages selected via the page field...e.g. $page->selected_single_page_field_name->title will give you the title of the page currently selected in that page field (here, single page reference field type)...You can do this for other fields belonging to the selected page, can iterate its other fields, etc. Link to comment Share on other sites More sharing options...
kyle Posted July 23, 2013 Author Share Posted July 23, 2013 @kongodo Thanks for your help again! So to answers these questions: no, an ad can only belong to one category and one city. So I guess I am having a little trouble understanding the fundamentals of page reference fields. With this link: http://processwire.com/videos/page-fieldtype/ it goes about showing related pages. So how would that work into sorting ads by categories and cities? How is that an advantage to sorting things differently than: City 1 -- Electronics -- Furniture -- etc... City 2 -- Electronics -- Furniture -- etc.. Link to comment Share on other sites More sharing options...
kongondo Posted July 24, 2013 Share Posted July 24, 2013 Kyle, If an AD can only belong to one City and one Category, then I would probably do it like below (almost similar to what you have...). Cities would be parents of ADs. Categories would be children of Category... City 1 AD 1 - C1 AD 2 - C1 City 2 AD 1 - C2 AD 2 - C2 AD 3 - C2 AD 4 - C2 City 3 AD 1 - C3 AD 2 - C3 Category Electronics Furniture Books This will keep my setup DRY. I do not have to repeat categories like you have in your example. ADs will have Single Page Reference Fields. I would restrict selection in this field to just children of Category (electronics, etc.). Cities will have a "cities" template with minimal fields. ADs an "ads" template with all the necessary AD fields + a Single Page Reference Field to select one category. Categories would have "categories" template probably with just a title. Searching: Written quickly, there could be errors, etc //find all ads of a city. 1007 is the ID of the city; you can use path or name of the city as well $ads = $pages->get(1007)->children("sort=title, limit=50"); //find all ads of a city that belong to electronics category. "category" is the name of the single page reference field. "electronics" is the name (title works as well I think?) of the category page $elecronicAds = $pages->get(1007)->children("sort=title, limit=50, category=electronics"); //find all ads belonging to electronics irrespective of city $elecronicAds = $pages->find("category=electronics, limit=50"); //find all ads and sort them by city, then category $allAds = $pages->find("template=ads, sort=parent, sort=category, limit=50"); There's probably better ways of doing this + you have other selectors at your disposal, but this should give you an idea 6 Link to comment Share on other sites More sharing options...
diogo Posted July 24, 2013 Share Posted July 24, 2013 Edit: ignore this post. The reason is explained by kongondo three posts below I would do it in a different way. Since the city is associated with the user, makes less sense to have the ads as children of the cities. I would probably put the ads under the user himself. Like this you would have cities and categories as page fields. users -- user 1 ---- ad 1 ---- ad 2 ---- ad 3 -- user 2 ---- ad 1 ---- ad 2 categories -- electronics -- furniture -- books cites --city 1 --city 2 edit: the ability to have the ads as children of users depends a lot of how you will create the users. But you would get the same effect by having all the adds under a "ads" parent, and connect to the user with a page-field or simply using "$page->createdUser" 2 Link to comment Share on other sites More sharing options...
kongondo Posted July 24, 2013 Share Posted July 24, 2013 Aaah, I forgot the user bit. Thanks Diogo...However, the ADs belong to the City and I think they should be together. In addition, I don't think the City is associated with the user. I think it is the other way round. The user is associated with the City. If the user is no longer registered, the City remains . Would it not be possible to restrict users to their Cities using the City template (access rights)? This way, we only have one instance of each AD but this can be accessed by multiple users. In your example, are those ADs repeating for each user? I would create users using normal PW access model. Maybe I am not reading this properly. 1 Link to comment Share on other sites More sharing options...
diogo Posted July 24, 2013 Share Posted July 24, 2013 Maybe the best would be like I told on the edit. To keep everything separated and connected with page-fields. are those ADs repeating for each user? No, where you read "ad 1" i mean "ad 1 from user 1" and "ad 1 from user 2" Link to comment Share on other sites More sharing options...
kongondo Posted July 24, 2013 Share Posted July 24, 2013 Maybe the best would be like I told on the edit. To keep everything separated and connected with page-fields. No, where you read "ad 1" i mean "ad 1 from user 1" and "ad 1 from user 2" I think this is where the confusion arises. I am assuming Kyle means "ADs for User 1, etc"...according to their City, but your example suggests "ADs by User 1, etc". Question is, who is posting the ADs?; these Users or others? 2 Link to comment Share on other sites More sharing options...
diogo Posted July 24, 2013 Share Posted July 24, 2013 You're right... I read understood it wrong! delete everything Link to comment Share on other sites More sharing options...
kongondo Posted July 24, 2013 Share Posted July 24, 2013 You position could be right,...ESC delete!...Kyle will enlighten us.... Link to comment Share on other sites More sharing options...
diogo Posted July 24, 2013 Share Posted July 24, 2013 You're just trying to be nice By reading it again, it can't be right... 1 Link to comment Share on other sites More sharing options...
kyle Posted July 24, 2013 Author Share Posted July 24, 2013 Ah thanks for the help this does give me some good direction. So what I wanted to do was actually have it so if you're not logged it you see all the ads, and if you are logged in you can only see ads from your city. So I guess the user would kind of belong to a city. Link to comment Share on other sites More sharing options...
ryan Posted July 25, 2013 Share Posted July 25, 2013 So what I wanted to do was actually have it so if you're not logged it you see all the ads, and if you are logged in you can only see ads from your city. if($user->isLoggedin()) { // display ads from your city } else { // display all the ads } 2 Link to comment Share on other sites More sharing options...
diogo Posted July 25, 2013 Share Posted July 25, 2013 Complementing Ryans code. If you have a page field on the user template that points to one city page, and you have the ads as children of pages: if($user->isLoggedin()) { // display ads from your city foreach($pages->find("parent=$user->city" as $ad)){ echo $ad->render(); } } else { // display all the ads foreach($pages->find("template=ad" as $ad)){ echo $ad->render(); } } Of course it has to be even more complemented with pagination and those things... but it gives you an idea 2 Link to comment Share on other sites More sharing options...
kongondo Posted July 25, 2013 Share Posted July 25, 2013 Nice one guys @Diogo...thanks for the reminder about user templates being editable. I usually forget that... Btw, you are missing the closing ")" in your selectors' code 1 Link to comment Share on other sites More sharing options...
diogo Posted July 25, 2013 Share Posted July 25, 2013 Corrected. The forum should throw a PHP error when you make those mistakes while writing directly in the browser 1 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