TinyPortal

Development => Block Codes => Topic started by: opschf on March 13, 2006, 03:48:35 AM

Title: Recent Articles For Center Block
Post by: opschf on March 13, 2006, 03:48:35 AM
I wanted a section for recent posts and I also wanted one for recent articles.  I am just getting my website up and running.  I could not figure out how to do it, so I gave up and wrote a phpbox to do this function as follows:


$articles=db_query("SELECT id,subject,intro,author FROM tportal_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 '<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px;
             margin-bottom: 4px;" border="0" class="tborder"><tr>';
    echo '<td width="100%"><div class="titlebg" style="padding: 6px;">
    <img src="http://www.mywebsite.com/SMF/Themes/default/images/TParticle.gif" alt="*" style="margin: 0px;" align="middle" />
    <a href="http://www.mywebsite.com/SMF/index.php?page=' . $row[0] . '"><b>' . $row[1] . '</b></a></div><div style="padding: 8px; padding-top: 0px;" class="windowbg2">
    <div style="padding-bottom: 4px; vertical-align: bottom;" class="smalltext"> By :
    <b>' . $row[3] . '</a></b></div>' . $row[2] . '<br></div>
    <div class="windowbg"style="padding: 6px;">
    <a href="http://www.mywebsite.com/SMF/index.php?page=' . $row[0] .'">Read more...</a></div></td>';
     echo '</tr></table>';
    }
   $cnt++;
}
If  ($cnt=0) {
    echo '<td>No Artcles to review.  Please submit articles.';
    }



[attachment deleted by admin]
Title: Re: Recent Articles For Center Block
Post by: Arkanthos on March 13, 2006, 04:40:54 AM
Blimey, that's exactly what I was trying to do this afternoon. I have a list of about 80 articles I'm bringing over from phpNuke where I had the handy dandy universal module to keep them neat and pretty. Thanks bro, big help.

Just one note, you might want to put a header section on this .txt and alter it a little bit for those who are less adept at scanning for material that needs to be changed. I'll toss one up just to show ya what I'm talking about.

[attachment deleted by admin]
Title: Re: Recent Articles For Center Block
Post by: opschf on March 13, 2006, 04:52:00 AM
I also added on the left hand side a block that lists the categories for articles.  Maybe you would find this useful as well...

$categories=db_query("SELECT * FROM tportal_variables", __FILE__, __LINE__);
While ($row=mysql_fetch_row($categories)) {
if ($row[4] == "category" && $row[0] != 46) {  // I exclude one category
echo '<a href=http://www.
mywebsite.com/SMF/index.php?cat=' . $row[0] . '>' . $row[1] . '</a><br>';
}
}
echo'
<br>
<br>
<i>More categories will be added as articles are received.<i>';


Let me know what you think of them...   ;D
Title: Re: Recent Articles For Center Block
Post by: Arkanthos on March 13, 2006, 05:02:10 AM
When I go to use the first one I'm getting

Table 'DBNAME.tportal_articles' doesn't exist
File: PATH/Sources/Load.php(1607) : eval()'d code(32) : eval()'d code
Line: 2


I've masked the path and DBname just for my own sense of security, can't be too careful
Title: Re: Recent Articles For Center Block
Post by: opschf on March 13, 2006, 10:45:09 AM
you need to check your database.  From the alarm, it cannot find the table "tportal_articles", which is the defaulted table name in program.  Go into phpmyadmin or similiar program and find where the table for tportal are listed.  Let me know if this helps.
Title: Re: Recent Articles For Center Block
Post by: Harro on June 13, 2006, 01:47:25 PM
Thanks for this. Was looking for it!
Modified it a bit.
Better for one of the side blocks now. Only displays the title of the article.
Here's the code if anybody is interested.
Example can be seen on http://www.forumaffiliates.net on the left sidebar.
$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.forumaffiliates.net/index.php?page=' . $row[0] . '">' . $row[1] . '</a><br /><br />';
    }
   $cnt++;
}
If  ($cnt=0) {
echo '<td>No Artcles to review.  Please submit articles.';
}
Title: Re: Recent Articles For Center Block
Post by: datu on August 09, 2006, 08:32:54 AM
Hey guys this is a great piece of code. very useful for me. Keep up the great work. Thnx a bunch!

I was wondering how you could modify this just to show specific articles, and not the most recent?

Thanks again, cheers!
Title: Re: Recent Articles For Center Block
Post by: Harro on August 10, 2006, 02:25:28 PM
For specific articles you can just create an html block and put the url to the articles there.
Title: Re: Recent Articles For Center Block
Post by: datu on August 12, 2006, 03:38:07 PM
Yah thats what im doing now.. i just wanted to be lazy and have a script do it for me.. haha

Oh well..

Thnx for the reply
Title: Re: Recent Articles For Center Block
Post by: aglioeolio on November 09, 2006, 06:56:11 PM
thatÂÃ,´s exactly what I wanted

thanks a lot
Title: Re: Recent Articles For Center Block
Post by: othersi on January 05, 2007, 07:14:29 PM
Hi all.

This code is sooo close to what I'm looking for, but could use some tweaks to get me exactly where I want it... and I can't figure it out.  Hoping someone can help me out here.

I took the first code posted, by opschf, altered the database table name and url's to match my setup, stripped it down a bit, and put it in a php block.

In the block I turned off title/frame, as we want to build our own frame around it.

I've got it to show the most recent Article titles, and the author, but can't figure out how to get it to display the article category or date along with it.  I tried fitting the 2nd code posted by opschf into the mix to show the category, but couldn't get it to work... kept getting a parse error.

To show what we're trying to accomplish, and were we are right now, here is a screenshot.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.othersi.com%2Fstorage%2Freviewblock.jpg&hash=7a9366b3f2b1f381561e78e1f0cc67e1c162c0e9)

The lower portion is a "mockup" block that was created, in a script block.  This is what we are trying to accomplish.  This mockup block has the article info entered manually, but of course, we want to use a modified version of the code in this thread to do the work for us automatically.  The mockup block is, as I said, in a script block, not a php block as the code in this thread is... and it (the mockup block) has title/frame disabled, calling on a custom style sheet, custom images, etc to achieve the look it has.

The upper block of the screenshot is the result of the code I have so far, modified from this thread, running in a php block, with title/frame disabled.  As you can see... not quite there.  lol

I tried copying the calls to the stylesheet from the mockup block into this php block, but it caused errors... so obviously php blocks and script blocks don't work the same way... so what I may need is for this code to be altered so it will work in a script block... in order to allow us to then setup the style the way we want it.

The code used in the PHP block (modified from this thread) is:



$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 '<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px;
             margin-bottom: 4px;" border="0" class="tborder"><tr>';
    echo '
    <a href="http://www.othersi.com/index.php?page=' . $row[0] . '"><b>' . $row[1] . '</b></a>
     <div style="padding: 8px; padding-top: 0px;">
By : <b>' . $row[3] . '</b></div>

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


So, could someone help me out with what I need to do to get from where I am now to where I want to be?  I don't necessarily need the article author to appear in the block (not sure whether I want that or not)... but if it is included in the code, I can easily remove it later.

What we do want is for the code to call up the article title of the latest X number of articles, along with the date posted, and the category ... it would be cool if it would call up the category icon as in the screenshot mockup block, but if that's not possible, just the text description of the category, possibly as a link to that category, would be fine.  And if the article author is also called, that's cool too... I can decide later if I want to keep that or not.

All this needs to work in a script block (I think) so that we can then add in our calls to our own style-sheet to format the block as seen in the screenshot mockup block.

If someone could post the script code we need to pull the information in the right way, we can take it from there and build the formatted look around it.

Thank you very much in advance!
Title: Re: Recent Articles For Center Block
Post by: IchBin on January 05, 2007, 07:32:15 PM
Well I don't know javascript at all so sorry about that. But to add the date you can just add 'date' to your database call.

SELECT id,subject,intro,author,date

You could then call it from the array with ', date($row[4], date_format_here),'

Refer to http://us2.php.net/date for the date format of your choice.

To add the Article category is a little beyond what I'm able to figure out without getting deep into it. You'd probably have to join the table on ID of articles and Category of the variables table if possible and pull the article category name from the tp_variables table, if you didn't want to create a seperate call. I don't know SQL commands well at all or I'd give it a shot.
Title: Re: Recent Articles For Center Block
Post by: othersi on January 05, 2007, 09:13:28 PM
Thanks, that's one step closer.

Could you explain how the connection is made between the # in the $row statement and the actual data?

eg.  Why does row[4] pull the date from the tp_article table?  When I view the table in phpmyadmin, DATE is not the 4th row.

EDIT:  Ahh... I think I figured it out... maybe?  The # in the $row call is referring to what is being called in the SELECT statement?  So in this case, there are 5 things called in the SELECT statement, with them being 'assigned' 0,1,2,3,4 ?

2nd EDIT:  I can't seem to get the date formatting to work.

I'm trying to get in the form of month.day.year (eg. today would be 01-05-07).

I've used:  ', date($row[4], "m.d.y"),' , but it returns the dates as long strings of numbers... eg. 1168029360
Title: Re: Recent Articles For Center Block
Post by: IchBin on January 05, 2007, 11:30:47 PM
Yes that long string of numbers is what is called Unix time. It has to do with the total amount of seconds since 1979 or something like that. I can't remember exactly. lol

Nice job on figuring out how the array works. :up:

That looks like it should be working, but I'm not a php guru yet. I'll take a look when I get home here in a bit cuz I'm still at work. :(
Title: Re: Recent Articles For Center Block
Post by: othersi on January 06, 2007, 12:38:58 AM
I appreciate your time and help.
Title: Re: Recent Articles For Center Block
Post by: IchBin on January 06, 2007, 03:27:13 AM
Oops... I had it backwards. You put the time integer first, and then the date format like this:

date('m.d.y', $row[4])

I'll see what I can come up with for a Category call. I don't want to make another database call. But as I said, I'm no guru so I'm going to see if I can figure it out.
Title: Re: Recent Articles For Center Block
Post by: JPDeni on January 06, 2007, 03:41:03 AM
Can I butt in? :)

You can add the category to the list of columns returned from the search:


SELECT id,subject,intro,author,date, category


If you know the number of the category that corresponds to the image you want to display for Playstation, DVD, CD, etc, you can just use an array to display it.
Title: Re: Recent Articles For Center Block
Post by: IchBin on January 06, 2007, 04:19:04 AM
But category only holds an integer, the name of the category is stored in the variables table. Please enlighten me more, because I'm working on a very complex SQL call right now lol. :)
Title: Re: Recent Articles For Center Block
Post by: JPDeni on January 06, 2007, 05:04:26 AM
QuoteBut category only holds an integer
Right. But it's pretty easy to define the category name or icon based on the integer without pulling it from the database. The example othersi gave shows an image for the category, which would have to be defined anyway.

Here's how I would create what he has in his example:


global $db_prefix, $scripturl;

$cnt = 5; // the number of articles you want to display

$format[1] = '<img src="http://url/to/playstation.jpg">'; // change number to playstation category
$format[2] = '<img src="http://url/to/dvd.jpg">'; // change number to dvd category
$format[3] = '<img src="http://url/to/cd/jpg">'; // change number to cd category

$articles=db_query(
    "SELECT id, subject, date, category
     FROM {$db_prefix}tp_articles
     WHERE approved=1
     AND off=0
     ORDER BY date DESC
     LIMIT $cnt", __FILE__,__LINE__);

echo '<table><tr><td>TITLE</td><td>DATE</td><td>FORMAT</td></tr>';
while ($row=mysql_fetch_row($articles))
{
  echo '<tr><td><a href="', $scripturl , '?page=' , $row['id'] , '"><b>' , $row['subject'] , '</b></a></td>';
  echo '<td>' , date('m.d.y', $row['date']) , '</td>';
  echo '<td>' , $format[$row['category']] , '</td></tr>';
}
echo '</table>';


Of course, I didn't add formatting and intros and that sort of stuff in there, but this would print out the information needed.

I find it preferable to use the column names rather than the numbers because there's more flexibility. If you change the code, you don't have to remember to change all the references to numbers. Also, it's easier to see what you're referring to.
Title: Re: Recent Articles For Center Block
Post by: othersi on January 06, 2007, 05:55:24 AM
You guys are awesome.  You have no idea how cool I find this that there are gurus like you out there willing to put time into other peoples problems. :)

JPDeni... if your idea ends up being the best solution... just wondering what parts of it I need to edit. 

Obviously I need to edit the URL's to the appropriate category image urls.  I also would need to add more $format[_] lines, one for each category (the example in my earlier screenshot only shows three categories, while there will be probably 6 or so when we're done).

Does anything else need to be edited?

Also... is this for a php block, or a script block?
Title: Re: Recent Articles For Center Block
Post by: IchBin on January 06, 2007, 06:21:57 AM
This for a php block. I just hashed out the code with some of the SMF guru's if this doesn't work out for you. Here's the code Jay, Daniel, and I came up with.


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)
        LIMIT 5", __FILE__,__LINE__);

echo '
<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px; margin-bottom: 4px;" border="0" class="tborder">';

if (mysql_fetch_assoc($articles) == 0)
        echo '
<tr>
<td>No Reviews Available</td>
</tr>';
else
{
        while ($row = mysql_fetch_assoc($articles))
                echo '
<tr>
<td>
<a href="', $scripturl ,'?page=', $row['id'], '"><b>', $row['subject'], '</b></a>
<div style="padding: 8px; padding-top: 0px;">
By : <b>', $row['author'], '</b><br />
Created on: ', date("m/d/y", $row['date']), '<br />
Category: ', $row['category_name'], '
</div>
</td>
</tr>';


}
echo '
</table>';

mysql_free_result($articles);
Title: Re: Recent Articles For Center Block
Post by: JPDeni on January 06, 2007, 02:29:55 PM
Right. You'll need to edit the URLs for the images, and add other images. You'll also need to add formatting to make things look the way you want them to... the "divs" and such. And you'll need to add your introductory text to the block. (I just had to edit my code because I forgot to put the img tags in. Minor detail. ;) )

This would go into a php block.

IchBin has done an exceptional job on this, especially for someone without much programming background.
Title: Re: Recent Articles For Center Block
Post by: IchBin on January 06, 2007, 02:32:46 PM
Well, I had to have Jay and Daniel explain the whole "JOIN" thing lol. They also schooled me in the "proper" way of indent and layout of programming. haha
Title: Re: Recent Articles For Center Block
Post by: othersi on January 06, 2007, 11:38:50 PM
Thanks IchBin... your code seems the closest to working right out of the gate.  It's a different layout than our mockup, but it does bring in all the relevant info.

(I can't get JPDeni's to work for some reason... it just brings in an empty "table", except that the date column is all filled in with 12.31.69)

I've tried IchBin's code in a PHP block, without editing anything, and it's only bringing in 4 articles (I assume the LIMIT 5 is supposed to bring in 5 articles?)... all from a single category ... and it's bringing them in from oldest first.

ie.  The 4 articles that get brought in are all from the 'music' category (category=27), which contains 8 articles... the code 'as is' is bringing in the 4 oldest articles from that category, listed oldest first.
Title: Re: Recent Articles For Center Block
Post by: othersi on January 08, 2007, 11:52:00 PM
Okay... I added an ORDER BY date DESC which fixed which articles were being called.

And for some reason, the LIMIT has to be set one higher than what is called.  ie.  to bring in 5 articles, it needs to be set to LIMIT 6.

Having done that, it is now bringing in all of the relevant info, though the categories are text, not the associated images.  I imaging mingling JPDenis changing thing where he changes the category integer to an image would work... if I can figure it out. :)
Title: Re: Recent Articles For Center Block
Post by: othersi on January 09, 2007, 04:09:30 AM
We are very, very close here. :)

I've got the code almost right where we want it.

Here's a screenie:

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.othersi.com%2Fstorage%2Freviewblock02.gif&hash=f10fdfd45d5deefeaadaa539c9a49b985acb24a1)


Two things I could still use a hand on:

ONE:

There is still a problem with how it's grabbing articles.

Here is the code as we've got it now:


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);


(most of the code is just setting up the formatting... the meat of the code is a modified version of what IchBin posted up above)

As you can see, in the code, the LIMIT statement is set to 5.  As you can see in the screenshot, it's only grabbing 4 articles.

If I change the LIMIT to 6, then 5 articles show.

BUT... what it's doing is ignoring the most recent article.

So, in the case of the screenshot above , the Zelda review is actually the *second* newest review.  The newest one happens to be a Battlestar Galactica article.

If I submit *another* article/review, suddenly Battlestar Galactica shows up, the other reviews all get bumped down 1... but the new review I just submitted/approved does not show.

As a test, I tried the code exactly as IchBin posted it, just adding an ORDER BY date DESC, right before the LIMIT 5" statement... and it behaves the same way... it pulls 4 articles, missing the most recent, listing the next 4.


What I discovered is the 'if (mysql_fetch_assoc($articles) == 0)' part was causing the problem.  If I take that bit (and the associated 'else' coding) out... and just use the code assuming there always will be at least 1 article, it works properly.

This isn't a HUGE deal... as there should always be an article present... but if someone can suggest a fix so that the "if (mysql_fetch_assoc($articles) == 0)" part will work, I would use it.



And TWO:

We're wanting to give some separation between each subsequent row in the review listing.

My initial idea, as seen in the initial screenshot I posted a while ago (http://www.othersi.com/storage/reviewblock.jpg) was to use alternating backgrounds in alternating rows.  This was setup in the mockup by a co-admin using tr class=row1 and tr class=row2 statements (calling on a custom stylesheet).

Deciding simpler might be better, I figured I could create a small line image... just a 1 pixel-high line that fits nicely across the table, and have that insert in between each row of the review listings.  Problem is... I can't figure out how to get the image in between the rows... seems no matter where I try to put the image tag, it ends up putting 5 copies of the image ABOVE the review listings, rather than in between the listings.



Any help on either of these two issues would be greatly appreciated!
Title: Re: Recent Articles For Center Block
Post by: Byakko89 on April 18, 2007, 05:36:48 AM
alguien que hable estañol y sepa de este tema me podria ayudar con esto ??
Title: Re: Recent Articles For Center Block
Post by: G6Cad on April 18, 2007, 09:37:01 AM
You have to write in english in this board.
Title: Re: Recent Articles For Center Block
Post by: gffb on June 14, 2007, 03:48:04 AM
I would really like to use this block snippet on my board has a fix for the block not showing the most recent artice been found and does is show articles in date order?

[edit] I used the code posted on page 2 this worked for me
$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 '<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px;
             margin-bottom: 4px;" border="0" class="tborder"><tr>';
    echo '
    <a href="http://www.othersi.com/index.php?page=' . $row[0] . '"><b>' . $row[1] . '</b></a>
     <div style="padding: 8px; padding-top: 0px;">
By : <b>' . $row[3] . '</b></div>

</td>';
     echo '</tr></table>';
    }
   $cnt++;
}
If  ($cnt=0) {
    echo '<td>No Reviews Available';
    }
Title: Re: Recent Articles For Center Block
Post by: planetricki on October 05, 2007, 05:21:55 PM
How would you use this code outside of TP/SMF? I'd like include recent articles or call a specific article to include on a mostly static php page using the php include code.

Any ideas? Thanks!
Title: Re: Recent Articles For Center Block
Post by: Rabain on October 11, 2007, 08:08:06 AM
Am I just imagining things or was there an Articles link on the left panel when I installed TP?  I recall doing something to deactivate it but now I can't recall what it was and I want Articles back...it showed the two articles that come with TP (Portal Features category).  The link was in the same box as Download link and similarly had an icon beside it.

Anyway my main question was...I'm am currently using the code in the first post to display recent articles.  However I want to remove the line separating each article in the list and change the font size.  Where do I put this in the code, after the border/class part?
Title: Re: Recent Articles For Center Block
Post by: Zetan on October 11, 2007, 09:39:04 AM
1. Try adding an Article category block.

2. Don't know. At work and can't check.
Title: Re: Recent Articles For Center Block
Post by: IchBin on October 12, 2007, 02:49:51 PM
Try changing the class or taking it off. Trouble shoot it that way and you'll learn how it works.
Title: Re: Recent Articles For Center Block
Post by: Rabain on October 17, 2007, 05:07:16 AM
I'm currently using the following:

$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 < 5) {
          echo '<font size="1"><strong><a href="http://www.borderkingdoms.net/index.php?page=' . $row[0] . '">' . $row[1] . '</a><br />';
    }
   $cnt++;
}
If  ($cnt=0) {
echo '<td>No Artcles to review.  Please submit articles.';
}


My font size and is applying itself to every block in the panel rather than just this php block.

I've tried every form of </font> entry but I'm just not up to speed on html/php.

All I want is the text in the block to be size 1 and bold (which I just couldn't get to work so I'm going with !).

Any help is much appreciated
.
Title: Re: Recent Articles For Center Block
Post by: Zetan on October 17, 2007, 08:28:08 AM
You probably have an open font tag.. you need to close any open tags, else they will bleed into other areas.

eg



<font><strong> content.. you must now close the tags that are open </strong></font>

Title: Re: Recent Articles For Center Block
Post by: G6Cad on October 17, 2007, 08:31:12 AM
echo '<td>No Artcles to review.  Please submit articles.';

You have the <td> but not a closing < /td> in that line
Title: Re: Recent Articles For Center Block
Post by: Rabain on October 17, 2007, 10:44:30 AM
Thanks guys.  Seems to be working now!
Title: Re: Recent Articles For Center Block
Post by: Chipicao on November 25, 2007, 10:26:23 PM
Quote from: IchBinâ,,¢ on January 06, 2007, 06:21:57 AM
This for a php block. I just hashed out the code with some of the SMF guru's if this doesn't work out for you. Here's the code Jay, Daniel, and I came up with.


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)
        LIMIT 5", __FILE__,__LINE__);

echo '
<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px; margin-bottom: 4px;" border="0" class="tborder">';

if (mysql_fetch_assoc($articles) == 0)
        echo '
<tr>
<td>No Reviews Available</td>
</tr>';
else
{
        while ($row = mysql_fetch_assoc($articles))
                echo '
<tr>
<td>
<a href="', $scripturl ,'?page=', $row['id'], '"><b>', $row['subject'], '</b></a>
<div style="padding: 8px; padding-top: 0px;">
By : <b>', $row['author'], '</b><br />
Created on: ', date("m/d/y", $row['date']), '<br />
Category: ', $row['category_name'], '
</div>
</td>
</tr>';


}
echo '
</table>';

mysql_free_result($articles);

How can I sort the articles by date, and how can I make it show only articles from one of the categories?
Title: Re: Recent Articles For Center Block
Post by: IchBin on November 25, 2007, 10:47:00 PM
Don't know if this will work as I haven't tested it. But give this a shot just changing this section of code: (don't forget to replace the category name where I put 'put_category_name_here').
$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)
WHERE category_name = 'put_category_name_here'
ORDER BY art.date
        LIMIT 5", __FILE__,__LINE__);

Title: Re: Recent Articles For Center Block
Post by: Chipicao on November 27, 2007, 08:30:57 PM
Thank you for the quick reply.

The category filter doesn't work. I get this error:
QuoteDatabase Error: Unknown column 'category_name' in 'where clause'
File: /var/www/sites/dev.sayit.ro/Sources/Load.php(1749) : eval()'d code(35) : eval()'d code
Line: 9

The sorting works, but it's ascending, so I have to use this:
ORDER BY art.date DESC

Any ideas? What exactly should I put instead of put_category_name_here? The actual name of the category?
Title: Re: Recent Articles For Center Block
Post by: IchBin on November 28, 2007, 01:27:18 AM
oops. Try var.value1 instead of category_name
Title: Re: Recent Articles For Center Block
Post by: Chipicao on November 28, 2007, 05:34:22 AM
Thanks, it works now! One more thing please. The newest article isn't shown, only from the second one till the last. How can I make the firs one appear?
Title: Re: Recent Articles For Center Block
Post by: IchBin on November 29, 2007, 01:00:07 AM
As far as I can tell it should be getting it. Is it on and approved?
Title: Re: Recent Articles For Center Block
Post by: Chipicao on November 29, 2007, 09:43:18 AM
Yes, the article is active. It appears on the recent list only after another article is posted, but again, the new article isn't listed.

Here is the exact code I use, if it helps:

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)
WHERE var.value1  = 'Teste si prezentari' AND approved=1 AND off=0
ORDER BY art.date DESC
        LIMIT 15", __FILE__,__LINE__);

echo '
<table cellspacing="0" cellpadding="0" width="100%">';

if (mysql_fetch_assoc($articles) == 0)
        echo '
<tr>
<td>No Reviews Available</td>
</tr>';
else
{
        while ($row = mysql_fetch_assoc($articles))
                echo '
<tr>
<td><font size="1">
<a href="', $scripturl ,'?page=', $row['id'], '"><b>• ', $row['subject'],

'</b></a>
</font></td>
</tr>';


}
echo '
</table>';

mysql_free_result($articles);

You can see it here: http://dev.sayit.ro
I've even tried removing AND approved=1 AND off=0, but it still doesn't work.
Title: Re: Recent Articles For Center Block
Post by: Chipicao on December 04, 2007, 12:21:22 PM
I have one more issue (unfortunately). I want to show articles from 4-5 categories, not just one. I thought that if I make the categories I want subcategories of one "main" category it will work. It doesn't! How can I work around this?

L.E. Solved it, thanks to a friend.
Just use WHERE var.value1 in ('cat1','cat2','cat3','cat4')

I also have a workaround for the last article issue. Just post an empty article, deactivate it and set it's date to 31 December. Don't forget to change the year on January 1st :)
Title: Re: Recent Articles For Center Block
Post by: jacortina on December 13, 2007, 11:07:57 PM
Quote from: Chipicao on November 29, 2007, 09:43:18 AM
Yes, the article is active. It appears on the recent list only after another article is posted, but again, the new article isn't listed.

Here is the exact code I use, if it helps:
if (mysql_fetch_assoc($articles) == 0)

Change that line to:
if (mysql_num_rows($articles) == 0)

The original code meant that the first row was fetched for the test. After it came up positive, what was left for the 'while' loop was the 2nd through Xth rows.
Title: Re: Recent Articles For Center Block
Post by: gffb on January 30, 2008, 09:57:38 PM
Quote from: opschf on March 13, 2006, 04:52:00 AM
I also added on the left hand side a block that lists the categories for articles.  Maybe you would find this useful as well...

$categories=db_query("SELECT * FROM tportal_variables", __FILE__, __LINE__);
While ($row=mysql_fetch_row($categories)) {
if ($row[4] == "category" && $row[0] != 46) {  // I exclude one category
echo '<a href=http://www.
mywebsite.com/SMF/index.php?cat=' . $row[0] . '>' . $row[1] . '</a><br>';
}
}
echo'
<br>
<br>
<i>More categories will be added as articles are received.<i>';


Let me know what you think of them...   ;D

I have tried using this code but get a 500 server error is there any other code that can list all my article cats in a block.
Title: Re: Recent Articles For Center Block
Post by: IchBin on January 30, 2008, 10:20:20 PM
Change this line to reflect the right table for variables:
$categories=db_query("SELECT * FROM tportal_variables", __FILE__, __LINE__);

Its usually tp_variables and not tportal_variables.

Title: Re: Recent Articles For Center Block
Post by: gffb on January 30, 2008, 10:37:43 PM
This code still gives 500 server error
$categories=db_query("SELECT * FROM tp_variables", __FILE__, __LINE__);
While ($row=mysql_fetch_row($categories)) {
if ($row[4] == "category" && $row[0] != 46) {  // I exclude one category
echo '<a href=http://www.abcunited.net/site/index.php?cat=' . $row[0] . '>' . $row[1] . '</a><br>';
}
}
echo'
<br>
<br>
<i>More categories will be added as articles are received.<i>';
Title: Re: Recent Articles For Center Block
Post by: gffb on January 30, 2008, 11:25:17 PM
Quote from: gffb on January 30, 2008, 10:37:43 PM
This code still gives 500 server error
$categories=db_query("SELECT * FROM tp_variables", __FILE__, __LINE__);
While ($row=mysql_fetch_row($categories)) {
if ($row[4] == "category" && $row[0] != 46) {  // I exclude one category
echo '<a href=http://www.abcunited.net/site/index.php?cat=' . $row[0] . '>' . $row[1] . '</a><br>';
}
}
echo'
<br>
<br>
<i>More categories will be added as articles are received.<i>';


Resolved by changing
$categories=db_query("SELECT * FROM tp_variables", __FILE__, __LINE__);
to
$categories=db_query("SELECT * FROM smf_tp_variables", __FILE__, __LINE__);
Title: Re: Recent Articles For Center Block
Post by: warhonowicz on February 07, 2008, 11:25:39 AM
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?
Title: Re: Recent Articles For Center Block
Post by: G6Cad on February 07, 2008, 01:25:57 PM
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
Title: Re: Recent Articles For Center Block
Post by: IchBin on February 07, 2008, 03:21:16 PM
If you don't find your answer then post a link so we can see it in action on your site.
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on February 20, 2008, 06:03:38 AM
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);
Title: Re: Recent Articles For Center Block
Post by: bigdog on March 19, 2008, 05:52:23 PM
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.
Title: Re: Recent Articles For Center Block
Post by: bigdog on March 20, 2008, 09:31:12 PM
we've modified one of the earlier codes in this thread.  got the block to look like this:
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg167.imageshack.us%2Fimg167%2F7294%2Fpicture1qd4.png&hash=8b3f73abeb32c75854e711e547caca9c144287bd)
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?
Title: Re: Recent Articles For Center Block
Post by: bigdog on March 21, 2008, 05:04:15 AM
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.
Title: Re: Recent Articles For Center Block
Post by: bigdog on March 24, 2008, 11:00:36 PM
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
Title: Re: Recent Articles For Center Block
Post by: fussilet on March 27, 2008, 10:14:42 PM
$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';
    }
Title: Re: Recent Articles For Center Block
Post by: bigdog on March 28, 2008, 04:55:56 AM
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.
Title: Re: Recent Articles For Center Block
Post by: G6Cad on March 28, 2008, 02:16:14 PM
Link doesent seem to work
Title: Re: Recent Articles For Center Block
Post by: bigdog on March 28, 2008, 02:43:05 PM
Quote from: G6 on March 28, 2008, 02:16:14 PM
Link doesent seem to work
....I don't know what to say, G6.  Perhaps you are being blocked by our firewall(s).  We had some dDOS attacks a few months back, and had to ban some seriously large blocks of IP's.  Especially some international ones (outside the U.S. I mean)

what IP are you on, or trying to access www.texasteamplayers.com from?
Title: Re: Recent Articles For Center Block
Post by: bigdog on March 28, 2008, 03:06:02 PM
an image for those that are unable to see my site (we have over 1000 unique visitors a day.....30,000 page views a day....so I'm guessing it must be an IP block if you can't visit the site).

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg526.imageshack.us%2Fimg526%2F1121%2Fpicture1sq6.png&hash=151afd9dc0e9d3db8f0d9586feb87f6a07a10179)
http://img526.imageshack.us/img526/1121/picture1sq6.png
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 07, 2008, 07:36:41 AM
how can i add the read more... after the article intro?
Title: Re: Recent Articles For Center Block
Post by: JPDeni on April 07, 2008, 12:55:52 PM
Assuming you're using the most recent code posted, change


    <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>


to


    <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] . ' read more...</font>


Notice that the domain name is hard-coded into this, so you'll have to change it to match your own domain.
Title: Re: Recent Articles For Center Block
Post by: bigdog on April 07, 2008, 04:17:46 PM
we had that on as well, however given the article title is linked to the article itself....it's redundant to have "read more" linked to the same destination.

so we took it off.
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 08, 2008, 06:10:15 PM
can we remove link for title and give it to read more?
Title: Re: Recent Articles For Center Block
Post by: bigdog on April 08, 2008, 06:12:24 PM
of course.
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 08, 2008, 06:19:32 PM
anybody can help to make it...
Title: Re: Recent Articles For Center Block
Post by: bigdog on April 08, 2008, 06:24:34 PM
if you look at the code, I bet you can figure it out.  Just move the hrefs and the row info around till you get what you want.
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 17, 2008, 05:22:14 AM
Quote from: bigdog on March 28, 2008, 04:55:56 AM
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.

when user click the article topic... its automatically bring user to log off but still can read article but not to post comment because there are now guest.
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 18, 2008, 06:00:09 PM
Quote from: alhaudhie on April 17, 2008, 05:22:14 AM
Quote from: bigdog on March 28, 2008, 04:55:56 AM
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.

when user click the article topic... its automatically bring user to log off but still can read article but not to post comment because there are now guest.

anybody can reply this?
Title: Re: Recent Articles For Center Block
Post by: JPDeni on April 18, 2008, 06:26:57 PM
Is your site http://www.texasteamplayers.com/ ? Is the code in your post the actual code that you are using?
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 18, 2008, 06:44:25 PM
thats not my site...

but i have change all the link to my site link...
Title: Re: Recent Articles For Center Block
Post by: JPDeni on April 18, 2008, 07:04:38 PM
I can't debug your code unless you post your code.
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 18, 2008, 07:15:58 PM
this my code....

$max_shown=3;
$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.mysite.net/v10/imej/umum.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.mysite.net/v10/index.php?cat=' . $row[7] . '"><img src="' . $row[8] . '" align="left" hspace="5"></a> <a href="http://www.mysite.net/v10/index.php?page=' . $row[0] . '"><b><font size="2px">' . $row[1] . '</font></b></a> <font size="1"><em>by <a href="http://www.mysite.net/v10/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';
    }
Title: Re: Recent Articles For Center Block
Post by: JPDeni on April 18, 2008, 07:59:34 PM
I rearranged it a bit to make it easier for me to read. I'm not sure if this will solve your problem, but it should work.


global $scripturl;

$max_shown=3;
$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.mysite.net/v10/imej/umum.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="' . $scripturl . '?cat=' . $row[7] . '">
       <img src="' . $row[8] . '" align="left" hspace="5"></a>
       <a href="' . $scripturl . '?page=' . $row[0] . '">
       <b><font size="2px">' . $row[1] . '</font></b></a>
       <font size="1"><em>by <a href="' . $scripturl . '?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 'No Articles Available';
}


Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 18, 2008, 08:02:24 PM
 :up: :up:

thanks soo much...

really nice...
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 18, 2008, 08:19:19 PM
how can i make the space between 2 article soo closed?

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg526.imageshack.us%2Fimg526%2F1121%2Fpicture1sq6.png&hash=151afd9dc0e9d3db8f0d9586feb87f6a07a10179)
Title: Re: Recent Articles For Center Block
Post by: JPDeni on April 18, 2008, 08:29:30 PM
Quotehow can i make the space between 2 article soo closed?
I don't understand. Do you want them closer together or further apart?
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 18, 2008, 08:54:16 PM
sorry for my bad english...

i mean, u can see the image for the article category ( the space between the image soo far) how can i make it not soo far...? or how can i make harizontal row between article?
Title: Re: Recent Articles For Center Block
Post by: IchBin on April 18, 2008, 08:59:07 PM
Take out the <p> and </p> tags in your code.
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 26, 2008, 09:20:27 PM
how can i make it to take image from custom folder?
Title: Re: Recent Articles For Center Block
Post by: JPDeni on April 26, 2008, 10:18:43 PM
Put in an img tag just like you would on an html page.
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on April 28, 2008, 07:39:51 PM
when using the new version of TP, the icon of article is replace...

before this in the old tp.. we put the image address...
in the new tp the icon of my article must be upload in tp-files/tp-articles/icons/myimages.png.

that why i think the article icon is gone...
how can i edit it to call from tp-files/tp-articles/icons/ ?
Title: Re: Recent Articles For Center Block
Post by: fussilet on April 28, 2008, 10:37:28 PM
hi  alhaudhie
When you look for when you look for in the Tportal.AdminTemp
Title: Re: Recent Articles For Center Block
Post by: alhaudhie on May 17, 2008, 01:31:19 AM
why this code cant read the intro article when it using html code exactly?

global $scripturl;

$max_shown=3;
$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.mysite.net/v10/imej/umum.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 '
    <a href="' . $scripturl . '?cat=' . $row[7] . '">
       <img src="/v10/tp-files/tp-articles/icons/' . $row[8] . '" align="left" hspace="5"></a>
       <a href="' . $scripturl . '?page=' . $row[0] . '">
       <b><font size="2px">' . $row[1] . '</font></b></a>
       <font size="1"><em>by <a href="' . $scripturl . '?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>
    </td>';
     echo '</tr></table>';
   $cnt++;
}
if  ($cnt=0) {
    echo 'No Articles Available';
}
Title: Re: Recent Articles For Center Block
Post by: IchBin on May 17, 2008, 02:18:11 AM
Looks to me like its fetching the intro's. If you don't have an intro set, it won't work. The article has to be an html/bbc article type. PHP articles don't have an intro.

Title: Re: Recent Articles For Center Block
Post by: Lafemme on October 22, 2008, 08:30:04 PM
hello,

i want to use this code, i like it very much :) However.. i do not see the categorie image at all... I use TP 1.0.6

this is the code that i am using :

Quote$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.bimeiden.nl/tp-files/tp-articles/icons/TPadm-article.gif') 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.bimeiden.nl/index.php/cat,' . $row[7] . '.html"><img src="' . $row[8] . '" align="left" hspace="5"></a> <a href="http://www.bimeiden.nl/index.php/page,' . $row[0] . '.html"><font size="4">' . $row[1] . '</font></a> <font size="1">by <a href="http://www.bimeiden.nl/index.php?action=profile;u=' . $row[4] . '">' . $row[3] . '</a> on ' . date( "m/d/y", $row[5] ) . '</font></div>
<font size="1">' . $row[2] . '</font>
     </p></td>';
     echo '</tr></table>';
   $cnt++;
}
If  ($cnt=0) {
    echo '<td>Geen artikelen beschikbaar';
    }

Does anybody have an idea?  Thank you
Title: Re: Recent Articles For Center Block
Post by: IchBin on October 22, 2008, 08:56:54 PM
Please post code in the BBC [ code ] brackets. Posting code in a quote loses some of the code elements as its parsed as a quote instead of code. Where did you get this code? It looks like you or someone added the link to the query? It will not work with that..
Title: Re: Recent Articles For Center Block
Post by: Lafemme on October 23, 2008, 10:48:43 AM
woops.. sorry... 

$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.bimeiden.nl/tp-files/tp-articles/icons/TPadm-article.gif') 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.bimeiden.nl/index.php/cat,' . $row[7] . '.html"><img src="' . $row[8] . '" align="left" hspace="5"></a> <a href="http://www.bimeiden.nl/index.php/page,' . $row[0] . '.html"><b><font size="4">' . $row[1] . '</font></b></a> <font size="1"><em>by <a href="http://www.bimeiden.nl/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';
    }


I got this code from thisreply in this topic..   http://www.tinyportal.net/index.php/topic,3320.msg184800.html#msg184800 (http://www.tinyportal.net/index.php/topic,3320.msg184800.html#msg184800)

also removind the <p> tag will result in an error.. if i want to decrease the space...
Do you also know what i have to change to make the titles one font smaller? because the titels are huge :D
Title: Re: Recent Articles For Center Block
Post by: IchBin on October 24, 2008, 12:10:13 AM
I'm assuming this is the font code for the title.
<b><font size="4">' . $row[1] . '</font>

Change the size to what you'd like and see if thats the line. If not, try the other <font> tags in the code. Experiment is the best way to learn.
Title: Re: Recent Articles For Center Block
Post by: Lafemme on October 24, 2008, 12:35:45 PM
oke Ichbin..  thank you for the reply..

does anyone else have the problem with not showing the category image? If so, how did  you fix it?
Title: Re: Recent Articles For Center Block
Post by: CWJT on November 10, 2008, 11:43:43 AM
How to I add in the time in this format [Today at 23:59:59]?
Title: Re: Recent Articles For Center Block
Post by: IchBin on November 10, 2008, 07:32:48 PM
You change the code where it sets the date.
</a> on ' . date( "m/d/y", $row[5] ) . '</em>

Take a look at www.php.net/date to see how you can change the date of the format to what you want.

</a> Today at ' . date( "m/d/y", $row[5] ) . '</em> (change the m/d/y to the options you get from the php.net page that you need.
Title: Re: Recent Articles For Center Block
Post by: CWJT on November 11, 2008, 03:42:31 AM
Is it possible to script it such that if it was posted today it will display today as the date and if was viewed the next day it will show yesterday's date just like recent topics.
Title: Re: Recent Articles For Center Block
Post by: Lafemme on November 11, 2008, 10:00:03 PM
oke.. it would be great if this  script  (that i have posted a couple of posts before)also parses bcc code :) since some intro's have some bcc code and now that's not shown in this block. :D
Title: Re: Recent Articles For Center Block
Post by: Itch on November 11, 2008, 10:20:59 PM
I'm not sure if it will work or not. Add doUBBC() to whatever part you want to parse bbc code on.

doUBBC($row[0]) for example.
Title: Re: Recent Articles For Center Block
Post by: Lafemme on November 13, 2008, 03:33:21 PM
yes.. it works.. thanks !!!!!!!!!
Title: Re: Recent Articles For Center Block
Post by: willcom on August 04, 2009, 09:30:54 AM
If I wanted to replace the little icon in this code for the article image, what code would I put in place of <img src="' . $row[8] . '" align="left" hspace="5"> Please excuse my php innocence.
Title: Re: Recent Articles For Center Block
Post by: ZarPrime on August 04, 2009, 11:30:23 AM
willcom,

This is kind of an old topic so it might help our coders, when they see this, if you could rephrase your question.  What little icon and what article image are you talking about?  If this code is from one of the blocks of code in this topic, it might help them if you could post the whole code you are using.

ZarPrime
Title: Re: Recent Articles For Center Block
Post by: Freddy on August 04, 2009, 12:44:19 PM
Yeah, I can see what to do here, but need to see which version of the code you are using.  But that said I should be able to help.  Cheers.
Title: Re: Recent Articles For Center Block
Post by: willcom on August 04, 2009, 02:17:53 PM
My mistake sorry folks.  Here is the code I'm using, it has a small icon next to <h3> and was wanting to know how to replace this with the article image (I guess that's the icon for the article category?)

See it in action on www.sorcey.co.uk


$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,'/sorcey/tp-files/tp-articles/icons/TPadm-article.gif') as category_img FROM smf_tp_articles a inner join smf_tp_variables c on a.category = c.id WHERE c.id IN ('1', '2') AND 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="index.php/cat,' . $row[7] . '.html"><img src="' . $row[8] . '" align="left" hspace="5"></a> <a href="index.php/page,' . $row[0] . '.html"><b><h3 style="margin-bottom:0px">' . $row[1] . '</h3></b></a>
<font style="margin-left:27px" size="1"><em>by <a href="index.php?action=profile;u=' . $row[4] . '"><b>' . $row[3] . '</b></a> on ' . date( "d/m/y", $row[5] ) . '</em></font></div>
<p>' . $row[2] . '  <strong><a href="index.php/page,' . $row[0] . '.html">read more...</a></strong></p>
<p><strong><a href="index.php?page=articles">More articles...</a></strong>
     </p></td>';
     echo '</tr></table>';
   $cnt++;
}
If  ($cnt=0) {
    echo '<td>No Articles Available';
    }


And why does the WYSIWYG editor sometimes flicker up and down when I'm trying to type!!!   :tickedoff:
Title: Re: Recent Articles For Center Block
Post by: Freddy on August 04, 2009, 04:40:08 PM
I think you can just change the line starting with $articles...

Change :

/sorcey/tp-files/tp-articles/icons/TPadm-article.gif

To wherever your alternative image is :

/path/to/my/image.gif

Is that what you mean - or do you mean a different image for each article ?