Welcome to Geeklog, Anonymous Thursday, November 14 2024 @ 10:12 pm EST

Geeklog Forums

Displaying Articles per Section Block


Status: offline

Robin

Forum User
Full Member
Registered: 02/15/02
Posts: 725

I was asked whether it is possible to display stories (titles) from a particular section in a separate block. I ain't no expert in php but I managed to write something like this:

Text Formatted Code
function phpblock_whateveryoucallit()
{
    global $_CONF;
    $siteurl = $_CONF['site_url'];

    $sql = "select sid,tid,title from gl_stories where tid='YourSectionName'";
    $mysql_result = mysql_query($sql);

    while($row = mysql_fetch_row($mysql_result)) {
        $display .= "<a href=$siteurl/article.php?story=$row[0]>$row[2]</a><br>";
    }
    return $display;
}

It works fine however I'm aware the code could be improved. Waiting for your feedback.


Geeklog Polish Support Team
 Quote

Anonymous

Anonymous
I have one problem - I don't know much about php but after installing this the block is appearing with all the articles. I need to decrease this number to some certain number like 5 or 10 newest. Also I want to ask a question how can I put such a block in the other geeked site? ex. news from mycompany.com will be shown on myothercompany.com J.
 Quote

Anonymous

Anonymous
I'm not a SQL expert either, but I think the query goes like this: $sql = "SELECT sid,tid,title,date FROM gl_stories WHERE tid='YourSectionName" ORDER BY date DESC LIMIT 0,4"; This should return only 5 stories ordered with the most current first. If you want more, change the "4" to whatever. You might be able to get the same results sorting on the sid too, but I'm not really sure how that is number generated. The first part is the date but I don't know what the basis is for the remaining numbers.
 Quote

All times are EST. The time is now 10:12 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content