1 (edited by 2008-08-05 23:29:47)

Topic: [HACK] Filter By Letter

Name: Filter By Letter
Author: NyNe
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: If you want to show article that start with a certain letter in the title, author, short story or full story.
Instructions:
open shows.inc.php
find:

$news_arr = explode("|", $news_line);


add below:

// Filter Letter - Start addblock
// To specify filtering, put the following in your include code:
// $filter_letter[X] = Y;
// Where X is a number from 1-4, which mean the following:
//  1 = filter by author
//  2 = filter by title
//  3 = filter by short story
//  4 = filter by long story
// And Y is the character you'd like to filter by.
// ex: $filter_letter[3] = C; will show articles who's short story start with C
if (isset($filter_letter[$arr])) {
$fl = trim($news_arr[$arr]);
$fl = strtolower($fl{0});
$filtered_letter = strtolower($filter_letter[$arr]);
if ($filtered_letter != $fl) { continue; }
}
// Filter Letter - End addblock

NOTE: it's not case sensitive

2 (edited by 2008-08-06 00:02:29)

Re: [HACK] Filter By Letter

Addon By: FUNimations
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: Use a form to make user choose the letter/field they want to filter upon.

add this form to your page.

<?php
$letter = '<select name="letter">';
for($t = 65; $t <= 90; $t++)
    $letter  .= '<option value="'.chr($t).'">'.chr($t).'</option>';
$letter .= '</select>';
$field = '<select name="field">';
$array = array("","author","title","short story", "full story");
for($t = 1; $t <= 4; $t++)
    $field  .= '<option value="'.$t.'">'.$array[$t].'</option>';
$field .= '</select>';
echo '<form action="" method="post">';
echo 'Field: '.$field.'
';
echo 'Letter: '.$letter.'
';
echo '<input type="submit" value="Filter"></form>';
?>


and add the following to your CN include code

if(isset($_POST['letter']))
$filter_letter[$_POST['field']] = $_POST['letter'];