Forum
Outputting A-Z results
Hi there
I have a directory of businesses, using the Blogs app: https://lovebedfordbusinesses.co.uk/businesses/
Outputting them by category is fine: https://lovebedfordbusinesses.co.uk/businesses/archive.php?cat=fashion
What I'm trying to do is output by A-Z.
Am I going about this completely the wrong way? In archive.php I have the following...
/* --------------------------- POSTS BY A-Z --------------------------- */
if (perch_get('company')) {
echo '<h1 class="archive">Businesses beginning with '.perch_blog_category(perch_get('company'), true).' in Bedford</h1>';
perch_blog_custom(array(
'filter'=>substr('postTitle', 0,1),
'match'=>'eq',
'value'=>perch_get('company'),
'template' => $template,
'count' => $posts_per_page,
'sort' => $sort_by,
'sort-order' => $sort_order,
));
$posts_displayed = true;
}
Thanks for help in advance.
Rich
That looks fine, presuming that
$sort_by
is the ID of a field in your template$sort_order
isASC
.This is my full code, however it doesn't seem to be working, sorry.
https://lovebedfordbusinesses.co.uk/businesses/archive.php?company=p
is the page in question... or =a or =b etc.
Ah, ok, I misunderstood - you're trying to filter items by the first character, is that right?
Yes that's right. I plan to have A, B, C etc. etc. Z as clickable links which when clicked on output all businesses beginning with the letter 'A' or 'B' etc.
Try:
Have tried that. No luck I'm afraid.
Page: https://lovebedfordbusinesses.co.uk/businesses/archive.php?company=a
If you turn on debug, what does it output?
https://docs.grabaperch.com/docs/installing-perch/configuration/debug/
https://lovebedfordbusinesses.co.uk/businesses/archive.php?company=a
Here it is Drew
Oh, I think it's the filter option. It should be the field ID that contains the company name (postTitle?)
This should find any postTitle that falls between, for example, A and AZ. That should be anything that begins with A.
Thanks a lot Drew, got it working... https://lovebedfordbusinesses.co.uk/businesses/archive.php?company=b
Just one last thing I can't figure out, the 'Businesses beginning with X in Bedford', obviously the X isn't working - I'm guessing because it's perch_blog_category, what should it be here?
Thanks
Wouldn't that just be the letter you're filtering by?
Hi Drew
Sorry, I'm getting an error on the page: https://lovebedfordbusinesses.co.uk/businesses/archive.php?company=b
Using the following...
What is on line 48?
Line 48 is: echo '<h1 class="archive">Businesses beginning with '.PerchUtil::html(strtoupper(perch_get('company'), true))).' in Bedford</h1>';
edit The error message is: Parse error: syntax error, unexpected ')', expecting ',' or ';' in /var/sites/l/lovebedfordbusinesses.co.uk/public_html/businesses/archive.php on line 48
Just need to fix the typo: