TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 452
  • Total: 452

Recent Articles For Center Block

Started by opschf, March 13, 2006, 03:48:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

warhonowicz

I've just found this and thought it would be what I want ... however

I use this code


$articles=db_query("SELECT id,subject FROM smf_tp_articles WHERE approved=1 AND off=0 ORDER BY date DESC", __FILE__, __LINE__);
$cnt=0;
While ($row=mysql_fetch_row($articles)) {
   // The number of articles you want displayed
   if ($cnt < 3) {
          echo '<a href="http://www.addedo.com/forum/index.php?page=' . $row[0] . '">' . $row[1] . '</a><br /><br />';
    }
   $cnt++;
}
If  ($cnt=0) {
echo '<td>No Artcles to review.  Please submit articles.';
}


and it does display three entries with the latest article names. However, they are all links back to the forum index.

I tried to set $cnt to 3 but then it simply does not display anything.

What am I doing wrong?

G6Cad

Why not just take a cup of tea, relax, lean back in your chair, and go back in this threads first post and read everything from the start again. The answer is there

IchBin

If you don't find your answer then post a link so we can see it in action on your site.

alhaudhie

with this code, how can i include article intro below the title of the article?..
global $db_prefix, $scripturl;

$articles = db_query("
        SELECT art.date, art.author, art.subject, art.id, var.value1 AS category_name
        FROM {$db_prefix}tp_articles AS art
                LEFT JOIN {$db_prefix}tp_variables AS var ON (var.id = art.category)
      ORDER BY date DESC LIMIT 5", __FILE__,__LINE__);


echo '
<div align="center">
      <center>

<table cellpadding="0" cellspacing="0" border="0" width="519" style="border-collapse: collapse" bordercolor="#111111">
<tr valign="top">
<td bgcolor="#101018" colspan="4">
    <img src="http://www.othersi.com/Themes/default/assets/images/header-reviewpost.jpg" alt="Review Post" width="519" height="24"></td></tr>

<tr valign="top">
<td class="lineleft2">
    <img src="http://www.othersi.com/Themes/default/assets/images/spacer.gif" alt="spacer" width="11" height="1"></td>
<td class="mainbg">
    <img src="http://www.othersi.com/Themes/default/assets/images/spacer.gif" alt="spacer" width="386" height="12"><br>

<img src="http://www.othersi.com/Themes/default/assets/images/title-newestreviews.gif" alt="Newest Reviews" width="390" height="22" align="left"><br><br>


<div align="left">
The 5 most recent reviews are listed below. For our complete listing of reviews,
please visit the <a href="http://www.othersi.com/index.php?cat=15">Review archives</a>.</p>

        <table cellpadding="2" cellspacing="0" border="0">
        <tr valign="top">
        <td width=100%>
        <img src="http://www.othersi.com/Themes/default/assets/images/post-title.gif" alt="Title" width="190" height="13"></td>
        <td>
        <img src="http://www.othersi.com/Themes/default/assets/images/post-date.gif" alt="Date" width="54" height="13"></td>
<td>
    <img src="http://www.othersi.com/Themes/default/assets/images/post-format.gif" alt="Format" width="89" height="13"></td></tr>';


if (mysql_fetch_assoc($articles) == 0)
        echo '
<tr>
<td><b>No Reviews Available</b></td>
</tr>';

else
{
        while ($row = mysql_fetch_assoc($articles))
                echo '

                   <tr>
                          <td>
<a href="', $scripturl ,'?page=', $row['id'], '"><b>', $row['subject'], '</b></a></td>
         <td> ', date("m/d/y", $row['date']), '</td>
<td align="right">', $row ['category_name'], '</td>
</tr>';

}

echo '
</table>

<img src="http://www.othersi.com/Themes/default/assets/images/spacer.gif" alt="spacer" width="1" height="10"><br></td>
       
<td class="mainbg">
        <img src="http://www.othersi.com/Themes/default/assets/images/spacer.gif" alt="spacer" width="10" height="1"></td>
        <td class="linerightm">
        <img src="http://www.othersi.com/Themes/default/assets/images/spacer.gif" alt="spacer" width="3" height="1"></td></tr>

        <tr valign="top">
        <td colspan="4">
        <img src="http://www.othersi.com/Themes/default/assets/images/footer-home.gif" alt="spacer" width="100%" height="3"></td></tr>
        </table>

        </center>
</div>';



mysql_free_result($articles);

bigdog

I wish to do the same.  Add the intro below the title/author display.  Perhaps even specify how many words/characters of the article to display.

bigdog

we've modified one of the earlier codes in this thread.  got the block to look like this:

http://img167.imageshack.us/img167/7294/picture1qd4.png

$articles=db_query("SELECT id,subject,intro,author,category,date FROM smf_tp_articles WHERE approved=1 AND off=0 ORDER BY date DESC", __FILE__,__LINE__);
$cnt=0;
While ($row=mysql_fetch_row($articles))

{
   // The number of articles you want displayed
   if ($cnt < 8) {
    echo '<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px;
             margin-bottom: 4px;" border="0" class="tborder"><tr>';
    echo '
    <a href="http://www.texasteamplayers.com/index.php?page=' . $row[0] . '"><b>' . $row[1] . '</b></a> <font size="1"><em>by <b>' . $row[3] . '</b></em> on ' . date( "m/d/y", $row[5] ) . '</font></div>
<font size="1">' . $row[2] . '</font>
     </td>';
     echo '</tr></table>';
    }
   $cnt++;
}
If  ($cnt=0) {
    echo '<td>No Articles Available';
    }


What we'd like to do is add the category.   Category is being selected as row 4, and date as row 5 (and we formatted the date to look d/m/year).  Problem is, category is displayed as the category ID# and not as the category name.

what is the call for category name?

As well, what is the call for a user/author's ID number, so their name can be linked to their profile?

bigdog

it would also be nice to perhaps put in some sort of restriction as to which categories can be called into the block.  Some articles we use for "contact us" or "driver update" flash pages.  Not actual article-articles.  If there was a way to say show recent artcles from category 2, 3, 5, 6, etc....that would be good.

bigdog

we've done some more.  Article category is now displayed, and the article author's name now links to their profile.

$max_shown=10;
$articles=db_query("SELECT a.id,a.subject,a.intro,a.author,a.authorid,a.date,c.value1 as category,a.category as category_id FROM smf_tp_articles a inner join smf_tp_variables c on a.category = c.id WHERE approved=1 AND off=0 ORDER BY date DESC LIMIT " . $max_shown, __FILE__,__LINE__);
$cnt=0;

While ($row=mysql_fetch_row($articles))
{
    echo '<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px;
             margin-bottom: 4px;" border="0"><tr><td>';
    echo '
    <li><a href="http://www.texasteamplayers.com/index.php?cat=' . $row[7] . '"><b>[' . $row[6] . ']</b></a> <a href="http://www.texasteamplayers.com/index.php?page=' . $row[0] . '"><b>' . $row[1] . '</b></a> <font size="1"><em>by <a href="http://www.texasteamplayers.com/index.php?action=profile;u=' . $row[4] . '"><b>' . $row[3] . '</b></a></em> on ' . date( "m/d/y", $row[5] ) . '</font></div>
<font size="1">' . $row[2] . '</font></li><br><br>
     </td>';
     echo '</tr></table>';
   $cnt++;
}
If  ($cnt=0) {
    echo '<td>No Articles Available';
    }


see it as the homepage block on www.texasteamplayers.com

fussilet

$articles=db_query("SELECT id,subject,intro,author FROM smf_tp_articles WHERE approved=1 AND off=0 ORDER BY date DESC", __FILE__,__LINE__);
$cnt=0;
While ($row=mysql_fetch_row($articles))

{
   // The number of articles you want displayed
   if ($cnt < 5) {
         echo '<div style="padding: 1px;" class="smalltext"><p style="margin: 0; padding: 0 0 0 0;">';
    echo '
    <a href="http://www.fussilet.com/forum//index.php?dummy=1;page=' . $row[0] . '"><img src="'.$settings['images_url'].'/tpgoto.gif" alt="" border="0" style="margin:0 2px 0 0;" /> ' . $row[1] . '</a>

';
     echo '</p></div>';
    }
   $cnt++;
}
If  ($cnt=0) {
    echo '<td>No Reviews Available';
    }

bigdog

here's our final version, pretty much.

shows image category icon, article title in a larger font, and bolded, the author, with their name linked to their profile, and the date of posting.  Also shows the article introduction.

$max_shown=5;
$articles=db_query("SELECT a.id,a.subject,a.intro,a.author,a.authorid,a.date,c.value1 as category,a.category as category_id, IF(length(c.value4) > 0,c.value4,'http://www.texasteamplayers.com/misc/images/newspaper.png') as category_img FROM smf_tp_articles a inner join smf_tp_variables c on a.category = c.id WHERE approved=1 AND off=0 ORDER BY date DESC LIMIT " . $max_shown, __FILE__,__LINE__);
$cnt=0;

While ($row=mysql_fetch_row($articles))
{
    echo '<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px;
             margin-bottom: 4px;" border="0"><tr><td>';
    echo '
    <p><a href="http://www.texasteamplayers.com/index.php?cat=' . $row[7] . '"><img src="' . $row[8] . '" align="left" hspace="5"></a> <a href="http://www.texasteamplayers.com/index.php?page=' . $row[0] . '"><b><font size="4">' . $row[1] . '</font></b></a> <font size="1"><em>by <a href="http://www.texasteamplayers.com/index.php?action=profile;u=' . $row[4] . '"><b>' . $row[3] . '</b></a> on ' . date( "m/d/y", $row[5] ) . '</em></font></div>
<font size="1">' . $row[2] . '</font>
     </p></td>';
     echo '</tr></table>';
   $cnt++;
}
If  ($cnt=0) {
    echo '<td>No Articles Available';
    }


see it in action as the first center block on www.texasteamplayers.com homepage.

This website is proudly hosted on Crocweb Cloud Website Hosting.