• getting archives, title, author, and an excerpt separated by category would be nice:
    <¿get_archives (“postbypost”,nposttoshow,$cat=1 )?>
    Cat. 1
    title
    by admin on…
    alalalalal alalalalal alalalalala alal [..more]

    <¿get_archives (“postbypost”,npost,$cat=2 )?>
    and so on..

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Anonymous

    In the last post i was thinking on this hack banzer wrote for b2, it was useful for me,but with the latest renaming of wp files and tables its out of order:
    function preview_posts($the_cat = “1”, $last_char = “0”, $n_posts = “3”, $pr_more = “<b>»</b>más…”, $set_date = “nohour”, $the_file = “b2.php”, $pr_before = “<img src=\”images/arrows.gif\” width=\”8\” height=\”8\” /><b>”, $pr_aftertitle =”</b> <i>”, $pr_afterauthor = “</i> “, $pr_afterdate = “<br><br>”, $pr_after_pr = “<br>”, $pr_ending = “<br><br>”) {
    #this function by Benzer at benzer@arkania.org http://benzer.arkania.org
    global $tableposts, $querycount, $postdata, $authordata, $tableusers;
    if ($the_cat != “”) {$choose_cat = “WHERE post_category=’$the_cat'”;}
    else {$choose_cat = “”;}
    $query=”SELECT * FROM $tableposts $choose_cat ORDER BY post_date DESC LIMIT $n_posts”;
    $result=mysql_query($query);
    $querycount++;
    while($row = mysql_fetch_object($result)) {
    $pr = explode(“
    “, stripslashes($row->post_content),2);
    if ($last_char != 0) {$preview_tx = substr(stripslashes($row->post_content), 0, $last_char);}
    else {$preview_tx = $pr[0];}
    $author_id = $row->post_author;
    $the_author = mysql_query(“SELECT user_nickname FROM $tableusers WHERE ID=’$author_id'”);
    $the_author2 = mysql_fetch_object($the_author);
    if ($set_date == “nohour”) {
    $no_hour = explode(” “,$row->post_date);
    $the_date = $no_hour[0];
    } else {$the_date = $row->post_date;}
    echo $pr_before.stripslashes($row->post_title).$pr_aftertitle.$the_author2->user_nickname.$pr_afterauthor.$the_date.$pr_afterdate.$preview_tx.$pr_after_pr.”ID.”\”>”.$pr_more.”“.$pr_ending;
    }
    }

    Thread Starter Anonymous

    Well, is not a perfect code but it does the trick (i made some modifications from a previous hack for b2) , sure somebody would improve it. add this lines at the end of your template-functions.php file:
    function preview_posts($cat=””, $limit=””, $predate=””) {
    global $tableposts, $tablepost2cat;
    //$post_amount = “post_content AS content”;
    $post_amount = “SUBSTRING(post_content,1,350) AS content”;
    $sql= ” SELECT ID, post_title, DATE_FORMAT(post_date, ‘%d/%m/%y %h:%i’) AS formatted_date, ” .
    ” $post_amount ” .
    ” FROM $tableposts,$tablepost2cat ” .
    ” WHERE ID=$tablepost2cat.post_id and $tablepost2cat.category_id=$cat” .
    ” ORDER BY post_date DESC LIMIT $limit”;
    $result=mysql_query($sql);
    WHILE ($row = mysql_fetch_array($result)) {
    echo($predate.$row[‘formatted_date’].'<h4>| ‘.
    stripslashes($row[‘post_title’]).'</h4>

    ‘.stripslashes($row[‘content’]).'[…]
    …more‘.’
    ‘);
    }
    }
    ,in your template add this code where you want to display posts:
    <?php preview_posts (“catnumber”,”npost”) ; ?>
    , where catnumber=the number of the category you want to select (eg. 1 or 2 .., and npost=the number of posts to be shown: 4, or 3.

    Thread Starter Anonymous

    Sorry, replace above code with this, i missed some lines:
    function preview_posts($cat=””, $limit=””, $predate=””) {
    global $tableposts, $tablepost2cat,$siteurl, $blogfilename;
    //$post_amount = “post_content AS content”;
    $post_amount = “SUBSTRING(post_content,1,350) AS content”;
    $sql= ” SELECT ID, post_title, DATE_FORMAT(post_date, ‘%d/%m/%y %h:%i’) AS formatted_date, ” .
    ” $post_amount ” .
    ” FROM $tableposts,$tablepost2cat ” .
    ” WHERE ID=$tablepost2cat.post_id and $tablepost2cat.category_id=$cat” .
    ” ORDER BY post_date DESC LIMIT $limit”;
    $result=mysql_query($sql);
    WHILE ($row = mysql_fetch_array($result)) {
    echo($predate.$row[‘formatted_date’].’ ‘.
    stripslashes($row[‘post_title’]).’

    ‘.stripslashes($row[‘content’]).'[…]
    …more‘.’
    ‘);
    }
    }

    Thread Starter Anonymous

    certain lines of code are deleted when posted

    Ok I was able to piece together the above code. Anyone interested just send me an email and I’ll send it to you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Last n post by cat’ is closed to new replies.