Different Content Types

Feed 24 posts, 4 voices

Aug 6, 2008 20:58
Avatar
351 posts

So back to the discussion of reusable Parts or different content types. My impression is that you can simulate different content types by creating a Part that you use to identify the content type. You might leave this blank, because it's purpose is to identify the content type rather than being a Part you use, though you can use it. But if you had for example a content type called Themes, you could simply create a Part called "Themes"

Then you can do a select in the database: mysql> select distinct page_id from page_part where name="Themes";

That will give you a listing of the page ids for the content type Themes. You can then take the page id and do a query like: mysql> select content from page_part where page_id=21 and name="Author";

That will give you the Author Part associated with that page.

My question then is how do you do turn this into a plugin where you will get methods that you can use. Methods or classes where you can specify the content type and then be able to get the different Parts that correspond to it, and be able to use those parts, so you can output listings.

Unfortunately I'm not experienced enough to figure it out myself, but it seems like it should be possible.

What do you guys think?

 
Aug 6, 2008 21:02
Avatar
351 posts

by the way this is a continuation of the discussion at the reusable parts thread: http://forum.madebyfrog.com/forum/topic/298/2

 
Aug 6, 2008 21:09
Avatar
351 posts

so that you can do something like this in pseudoish code:

restaurants = customContent("Restaurants")

for each restaurant in restaurants { echo restaurant->name; echo restaurant->address; echo restaurant->phone; }

 
Aug 6, 2008 21:26
Avatar
351 posts

To implement it perhaps something along these lines?

array of page ids = sql query (”restaurants”)

for each of the page ids create an object with attributes corresponding to each of the page’s parts, which you can get via something like "select content, name from page_part where page_id=21;"

collect all he objects into an array

return the array of objects to the calling method.

Would that work?

 
Aug 6, 2008 21:37
Avatar
351 posts

The reason I'd like this feature is I got really sick of adding data repetitively. Having to write markup for a listing of even say 20 items is annoying. And it's even worse because you're repeating yourself as long as each of those items have their own page, with the same information repeating itself. THen think about how you have to keep these in sync so that your page of listings corresponds to all the records you have.

So I think a feature like this is very important.

It would also make it possible to display the data in different forms on different parts of your site. Maybe somewhere say on the home page you want a widget that just displays one Part of a specific content type. For example, a widget that says "New Themes" and which displays just the name of the theme.

So another nice part of this would be if you can sort by date, so you can easily create these widgets that display new records for a specific content type.

 
Aug 7, 2008 03:22
Avatar
26 posts

Not really thought about this, but could you also use tags (if you're not using them for something else)? This would avoid having to create an empty part. In my case I could also use the keywords since I don't actually use the page specific keywords either at the moment...

 
Aug 7, 2008 18:27
Avatar
351 posts

hi tom, from what i can tell the tags don't inherit, so it may be somewhat less convenient than using a part to identify the content type...

 
Aug 8, 2008 05:03
Avatar
963 posts

I still can't help thinking how much this sounds like XML!

What you describe, ricks, sounds possible in Frog, and some of the community have the skills to make it happen (I don't!).

Another thought, sparked by the XML connection, is to find of way of making Frog use external data-sources. Then you could have your restaurant list in an external XML file, but handled within Frog.

I was inspired by siriomi in this thread to take a look at lastRSS, which I now have working on localhost for a Frog-based personal homepage, bringing in feeds. I'm aware there are things like Simplepie, too, though I haven't looked more closely. I realise that is "dynamic" external datasource, but I wonder if such things might not be suggestive for thinking about other ways of bringing structured data into Frog.

Of course, there is something appealing about the scenario Ricks is sketching: nice to take care of it all from within this lovely CMS. :)

 
Aug 8, 2008 05:52
Avatar
351 posts

hi david, i think i understand what you're saying about xml and it's not difficult to bring xml in to frog to just display it. i have a frog site that parses and displays news feeds using simplepie, and it wasn't a big deal to get it working.

but i think the difference here is that i need the data not just listed on one page but also with a page for each record (in this example, for each restaurant). i need it persisted in the frog database in other words. and i'm not sure how an external xml source would help. i don't want to code another form or application somewhere else to take the data and i don't want to write the xml markup either. so ideally i would just be able to use frog's existing parts.

 
Aug 8, 2008 05:56
Avatar
351 posts

and i do want to have full control over data that doesn't really belong with the data but with the page. with restaurants for example it may make perfect sense to associate each restaurant with a name, a phone number, etc in the xml. but other data like slug, keywords, page title and so on really are associated with the restaurant's page, not the restaurant itself, and i want to have that data somewhere...in Frog!

 
Aug 8, 2008 06:31
Avatar
963 posts

Yeah ... I see what you mean. Thus my final comment about your "appealing scenario" and keeping this all in Frog! it would also give Frog some quite powerful options, without in any way compromising the appeal of its simplicity. And that's good thing, too!

(P.s., if you have some live Frog sites out there, I'd love to see them! If you'd rather not post them to the forum, you could always shoot me a note from here. :)

 
Aug 8, 2008 06:37
Avatar
351 posts

hi David, i have some sites out but they are not yet ready for primetime :)

more like placeholders right now...

 
Aug 12, 2008 21:09
Avatar
351 posts

hey guys, i came up with a simple solution that will return an array of arrays, but i'm not sure how to bring it into frog and turn into a re-usable plugin.

this is what i have so far: http://pastie.org/251962

please advise!

 
Aug 13, 2008 03:15
Avatar
277 posts

Looks interesting. Just let me test it.

 
Aug 13, 2008 03:20
Avatar
277 posts

I don't know if I understand what you want to achieve. You want to show all the pages/articles which have a common page part ?

 
Aug 13, 2008 03:25
Avatar
351 posts

yeah, the common page part just identifies the content type. the idea is to simulate different content types in frog. so in this example, the content type is Recipe. it's actually created as an empty Part, and it's used just to identify the content type.

so the code i have there grabs all the recipes in the database so that it can be shown as a listing for example on another page.

 
Aug 13, 2008 05:52
Avatar
963 posts

This could be a very powerful feature - sort of like tags on steroids! Tags let you combine on one page links to pages with a similar ... tag (!). Doing this with page.parts lets you gather content of the same kind to a single webpage, presumably with links to those pages if you wanted -- even though that content is stored (in the db) in different Frog pages.

Another example: think of a site for a small business. You want a page for the "team", so you have a "Meet the Team" page, and subpages for each member. If those subpages had page.parts of "Body" (req'd?), Pic, Bio, Contact -- then you could use Ricks's method to pull just the Body + Pic on to one page, with click-through to the full (sub)page of the "team" member where you would find body + pic + bio + contact.

There could be all kinds of uses for this, and would give the "page.part" element of Frog all the power of custom fields that you would normally want.

Or so it seems to me! I regret I lack any coding skills whatsoever to help with this, though!!

 
Aug 13, 2008 06:06
Avatar
277 posts

Ricks, if you need any additional help or some help to code it as a plugin, just contact me at bebliuc.george [at] gmail [dot] com .

 
Aug 13, 2008 17:29
Avatar
351 posts

Thanks for the offer to help, Bdesign. I'll probably be in touch with you soon.

David, thanks for another great example of how this plugin could be used and what the benefits would be.

I guess with the plugin, what I'm really wondering about is how to access the database. I know Frog must have internal methods for making database calls so that I don't have to specify database name and authentication information. I tried to look for the Frog API documentation but the page is blank:

http://www.madebyfrog.com/docs/plugins-api.html

If I can just get that information I can probably put together a rough and simple plugin myself.

 
Aug 13, 2008 18:15
Avatar
277 posts

To manipulate the database you have to first global $__FROG_CONN__; , then you will use PDO to create querys. Here is an example : $stmt = $__FROG_CONN__->prepare($sql); $stmt->prepare(); $result = $stmt->fetchObject(); . We will talk on private... and I'll explain.

 
Aug 13, 2008 22:12
Avatar
351 posts

Bdesign, thanks for posting the information there. I looked up PDO and managed to get it working as a plugin. Basically this is what I have:

http://pastie.org/252691

It works fine and it's probably all I need right now, but I'd appreciate advice on how it can be better, more object-oriented etc.

Anybody who wants to use the code is welcome to. It just returns an array of all the records for the content type passed in. It returns an array of an array. You're on your own as far as sorting, pagination and whatever else.

For sorting you will probably want to use usort() and pass in whatever comparison method you want to use for that column. Pagination can be achieved using offsets. I actually haven't had a chance to deploy this yet, but I think it should work fine. If I run across problems I'll let you know.

 
Aug 14, 2008 16:32
Avatar
351 posts

Okay, first question: How do you create URLs in Frog? I have the slug. How do I get the rest of the URL?

Thanks

 
Aug 14, 2008 17:56
Avatar
351 posts

This is what I have for doing URLs:

http://pastie.org/253262

It works fine for when you have the listing on a "directory" and all the pages as children of that directory. In other words if you have the listing on site.com/shops

then it'll work for the cases like: site.com/shops/victorias-secret site.com/shops/fredericks-of-hollywood

etc.

 
Aug 14, 2008 18:26
Avatar
351 posts

actually hang on. i think i will add a sort method to the plugin...

 
Aug 14, 2008 19:45
Avatar
351 posts

See the new thread in the plugins section: http://forum.madebyfrog.com/forum/topic/431