Help - Search - Members - Calendar
Full Version: A-Z Search Feature
Movable Type Community Forum > Additional Resources > Tips and Tricks
element059
Hello,

I have been using MT for about six months now for posting reviews, previews and various articles on my site. I even use it to post screenshots. But it has come to the point where the index page is filling up so much I am not sure if this script is right for what I need it for.

Is MT intended to be for review sites?

I basically needed the index page (where is shows the entries) to be split over various pages (i.e. pages: 1, 2, 3, 4, 5).

I also needed it to have some form of alphabetical listing on the main page so that people can click on letter's A- Z and get the entry's under that particular letter.

Are there any add-ons that can do this? Or will I need to change to another script? If so do you know of any?

Many thanks,

- Laurence
element059
Think I previously posted this in wrong forum.

EDITED by moderator: Topics merged. Don't worry about repeating posts if you think you got the wrong forum - we can just move 'em. wink.gif
charle97
use the mtpaginate plugin
element059
Thank you! Is there one for A-Z listing?
trialanderror
I believe you can use MT for whatever purpose you desire. The usefulness all depends on how you manage your entries. That being said...

If you need to break-up long articles or an index template page, you may want to consider the MTPaginate plugin. Or if you want to "shorten" your content and provide a "more" link MTBloxpert might be suited to your requirements.

As far as alphabetical listings, there is an example in the mtmanual that describes how to do what you want. However, you may want to consider custom sorting and use MTCollate.

hope this helps

t&e
element059
Thanks trial,

However when using an A-Z system the MTCollate simply arranges in A-Z order.

If I would want to create a cheat database for example I would need a system that would list the letter's A- Z so the user can select a letter and get a selection of results under that particular letter. So the letter S would bring up all entry's containing S in the first letter of the title.

I don't see how this is possible with MT and havnt found any other script to do this! Any good script anyway smile.gif
trialanderror
I am only suggesting this. Its a workaround or enhancement (just depends on your point of view). Instead of relying on one of the sort fields that MT allows you to use.

1. Create your own sort field with MTKeyValues. I did a mini test and it will work. Search on MTCollate and MTKeyValues (you will find my post).

I chose to use MTEntryKeywords as my place for KeyValues. (Reasons, I took a brief look at RSS and I don't think this field is included-I just don't remember right now).

Specify KeyValues something like this.

sortbyme=SA

in another entry

sortbyme=SB

etc...

Your own cataloging system is what you put after the equal sign.

So what you create is your own cataloging system and can adjust sort order as you would like.

You would then collatecollect from all entries or by category then produce your index listing.

t&e
-lc-
I asked Stepan (Riha) the MTpaginate creator, if he could impliment A-Z ability a month or so ago but no word so far sad.gif I wanted to use it to organize a book/magazine listing by author/title.

It occurs to me that we could take the number listing and do a search/replace on the numbers into letters using javascript or php, but it would be a little clunky if there were alot of pages involved to repeat all the code.
kadyellebee
I use PHP for something like this on TheRedKitchen. See the Alphabetical Archives - you can click on a letter, and only the recipes starting with that letter will appear. Is that what you are trying to do?

If PHP is an option for you, I'll dig up some info for you - seems like I wrote up a tutorial on how to do this at one point, but I can't find it on the normal places I would save it! If I can't find it, I'll put the code together again.

Kristine
-lc-
kadyellebee, that is a sweet looking interface (so are some of those recipies! smile.gif ) and just what I was looking for... would love to see the php code to do that... thanxs for all your great work (and sharing!)

ooh... on deeper examination, it appears that the way you are doing this is by listing ALL of the entries and then using php to insert HTML comments to "comment out" the non-relavant entries? Is that correct? That could be a problem if there were hundreds or imagine thousands of entries... the entire page would have to be loaded over and over... the redkitchen page alone is already at 200k! - I am pondering some hacks to that idea to make that work with a lesser load for dial-up folks... still would love to see your PHP code, I love to hack at things like that tongue.gif

ps. even without a hack, that page could benefit from the relative URL MT plugin wink.gif - could shave like 20k off the page size
crys
Actually it looks like she has a couple of older versions of the sidebar still in the code but commented out.
girlie
This is the code I got from Kristine when she first put that together (here on the forum somewhere, I think?):

CODE
<?
$titles = array(<MTGlueContainer><MTEntries lastn="800">'<$MTEntryTitle encode_php="q">'<MTGlue>, </MTGlue></MTEntries></MTGlueContainer>);
$links = array(<MTGlueContainer><MTEntries lastn="800">'<$MTEntryLink encode_php="1">'<MTGlue>, </MTGlue></MTEntries></MTGlueContainer>);

//sorts the titles and links but lets them keep the same value
array_multisort($titles, $links);
$count = count($titles)-1;

//find all of the first letters used in the $titles array
for ($i = 0; $i <= $count; $i++) {
 $letters[$i]=substr($titles[$i], 0, 1);
}

//create the links to each unique letter on the top of the pages.
$letterarray = array_values(array_unique($letters));
foreach ($letterarray as $l) {
  echo " <a href=\"?letter=", $l, "\">", $l, "</a>  ";
}

echo "<br>\n\r";

//print the titles differently if they match the last letter or not.
for ($t=0; $t <= $count; $t++) {
  if (substr($titles[$t-1],0,1) == substr($titles[$t],0,1)) {
      if ($_GET['letter'] == substr($titles[$t],0,1)) {
         echo "<a href=\"", $links[$t], "\">", $titles[$t], "</a><br>\n\r";
      }
  }
  else {
      if ($_GET['letter'] == substr($titles[$t],0,1)) {
         echo "<a href=\"", $links[$t], "\">", $titles[$t], "</a><br>";
      }
  }
}
?>


(I haven't looked at her current code to compare for changes, that's just what it started out as.)
-lc-
Oh I see what that is doing. And the comment issue must be some left over debugging or something.
(Someone should fix that though on the redkitchen site, 200k pages aren't very dialup friendly)

I might try to come up with a perl flavah of that, to write prepared archive files so its less cpu intensive for many hundreds of entries (for a non-profit library) with many people on the site.

Thanks for sharing the code! biggrin.gif
kadyellebee
I did go in this afternoon and clean up some of the code that had been commented out - thanks for the heads up on that, Crys!

I checked the that page, and it wasn't anywhere near 200K, but it does vary between which letter you have picked.

Girlie posted the correct code - the only thing I have different in my current version is that I set it up to use full URLs - the site has multiple pointers to it, and it was much less hastle to have the full URL than deal with which subdomain people came to the site on! smile.gif And then I added an array for each of the author, date, and category to make them display as well. Its the same as the current code, just with the correct MT tags in each array. smile.gif

Hope that helped, guys,
Kristine
element059
Hi kadyellebee,

Sorry for the late reply I thought you guys would take a while to get back to me so I havnt checked the forum all of today. But yes that is exactly what I wanted to do on my site? Did you say I should use the bit of code posted by girlie?

Where does that need to be implemented to?

I am guessing just the index pages smile.gif but anywhere specific in the page and what needs to be overwritten?

Many thanks for all your help!
element059
Hmm hello biggrin.gif?
element059
Hello,

I recently asked a question about how to show an A-Z search feature on my site using MT.

I got a reply from a couple of people but no one got back to me with the code to implement into my site and how to do it.

It was this that I wanted to do:
http://theredkitchen.net/alpha.php

Could someone please get back to me.

Thank you,

- Laurence
maddy
Topics merged. Please read these guidelines for getting the help you want from us volunteers. smile.gif
element059
*bump*
kadyellebee
Like the link that Maddy posted said, all of us are volunteers here. Sometimes, you'll notice that one of us isn't around on a certain day, and its probably because another project has kept us busy, and/or "real life" is happening. I have had a bad cold this week, and have been trying to recover, and then spent the day with my family, so this is the first real time I've been back since my last post to you.

The code that Girlie posted was correct, and should work as is. Have you tried it and had problems or just were unsure of what to do? Do you want this on a separate page of your site like TheRedKitchen has? If so, here's the basic steps:

1. Create a new index template named Master Alphabetical Archives. Set the output file to alpha.php
2. Paste the code from Girlie above.
3. Click Save and Rebuild, and you should be good to go. smile.gif

If you have more than 800 entries, you'll want to change the first 2 lines ($titles and $links) to reflect that.

Post back if you have more questions.

Kristine
element059
Hey there kadyellebee,

Sorry I know I was a bit pushy to try and find out how to do it I was just rly excited at the fact it was possible and someone knew how to do it smile.gif

I should kno all too well about dealing with ppl in forums also as I do that alot on my site smile.gif

In response to your question I was wanting to have it on the index page rly.

I did what you said and copied and pasted that bit of code but im getting an error:

Parse error: parse error, expecting `')''

Maybe she didnt copy the full code.

I am a bit clueless when it comes to coding I do graphics more than anything else so plz forgive me smile.gif

Thanks again,

- Laurence
kadyellebee
I just tested it and it worked fine here without a parse error, but I bet that you need to install the Glue plugin; I've already got it, and didn't think about mentioning it until I looked over the code again.

If that doesn't do it, then maybe set up a test template with only that code in it so you can find out which line the error is coming from.

Its 2:25 here, so I'm going to bed, but I'll be around tomorrow. smile.gif

Kristine
element059
Thanks kadyellebee (long name smile.gif

I will try that out.. It's 10:28AM here and I havnt been to sleep. I live in England, London btw.
element059
Thank you kadyellebee it now works fine!

But do you have any idea how to create a top 10 list of the most recent entry's on the same page?

Thanks again!
element059
*bump*
kadyellebee
Good, I'm glad you got it to work.

As for a top 10 list, do you want to show the 10 most recent entries (the default templates have this already)? Or the top 10 determined by something else?

Kristine
element059
Hey,

I wanted to show the top 10 most recent entry's but on the same page as the A-Z search feature.

- Laurence
kadyellebee
Have you tried the code that is in the default templates to see if it does what you are looking for? Its on the sidebar under "Recent Entries".

Kristine
element059
Yes thank you that worked smile.gif

I notice on your site with the A - Z thing it doesnt rly have much visual customization is it possible to put things like [ ] in between the words so they look something like this:

[a] [b] [c] [d] [e]

I dunno if I would rly want it but im just wondering.

That's my last question honest biggrin.gif
kadyellebee
Play with the echo statements in the code - that's where other formatting can be added. Just note that if you have a quotation mark that you want to enter, you may need to escape it so it will display properly... if you get a parse error, that's something to watch for. smile.gif

Kristine
mookie
Hi.

Sorry to resurrect an old topic, but I have set this up for my blog. The only problem I have is setting the preferences so the file paths are correct. Although the page displays correctly as index.php, when I try and modify the paths to show this page as default via 'View Site' it gives me various build errors. Should I just leave the paths as they are and manually navigate to the page to check it, or am I missing something?

Thanx.

p.s Is there anyway to get the array to display the whole alphabet? At the moment it only gives an alphabetical index comprising the first letters of the entries I have at the moment (ie D, F, T, V, and W).
kadyellebee
Well, your Site Path and Site URL should point to the same place - and that's where the View Site is getting its info from. Are your archive links working okay?

Kristine
mookie
Yeah everything was fine just the 'view site' button pointed to the wrong page and when i altered the path to /index.php (would it pick up index.php by default?) it generated all sorts of errors.

After looking at that lovely looking recipe page, I've decided to merely use the php alphabetical index as one of several potential options as it seems the best, most flexible way to go.

Thanks.
wondergirlmj
Is there anyway to limit this code to include only a particular category? Basically I want to have the alphabetical listing like this on the archive pages for two different categories.
girlie
You can add the category attribute to the MTEntries tag if you use this in an Index Template.

To only use it in the Category Archive Template for certain categories, you'd need to set up some Per Category Templates or else all your Category Archives would use the alpha code.
wondergirlmj
Thanks girlie. Yeah I've got the category tag included and it's now showing the proper information (that is the letters from the proper category) however when the page loads I'm getting an error in addition to the proper display of information.

The error:
CODE
Warning: Array sizes are inconsistent in /home/virtual/site103/fst/var/www/html/alpha.php on line 6


I'm quite new to PHP so I have no idea what that means. It didn't have that error before I limited it by category so I'm not sure what to do here.
girlie
Are you still using a lastn in there? Maybe that's causing the problem? huh.gif
TweezerMan
Not knowing squat about php, this is what I would be looking at:

Line 6 of the code girlie provided is this:

CODE
array_multisort($titles, $links);

The error message ("Warning: Array sizes are inconsistent...") indicates to me that the $titles array (list of entry titles) and the $links array (list of entry links) do not have the same number of elements (the lists are not the same length). For example, your code could be producing 80 entry titles and 82 entry links.

There is an MTEntries container in both line 2 (the entry titles array) and line 3 (the entry links array). The MTEntries container tag in each line should be identical, but I think something about them is not the same:

CODE
$titles = array(<MTGlueContainer><MTEntries lastn="800">'...
$links  = array(<MTGlueContainer><MTEntries lastn="800">'...

wondergirlmj said this error started showing up after the "category tag" was included. Are both MTEntries container tags still identical?

Just my 2 cents...
mediagirl
I'm interested in implementing an A-Z listing of my "company" subcategory on my site.

The code example shown in this thread shows the A-Z listing for entries but can it be changed to work for listing a subcategory?
trailblaza
i have a quick question... i've gotten this working on my site, but i have one problem...

i've used the code as it was given, but it doesn't show anything on the initial page like it does on http://theredkitchen.net/alpha.php

is there any extra code that i need to add for it to automatically show all the "A" entries as a default when you first go to the page???

lj.
trailblaza
nevermind... found the current code here...

http://www.virtualvenus.org/archives/0402/...s_by_letter.php

lj.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.