To use this website completely, it is necessary to store cookies on your computer.
 

* Navigator

Expand - Collapse

* Statistic

  • *Total Posts: 16403
  • *Total Topics: 2518
  • *Online Today: 8
  • *Most Online: 292
(12. Nov 2016, 09:37:31)
  • *Users: 0
  • *Guests: 0
  • *Spiders: 1
  • *Total: 1

  • *Yahoo!

PHP Block for SMF Articles

Started by DarN, 11. Mar 2009, 21:00:02

previous topic - next topic

0 Members and 0 Guests are viewing this topic.

Go Down

DarN

11. Mar 2009, 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.

antechinus

#1
11. Mar 2009, 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.

fords8

#2
01. Apr 2009, 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.

fords8

#3
03. Apr 2009, 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.

antechinus

#4
04. Apr 2009, 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.

pzrzao

#5
07. May 2009, 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?

artus

#6
16. Feb 2010, 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);

codebirth

#7
17. Feb 2010, 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

artus

#8
17. Feb 2010, 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);


digiscrap

#9
30. Apr 2010, 18:43:40
Thank you! Great job!

Vincent
Digiscrap Digitaal scrappen | Digiscrap Fotoservice

SMF2.0.5 + PortaMx v1.45
Dutch translation PortaMx1.45

r2d2-trader

#10
06. Jul 2010, 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

ben sisko

#11
19. Jan 2011, 19:29:16
i was looking for this. thank you!

what will be the change needed to show only one 'featured article' (article=x).
changing the article number by editing the block will do.

claul

#12
10. Mar 2012, 17:18:44
I have tried using this code but it breaks my forum. I created a PHP block, input code and once I make the block active everything wants to appear in my side bar. Is there another way of calling recent articles or is  this the only option?


Quote from: DarN on 11. Mar 2009, 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.

feline

#13
11. Mar 2012, 03:20:59
Which articles ? You have a mod for this installed?
I see no error in the code, but I can't say, if the query correct for that mod.

And .. isAllowedTo('view_articles') is ugly in this case .. if anyone have no access, the block i broken.
Try:
allowedTo('view_articles')
{
   code here have access
}
else
{
   say the user him have no access
}

Many are stubborn in relation to the path, a few in relation to the target.

claul

#14
17. Mar 2012, 18:06:43
I currently use the PortaMX system and create articles in it. I want to make a block that shows created articles in it and searched around here and found that code. Is there an easier way to do this?

Go Up