tags:

views:

42

answers:

3

I'm building out a search results page within a blog. I've rewritten the URL so that going to:

/blog/tag/foo

will return a search results for foo.

In the template, I'd like to return a listing of all the posts that are tagged with 'foo', so I've made an MT:Entries block that starts:

<mt:Entries tag="<$mt:SearchString$>">

but it returns no results. However, placing on the page outputs 'foo' just fine.

So I tried this:

<mt:Entries tag="foo">

and it returns all results correctly that are tagged with foo. I'm not seeing a reason why the other one should work -- any ideas?

+1  A: 

You cannot use a tag as a parameter value. You'll have to pass it via a variable, like so:

<mt:setvarblock name="q"><$mt:SearchString$></mt:setvarblock>
<mt:Entries tag="$q">
François Nonnnemacher
While variable interpolation [1] (the method François uses here) should work in most templates, it is not the intended method for looping through tag search results in the Search Results system template. More info in my answer to this question.[1] http://www.movabletype.org/documentation/designer/variable-interpolation.html
Beau Smith
A: 

That's the only way this could be coded! (Francois sample)

However, you need to be careful where are you placing that.

See my feedback to this issue on Movable Type Forums.

Mihai Bocsaru
This should be a comment on François' answer (though I just learned that html is not allowed in StackOverflow comments). <wink>
Beau Smith
+1  A: 

The reason why <mt:Entries tag="foo"> worked is because you are telling Movable Type to explicitly grab the entries tagged "foo". This is how you should do it in most templates, however the Search Results system template is different.

While the example Francois offers should work, it's not the intended method to get "tag search" results in the Search Results system template.

In the Search Results template, instead of the <mt:Entries> block tag use the <mt:SearchResults> block tag.

You code should look something like this:

<mt:SearchResults>
    <mt:IfTagSearch>
        <!-- Template tags for "tag search" results -->
    </mt:IfTagSearch>
    <mt:IfStraightSearch>
        <!-- Template tags for "text search" results -->
    </mt:IfStraightSearch>
</mt:SearchResults>

For a more detailed example, take a look at the code in the default Search Results template in the "Classic Blog" template set (which ships with Movable Type) and modify the working (and tested) code.

Beau Smith