Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2009-04-14 00:57:31
- Agogo
- Member
- From: Sthlm, Sweden
- Registered: 2008-11-27
- Posts: 31
chh_article and search_result_count
Eels, you there? ;)
Im doing a wierd as search with restrictions to sections and categories and “the devil and his aunt” (Swedish expression).
Using <txp:article pgonly="1" />
before the <txp:search_result_count />
works, of course – but displays the wrong result count.
I need to use the <txp:chh_article />@ to be able to display search results in certain sections:
<txp:php>
echo chh_article(
array(
'limit'=>"20",
'searchall'=>"none",
'form'=>"search_results",
'sort'=>$sort,
'section'=>$section,
)
);
</txp:php>
<txp:search_result_count />
That snippet inside the <txp:php>
tags does work dandy for showing the result (Ive left some php out of here that constructs the variables since its not relevant). But it doesnt work with <txp:search_result_count />
. It doesnt display anything, actually. No figures, no nothing.
Any ideas?
Offline
Re: chh_article and search_result_count
You could for example use <txp:variable />
to count the articles.
Above your article search listing place <txp:variable name="count" value="0" />
which sets the first counted item to it starting number (zero).
After that place to your article form (search_results) the actual counting:
<txp:variable name="count" value='<txp:php> echo variable(array("name" => "count"))+1; </txp:php>' />
And after listing you can count the sum with <txp:variable name="count" />
.
If you want to display the count before your chh_article
call, you need to seperate call, where the other handles the counting before the listing, but uses empty form
, and so, doesn’t output anything.
Offline
#3 2009-04-14 10:13:20
- Agogo
- Member
- From: Sthlm, Sweden
- Registered: 2008-11-27
- Posts: 31
Re: chh_article and search_result_count
Thanks Gocom!
That is one way of doing it.
I might have tried it earlier my self but, as you say, I need the count before the result and it just feels over kill and kinda wrong to count the output manually. =)
And btw, my code should work!
Offline
Re: chh_article and search_result_count
Agogo wrote:
I might have tried it earlier my self but, as you say, I need the count before the result and it just feels over kill and kinda wrong to count the output manually. =)
You always have to count things twice if you want to output the count before the listings, even with core tags. As <txp:article pgonly="1" />
does count the articles. That is basically because the number is before the actual query so it can not know the count.
So it kinda isn’t overkill. Ofcourse core tags are faster than that chh_article
method, but the “way” is similiar. You can ofcourse make those ways indentical by making the count SQL only. For example <txp:php> echo safe_count('textpattern',/* And your wanted Search query copied from chh_article */); </txp:php>
etc.
Last edited by Gocom (2009-04-14 10:34:39)
Offline
Re: chh_article and search_result_count
Gocom wrote:
You can ofcourse make those ways indentical by making the count SQL only
… and as a followup, if you’re doing that you may consider smd_query / smd_if as an option. If you design your query correctly you can do this kind of thing:
<txp:smd_query query="my clever SQL goes here">
<txp:smd_if field="{smd_thisrow}" operator="eq" value="1">
Number of results: {smd_rows}
</txp:smd_if>
// Output row info here
</txp:smd_query>
Last edited by Bloke (2009-04-14 10:45:50)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#6 2009-04-14 10:49:20
- Agogo
- Member
- From: Sthlm, Sweden
- Registered: 2008-11-27
- Posts: 31
Re: chh_article and search_result_count
Gocom and Bloke – youve both got nice solutions! Thanks!
And theyll be great for anyone else that has got simliar problems or enquiries.
Its just that the site isnt mine and for someone else to take over admin the (almost) default counter would be easier to interpret.
And for the record Im stuborn so I want to make my way work :)
Offline
#7 2009-10-02 14:11:43
- Agogo
- Member
- From: Sthlm, Sweden
- Registered: 2008-11-27
- Posts: 31
Re: chh_article and search_result_count
Well. It seems there is a problem with chh_article and that problem is it hasnt been updated with Txp. There were one variable missing in the chh_article code: $grand_total.
The count never got any numbers from chh_article so its not strange it didnt show any…
Offline
Pages: 1