* User

Welcome, Guest. Please login or register.
Did you miss your activation email?

08 Sep 10, 14:45:23

Login with username, password and session length

Select language:

* Recent Topics



Donate

Donate for PortaMx !
Your donation is safe and helps support the issues and causes you care most about.

* Stats

  • *Total Members: 2448
  • *Latest: ElNikez

  • *Total Posts: 10789
  • *Total Topics: 1629
  • *Online Today: 20
  • *Most Online: 157
(27 Aug 09, 03:54:53)
  • *Users: 0
  • *Guests: 15
  • *Total: 15

Author Topic: PHP Block for SMF Articles  (Read 3308 times)

0 Members and 1 Guest are viewing this topic.

Offline DarN

  • Newbie
  • *
  • Posts: 3
  • Gender: Male
PHP Block for SMF Articles
« on: 11 Mar 09, 21:00:02 »
Code: [Select]
global $smcFunc, $scripturl;

isAllowedTo('view_articles');

$dbresult = $smcFunc['db_query']('', "
SELECT a.ID_ARTICLE, a.title
FROM {db_prefix}articles AS a
WHERE a.approved = 1
ORDER BY a.date DESC
LIMIT 10
");

while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
echo '<a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">' . $row['title'] . '</a><br />';
}
$smcFunc['db_free_result']($dbresult);

This will post a list of links to your 10 latest articles, sorted by date descending.

Offline antechinus

  • PortaMx Supporter
  • *
  • Posts: 686
Re: PHP Block for SMF Articles
« Reply #1 on: 11 Mar 09, 23:57:56 »
Nice one. Thanks.
Using Internet Explorer 6 on the internet is like urinating in a public swimming pool.
It's rude, there's no excuse for it, and anyone who does it should be ashamed of themselves.

Offline fords8

  • Testing!
  • Newbie
  • *
  • Posts: 25
  • Gender: Male
    • Section 8: HQ
Re: PHP Block for SMF Articles
« Reply #2 on: 01 Apr 09, 07:10:03 »
Anyone know how I can show the summary of the articles?

I want it to output like this:

Title Here --- Summary Here

I just want the title to be clickable also. The summary is just text.

Offline fords8

  • Testing!
  • Newbie
  • *
  • Posts: 25
  • Gender: Male
    • Section 8: HQ
Re: PHP Block for SMF Articles
« Reply #3 on: 03 Apr 09, 08:24:37 »
Ok, I did some work on this and came up with:

Code: [Select]
global $smcFunc, $scripturl;

isAllowedTo('view_articles');

$dbresult = $smcFunc['db_query']('', "
SELECT a.ID_ARTICLE, a.title, a.description
FROM {db_prefix}articles AS a
WHERE a.approved = 1
ORDER BY a.date DESC
LIMIT 10
");

while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
echo '<center><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">' . $row['title'] . ' --- ' . $row['description'] . '</a></center><br />';
}
$smcFunc['db_free_result']($dbresult);

This will center the title and summary of the article in the block. It will make the whole thing clickable.

Offline antechinus

  • PortaMx Supporter
  • *
  • Posts: 686
Re: PHP Block for SMF Articles
« Reply #4 on: 04 Apr 09, 21:07:32 »
Nice job. Thanks for that.
Using Internet Explorer 6 on the internet is like urinating in a public swimming pool.
It's rude, there's no excuse for it, and anyone who does it should be ashamed of themselves.

Offline pzrzao

  • Newbie
  • *
  • Posts: 19
Re: PHP Block for SMF Articles
« Reply #5 on: 07 May 09, 07:28:18 »
I just tried this script and it is impressive!

To make it even more useful, is it possible to filter for specific articles categories?  For instance, if I have categories for Games, Hardware, Tips - how could I modify the script to show only the Games category?

Offline artus

  • Newbie
  • *
  • Posts: 9
Re: PHP Block for SMF Articles
« Reply #6 on: 16 Feb 10, 23:56:53 »
Hi,

I made a small modification to place the code in the left or right panel. I think it looks a bit better. I just can't manage to show the user who submitted the article. Maybe someone could help?

Code: [Select]
global $smcFunc, $scripturl;

isAllowedTo('view_articles');

$dbresult = $smcFunc['db_query']('', "
   SELECT a.ID_ARTICLE, a.title, a.description, a.date
   FROM {db_prefix}articles AS a
   WHERE a.approved = 1
   ORDER BY a.date DESC
   LIMIT 10
");

while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
   echo '<a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '"><strong>' . $row['title']. '</strong></a><br/> <span class="smalltext">Submitted by: '. '???'. '<br/>['. timeformat($row['date']). ']</span><hr />';

}
$smcFunc['db_free_result']($dbresult);

Offline codebirth

  • PortaMx Supporter
  • *
  • Posts: 227
  • Gender: Male
  • Dark Knight
    • My SMF 2.0 related site
Re: PHP Block for SMF Articles
« Reply #7 on: 17 Feb 10, 10:25:21 »
This should do it

Code: [Select]
global $smcFunc, $scripturl;

isAllowedTo('view_articles');

$dbresult = $smcFunc['db_query']('', "
   SELECT a.ID_ARTICLE, a.ID_MEMBER, a.title, a.description, a.date, b.real_name
   FROM {db_prefix}articles AS a
   LEFT JOIN {db_prefix}members AS b
      ON (a.ID_MEMBER=b.id_member)
   WHERE a.approved = 1
   ORDER BY a.date DESC
   LIMIT 10
");

while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
   echo '<a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '"><strong>' . $row['title']. '</strong></a><br/> <span class="smalltext">Submitted by: <a href="'. $scripturl .'?action=profile;u='. $row['ID_MEMBER'] . '">' . $row['real_name'] . '</a><br/>['. timeformat($row['date']). ']</span><hr />';

}
$smcFunc['db_free_result']($dbresult);

Haven't tested it, but hope it works.

c o d e b i r t h
http://codebirth.com/smf

Offline artus

  • Newbie
  • *
  • Posts: 9
Re: PHP Block for SMF Articles
« Reply #8 on: 17 Feb 10, 11:38:13 »
Works great! Thanks!

Here is my version for the front page:

Code: [Select]
global $smcFunc, $scripturl;

isAllowedTo('view_articles');

$dbresult = $smcFunc['db_query']('', "
   SELECT a.ID_ARTICLE, a.ID_MEMBER, a.title, a.description, a.date, b.real_name
   FROM {db_prefix}articles AS a
   LEFT JOIN {db_prefix}members AS b
      ON (a.ID_MEMBER=b.id_member)
   WHERE a.approved = 1
   ORDER BY a.date DESC
   LIMIT 10
");

while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
echo '<a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '"><strong>' . $row['title']. '</strong></a><span class="smalltext"> (Submitted by: <a href="'. $scripturl .'?action=profile;u='. $row['ID_MEMBER'] . '">' . $row['real_name'] . '</a> ['. timeformat($row['date']). '])<br/><i>'
.$row['description'] .'</i> </span><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '"><strong>Read more</strong></a><hr />';

}
$smcFunc['db_free_result']($dbresult);


Offline digiscrap

  • SMF2.0RC3+PortaMx
  • Charter Member
  • *
  • Posts: 154
  • Gender: Male
Re: PHP Block for SMF Articles
« Reply #9 on: 30 Apr 10, 18:43:40 »
Thank you! Great job!

Vincent

Offline r2d2-trader

  • Newbie
  • *
  • Posts: 9
  • Gender: Male
  • Alles wird gut!
    • Das Forex Test Forum für Trader
Re: PHP Block for SMF Articles
« Reply #10 on: 06 Jul 10, 18:24:26 »
How do i have to modify the php-code to get the articles in 2 or more rows on the frontpage?

cu Rob
"Aller Anfang ist leicht, und die letzten Stufen werden am schwersten und seltensten erstiegen."
Johann Wolfgang von Goethe