• With almost 300 movie reviews on our website now we’re running into trouble. I’ve use a simple “cat=” switch to generate a page with all the reviewed titles. That list is getting way too long.
    What I’d like is for a way to call all entries within a category, starting with a specific letter. That way I could have a clickable alphabet at the top of the page that call a nice short page with all titles starting with the clicked letter.
    Does anybody know whether the search functionality can be made to look for starting letters? Or is there a plugin that will do this? If not, I’ll try and do a plugin, but I’m not really a SQL wizard… only so-so in PHP as well…

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter weefselkweekje

    (@weefselkweekje)

    Thanks, I’ll have a look at that.

    Thread Starter weefselkweekje

    (@weefselkweekje)

    I had a try at the PHP and it now works nicely. I’m using the following code:

    <ul class="alphabet">
    <?php
    // build menu
    echo "

    • #
    • ";
      $tempstr = "abcdefghijklmnopqrstuvwxyz";
      for( $i = 0; $i < strlen($tempstr); $i++ ){
      $l = substr( $tempstr, $i, 1);
      echo "

    • ".$l."
    • ";
      }
      echo "

    • all
    • ";
      ?>

      <ul class="contentlisting">
      <?php
      // get current selection
      global $wpdb, $tableposts, $tablepost2cat;
      $letter = $_GET['letter'];
      if( $letter == '0' ){
      $query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE left( post_title, 1 ) BETWEEN '0' AND '9' AND (post_id = ID AND category_id = '2') ORDER BY post_title ASC";
      } elseif( $letter == 'all' ) {
      $query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE post_id = ID AND category_id = '2' ORDER BY post_title ASC";
      } else {
      $query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE ( left( post_title, 1 ) = '".$letter."' OR left( post_title, 5 ) = 'the ".$letter."') AND (post_id = ID AND category_id = '2') ORDER BY post_title ASC";
      }
      $results = $wpdb->get_results( $query );
      // display selection
      if ($results) {
      foreach ($results as $result) {
      echo "

    • ID."'>".stripslashes($result->post_title)."
    • ";
      }
      } else {
      echo '

    • No articles found
    • .';
      }
      ?>


      If anyone wants to convert this into a nice plugin, be my guest ??
      Have a look at it here.

    Where did you plug that code into? into the narchives.php page or your index pages? I’m lost..

    Thread Starter weefselkweekje

    (@weefselkweekje)

    Sorry I didn’t check back on this thread before. The code is in the index.php, but I have switch that tells the page what type of layout I want. If the URL has “action=archives”, I do a PHP include to insert this code into the posts-loop. For other page types I have other code bits to include.
    Actually, having page types could be a WP feature…

    This is worth a bump. I just put this to work and it’s brilliant. I don’t completely understand the MySQL stuff (I’m a PHP newb), but I did hack this code a bit so that the category is automatically pulled from url. I figured the code might be worth a repost since it’s a little mangled up above anyway (this may take two posts — I’m still new at posting code myself):

    <ol class="alphabet">
    <?php
    $tempstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for ( $i = 0; $i < strlen ( $tempstr ); $i++ ) {
    $l = substr ( $tempstr, $i, 1 );
    echo "<li";
    if ( $_GET['letter'] == $l ) { echo " class="active""; }
    echo "><a href="index.php?cat=".$_GET['cat']."&letter=".$l."">".$l."</a></li>";
    } ?>
    </ol>

    <div class="someclass">
    <ul class="letter">
    <?php
    global $wpdb, $tableposts, $tablepost2cat;
    $letter = $_GET['letter'];
    $category = $_GET['cat'];
    if( $letter == '0' ) {
    $query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE left( post_title, 1 ) BETWEEN '0' AND '9' AND (post_id = ID AND category_id = '".$category."') ORDER BY post_title ASC";
    } elseif( $letter == 'all' ) {
    $query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE post_id = ID AND category_id = '".$category."' ORDER BY post_title ASC";
    } else {
    $query = "SELECT post_title, ID FROM $tableposts, $tablepost2cat WHERE ( left( post_title, 1 ) = '".$letter."' OR left( post_title, 5 ) = 'the ".$letter."') AND (post_id = ID AND category_id = '".$category."' ) ORDER BY post_title ASC";
    }
    $results = $wpdb->get_results ( $query );
    // display selection
    if ($results) {
    foreach ($results as $result) {
    echo "<li><a href="#">".stripslashes($result->post_title)."</a></li>";
    }
    } else {
    echo 'No articles found.';
    } ?>
    </ul>
    </div>

    I’m a total newb, although I did manage to get a lot of the stuff I want working, as much as I tried I cannot get this one to work. I searched all over the internet, and this is exactly what I want, but I can’t get it to work!!! Could somebody pls help? Exactly where in the index page I should insert the above code? Wherever I inserted it, the page shows up blank!
    Thanks..

    Sorry, but in which file do I have to insert those code snippets?

    Thanks,
    /Frank

    To anyone in need of an alphabet-based post navigation menu, I have transformed this code into a plugin.

    https://www.nateomedia.com/wordpress/wp-snap

    Scott

    (@scottwblack)

    Like weefselkweekje, I have a movie review site and want to implement this on my WordPress 1.5 weblog. I’m a total PHP newb, though, and can’t figure out where to insert the aforementioned code. I’d like my archive page to look exactly like the one on the Choking on Popcorn site. Any thoughts? Suggestions?

    Use my plugin? The only difference between it and Choking on Popcorn is that it has an “all” and “#” category — and I’ve already noted to put something like that in the next version.

    Try my plugin and, if you cannot figure out how to get it to work, leave a comment on my web page noting the specific steps that you performed and I’ll help you get it to work.

    Scott

    (@scottwblack)

    Thanks.

    I would love to use your plugin, but unfortunately I am still using WordPress 1.5. Guess I should just attempt to upgrade and hope I don’t mess things up.

    Give the plugin a shot in 1.5. It might work. I just haven’t tested it in that environment. But there’s nothing that the plugin could really do to damage your database or anything — either it will work or it won’t.

    If you just want to sort posts in category view by title rather than by date, then here’s a quick and easy way to do that:

    https://www.mikesmullin.com/2006/05/23/wordpress-plugin-sort-category-posts-by-title/

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Quick way to do alphabetical category archive?’ is closed to new replies.