keyword sorting

Permalink
I am wondering if it would be possible to display/sort pages by keyword. (Or tags, or however you want to word it)

I basically would like to generate a list of pages that carry particular keywords. So on a page there can be a page-list/autonav type thing in the side bar and it lists, say, all pages related to Apples. Whereas on each page I would have somehow tagged it to being related to Apples. And any single page may be keywored with Apples, Oranges, Pineapple or any combination thereof.

The pages are all in separate sub-navs, if that matters. They need to stay that way...

I don't mind getting my hands messy with PHP if I need to, but figured I'd ask about it before venturing off on my own.

lisbokt
 
elyon replied on at Permalink Reply
elyon
Although it might be possible to read values out of the pages meta keywords or description, I think that the cleanest approach would be to use a custom page attribute.

Go to Dashboard > Pages and Themes > Page Types. Click "Add Page Attribute".

You could do it as "Text" or "TextArea", but I think that "Select" might be the best way to go. In this way, you can choose one of several choices when you create a new page, then you can add new choices to the page attribute later if you need a new category. I would probably only use the "Text" style of attribute if the categories were constantly changing.

I don't think there's a block that would currently let you filter pages based on a custom attribute, so you could either write your own block or you could make a custom template for a page list or auto-nav block. I think the latter would be easier. In that way, you could set up all the normal options, but add a custom template for each category you need. Otherwise if you're comfortable writing your own block, it could probably be done pretty easily.

I don't know off-hand what the code is for looking up page attributes, but this should help give you a start in thinking how to build this
lisbokt replied on at Permalink Reply
lisbokt
This was a really helpful start.. thank you!

For what I'm doing, it would be woefully cumbersome to make a separate template for each category. The site is fairly large (200+ pages) and the tag list will be fairly long (at least 40 to start).

Some of the tags will have 20+ pages, other tags will have three or four.

I was kind of thinking of a code that automatically pulled whatever tags were assigned to that page, and then spit them out as a list ("related pages").

This is kind of sounding like "build my own block" time.. hrm.. (Goes off to read tutorials on that)
elyon replied on at Permalink Reply
elyon
When I started making blocks I often copied or duplicating existing blocks to make it easier to get started.

Here's the basics:

In your /blocks directory, create a new directory for your block, like "tag_display"

Inside this new folder, you'll need "add.php", "edit.php", "controller.php", "view.php" and "db.xml"

Inside db.xml, make sure to give the block a unique table name (like "btTagDisplay"), an entry for the block ID, and then one more entry for each other value you need to save. Again, looking at other blocks you've purchased or in the /concrete/blocks directory is a helpful start.

Then in controller.php, make sure you rename the class to match your folder name. If you used "tag_display", then it should be called "TagDisplayBlockController", I think. Again, copy from another block that seems easy and straightforward. I think the Image block is pretty basic. Make sure the data table name is right, and make sure you have variables in your controller that match up with the variable names in your database table. Edit the save function to make sure you put these variables back into the database.

Add.php and edit.php, as you can imagine, are each called when you either create a new block or you edit an existing block. This is what pops up in the dialog box. If you had a public variable called $tagName in your controller, you could access it here by using $controller -> tagName

Modify the values as necessary, using the same variable names, and the saving will happen automatically. Again, you might see this pattern when you look at source code for other blocks.

Finally, view.php is called when your block is on a page. Variables like $bID, $b or $controller are available in the code for the block ID, block or your controller. Again you can call $controller -> tagName or other functions from your controller to get it to show up right.
kirkroberts replied on at Permalink Reply
kirkroberts
I'm curious if there is a resolution to this.

My needs are a bit simpler than the original poster's (I think).

I'm just looking to have a list of news items that can be assigned tags/keywords. The list can then be viewed with just the pages that have the particular tag.

The pages are NOT in separate sub-navs. All in one.

But I also wouldn't want to have to create a separate template block for each tag. Perhaps that tag could be passed in a query string?

I'm wondering if there is an easy way to get similar functionality that I'm overlooking.

Thanks!
asmith replied on at Permalink Reply
asmith
Same here. This is exactly what I'm looking to do.
kirkroberts replied on at Permalink Reply
kirkroberts
asmith: I believe there is now a Tags block in the standard c5 install. And a Tags property you can assign to any page (or perhaps in the Page Type defaults). The Tags block can link to a page for search results (I'm guessing). Haven't used it yet, but that's the first place I'd look if trying to accomplish this. Hope that helps!