searches and checkbox lists

5 posts by 3 authors in: Forums > CMS Builder
Last Post: January 31, 2012   (RSS)

By rez - April 26, 2011 - edited: April 27, 2011

I have a section editor for projects with a list field called "tags" populated from another editor (checkboxes multi value- values =num, labels=title)

The list viewer page at projects.php shows the tags (labels) for each record just fine with cmsb generator code:

code generator code:
Tags: <?php echo join(', ', getListLabels('projects', 'tags', $record['tags'])); ?><br/>
gives me:
Tags: furniture, interior design, menu board, mural, etc.

for each record. Perfect. (test searches are working: mydomain/projects.php/furniture-1) I would like each of those tags listed to be a search link though. Clicking the furniture tag would list all the projects that have the furniture checkbox filled for instance. How do I make the tag list show as these links? Something like a for each tag
<a href="http://www.mydomain.com/getListvalue"> getListLabel,</a>

so
1. how do I make the tag list into search links for records that match a clicked tag
2. In addition, i'd like to know how to make this same list into a UL list.
3. btw, can the search links show/use labels instead of values somehow in the address bar while keeping values "num"?

Re: [rez] searches and checkbox lists

By Jason - April 27, 2011

Hi,

If you're using a newer version of CMS Builder (2.04 and up) you can make use of the pseudo fields :labels and :values.

What we'll do is first create an array of selected options with the num as the index and the title as the value. After that, we'll loop through the array and output the options in a <ul> list, with each being a link.

For example:

<?php $tags = array_combine($record['tags:values'], $record['tags:labels']); ?>

<ul>
<?php foreach ($tags as $value => $label): ?>
<li><a href="http://www.mydomain.com/tags=<?php echo $value;?>"<?php echo $label; ?></li>
<?php endforeach ?>
</ul>


Note that in this example, each link has tags= in it. This is because to do an automatic search, you need to have the name of the field appear in the url.

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] searches and checkbox lists

By rez - April 28, 2011 - edited: April 28, 2011

Will google crawl these links? I see this mentioned in the documentation but it looks like the = cant be used? I tested the / situation out on my server and it works.

I'm confused though, how do i make these links in your instructions seo friendly? (I want to use all of this to build my main site navigation as well in a category menu)

Re: [rez] searches and checkbox lists

By Jason - April 28, 2011

Hi,

Yes, Google shouldn't have any trouble crawling these links. If you want to set it up to use / instead of = you could try this:

<?php $tags = array_combine($record['tags:values'], $record['tags:labels']); ?>

<ul>
<?php foreach ($tags as $value => $label): ?>
<li><a href="http://www.mydomain.com/tags/<?php echo $value;?>"<?php echo $label; ?></li>
<?php endforeach ?>
</ul>


If your server is configured correctly, this should be the same as tags=value.

Give that a try and let me know if you run into any issues.
Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/