SimplePortal

Customization => Blocks and Modifications => Topic started by: Blue on May 04, 2009, 09:02:08 AM

Title: A Better "SMF ARTICLES" Block
Post by: Blue on May 04, 2009, 09:02:08 AM
There is a simple block somewhere in the "custom coding" forum related to SMF Articles. It's great but It's very simple.

To that code, I added some customization. Hope you like it :)

Code: (SMF 2.0) [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 RAND()
LIMIT 5
");

echo'
<div class="smalltext" style="text-align: center; color: #216095;">
   <strong>5 Random Articles</strong>
</div>
   <hr />';

echo'
<table>';
while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
echo '
<tr>
<td align="center">', sp_embed_image('topic'), ' </td>
<td><span class="smalltext"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">' . $row['title'] . '</a></span> </td>
</tr>';
}
$smcFunc['db_free_result']($dbresult);

echo'
</table><hr />
', sp_embed_image('dot'), ' <span class="smalltext"><b><a href="' . $scripturl . '?action=articles">Read ALL Articles</a></b></span>';

Code: (SMF 1.1.X) [Select]
global $scripturl, $db_prefix;
isAllowedTo('view_articles');
$dbresult = db_query("
SELECT a.ID_ARTICLE, a.title
FROM {$db_prefix}articles AS a
WHERE a.approved = 1
ORDER BY RAND()
LIMIT 5", __FILE__, __LINE__);

echo'
<div class="smalltext" style="text-align: center; color: #216095;">
   <strong>5 Random Articles</strong>
</div>
   <hr />';

echo'
<table>';
while ($row = mysql_fetch_assoc($dbresult))
{
echo '
<tr>
<td align="center">', sp_embed_image('topic'), ' </td>
<td><span class="smalltext"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">' . $row['title'] . '</a></span></td>
</tr>';
}
mysql_free_result($dbresult);

echo'
</table><hr />
', sp_embed_image('dot'), ' <span class="smalltext"><b><a href="' . $scripturl . '?action=articles">Read ALL Articles</a></b></span>';

Edited: This document was successfully checked as XHTML 1.0 Transitional!
Title: Re: A Better "SMF ARTICLES" Block
Post by: [SiNaN] on May 04, 2009, 11:52:56 AM
Looks cool, good job!
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 04, 2009, 12:08:55 PM
Thanks ;) Next block is going to be an Admin Block eheh ;D
Title: Re: A Better "SMF ARTICLES" Block
Post by: [SiNaN] on May 04, 2009, 12:37:54 PM
That sounds great. Looking forward to seeing that.
Title: Re: [BLOCK] A Better "SMF ARTICLES" Block
Post by: Blue on May 04, 2009, 05:32:52 PM
It's done eheh :P

See for yourself:
http://simpleportal.net/index.php?topic=2206.0 (http://simpleportal.net/index.php?topic=2206.0)
Title: Re: A Better "SMF ARTICLES" Block
Post by: Nathaniel on May 04, 2009, 05:49:25 PM
Moved to the "Blocks and Modifications" board.

One thing that you could do, is use the 'sp_embed_image' function to put in the topic images. Like the code below:

Code: [Select]
', sp_embed_image('topic'), '
That function will load any images in the 'sp' image folder. :)
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 04, 2009, 06:05:42 PM
That's a good suggestion but if I put:

Code: [Select]
', sp_embed_image('dot'), ' 

The "dot" will be a random dot right? I'm asking because I saw that code in your "Who's online block"

And I can't try by myself since I'm using SP 2.1.1 (I just need the php block :P)

Even though, I'll update the block and replace for that code ;) Thanks LHVWB
Title: Re: A Better "SMF ARTICLES" Block
Post by: fotografo74 on May 07, 2009, 07:04:51 AM
Thanks for sharing this :-)
I have problem , i have this error:
Code: [Select]
Parse error: syntax error, unexpected '<' in /home/macrofor/public_html/Sources/SPortal2.php(3174) : eval()'d code on line 17

I have SMF2 RC1 and SP 2.2

My forum: www..macroforum.org

Thanks for help!
Antonio
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 07, 2009, 07:21:51 AM
I forgot an "echo'", sorry about that :-[

I've updated the code in the first post. Try it now and tell me if it works :nervous-happy:
Title: Re: A Better "SMF ARTICLES" Block
Post by: fotografo74 on May 07, 2009, 10:02:54 AM
I forgot an "echo'", sorry about that :-[

I've updated the code in the first post. Try it now and tell me if it works :nervous-happy:
Thanks, it works now!
Thanks!
Antonio
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 07, 2009, 10:59:52 PM
I'm glad I helped you ;)
Title: Re: A Better "SMF ARTICLES" Block
Post by: Hellan on May 08, 2009, 03:04:28 PM
Hi Blue,
Any chance of making this available for smf 1.1.8?
I would LOVE this mod on my portal
Thanks
Hellan
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 08, 2009, 08:01:45 PM
Maybe :P I just need to see the things I need to change. 

hum... I'll try
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 08, 2009, 10:06:34 PM
Try this:
Code: [Select]
global $scripturl, $db_prefix;
isAllowedTo('view_articles');
$dbresult = db_query("
SELECT a.ID_ARTICLE, a.title
FROM {$db_prefix}articles AS a
WHERE a.approved = 1
ORDER BY RAND()
LIMIT 5
");

echo'
<div class="smalltext" style="text-align: center; color: #216095;">
   <strong>5 Random Articles</strong>
</div>
   <hr />';

echo'
<table>';
while ($row = mysql_fetch_assoc($dbresult))
{
echo '
<tr>
<td align="center">', sp_embed_image('topic'), ' </td>
<td><span class="smalltext"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">' . $row['title'] . '</a></span></td>
</tr>';
}
mysql_free_result($dbresult);

echo'
</table>
<hr>
', sp_embed_image('dot'), ' <span class="smalltext"><font color="#000000"><b><a href="' . $scripturl . '?action=articles">Read ALL Articles</a></b></span>';
Title: Re: A Better "SMF ARTICLES" Block
Post by: Hellan on May 09, 2009, 07:19:16 AM
Thank you works great
Title: Re: A Better "SMF ARTICLES" Block
Post by: techprince on May 10, 2009, 05:29:28 PM
i modified the code a little, but getting missing arguments 2 and 3 for db_query()

Code: [Select]
global $scripturl, $db_prefix;
isAllowedTo('view_articles');
$dbresult = db_query("
SELECT a.ID_ARTICLE, a.title, a.commenttotal
FROM {$db_prefix}articles AS a
WHERE a.approved = 1
ORDER BY a.date DESC
LIMIT 8
");

echo'
<table>';
while ($row = mysql_fetch_assoc($dbresult))
{
echo '
<tr>
<td align="center" style="padding:6px;">', sp_embed_image('topic'), ' </td>
<td><span class="smalltext"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">' . $row['title'] . '  (' . $row['commenttotal'] . ')</a></span></td>
</tr>';
}
mysql_free_result($dbresult);

echo'
</table>
<hr>
', sp_embed_image('dot'), ' <span class="smalltext"><font color="#000000"><b><a href="' . $scripturl . '?action=articles">Read ALL Reviews</a></b></span>';
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 10, 2009, 05:50:46 PM
Hum... The code seams correct.

What do you mean by: "getting missing arguments 2 and 3 for db_query()"? :0
Title: Re: A Better "SMF ARTICLES" Block
Post by: techprince on May 10, 2009, 06:02:14 PM
I am getting these errors in Forum Log, though the output is clean.

2: Missing argument 2 for db_query(), called in /Sources/SPortal1-1.php(3244) : eval()'d code on line 9 and defined
File: /Sources/Subs.php
Line: 238

2: Missing argument 3 for db_query(), called in /Sources/SPortal1-1.php(3244) : eval()'d code on line 9 and defined
File: /Sources/Subs.php
Line: 238


These errors are from this block only. :(
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 10, 2009, 06:09:40 PM
Hum.. This is very odd :'( I don't know what's wrong with the block. In smf 2.0 block i'm not getting any error.

Can you attach your Subs.php? Maybe the problem is from it
Title: Re: A Better "SMF ARTICLES" Block
Post by: techprince on May 10, 2009, 06:28:47 PM
Sorry for the delay, and this is for 1.1.8 :)
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 10, 2009, 11:15:55 PM
Ok, I think I know what the problem is:

in line 238 of your Subs.php says:
Code: [Select]
function db_query($db_string, $file, $line)
Well, I'm a SMF 2.0 User not and 1.1.x so I didn't knew what was happening. I searched a bit and found that SMF 1.1.x needs arguments for $file and $line.

In other words, it needs this when we do a query:
Code: [Select]
__FILE__, __LINE__
eheh :P

So, try this in a php block and see if it works ;)
Code: [Select]
global $scripturl, $db_prefix;
isAllowedTo('view_articles');
$dbresult = db_query("
SELECT a.ID_ARTICLE, a.title, a.commenttotal
FROM {$db_prefix}articles AS a
WHERE a.approved = 1
ORDER BY a.date DESC
LIMIT 8", __FILE__, __LINE__);

echo'
<table>';
while ($row = mysql_fetch_assoc($dbresult))
{
echo '
<tr>
<td align="center" style="padding:6px;">', sp_embed_image('topic'), ' </td>
<td><span class="smalltext"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">' . $row['title'] . '  (' . $row['commenttotal'] . ')</a></span></td>
</tr>';
}
mysql_free_result($dbresult);

echo'
</table>
<hr>
', sp_embed_image('dot'), ' <span class="smalltext"><font color="#000000"><b><a href="' . $scripturl . '?action=articles">Read ALL Reviews</a></b></span>';
Title: Re: A Better "SMF ARTICLES" Block
Post by: techprince on May 11, 2009, 01:58:23 PM
Working fine :) and i also found out the same last day :)
Title: Re: A Better "SMF ARTICLES" Block
Post by: Blue on May 11, 2009, 02:05:06 PM
Glad I helped you :P
Title: Re: A Better "SMF ARTICLES" Block
Post by: techprince on May 11, 2009, 02:15:59 PM
There is no Karma system enabled here or else i would have repped you :) Thanks for everything :D

And yes, here is the XHTML Transitional Valid Code for Latest Articles :)

Code: [Select]
global $scripturl, $db_prefix;
isAllowedTo('view_articles');
$dbresult = db_query("
SELECT a.ID_ARTICLE, a.title, a.commenttotal
FROM {$db_prefix}articles AS a
WHERE a.approved = 1
ORDER BY a.date DESC
LIMIT 8", __FILE__, __LINE__);

echo'
<table>';
while ($row = mysql_fetch_assoc($dbresult))
{
echo '
<tr>
<td style="text-align:center;padding:6px;">', sp_embed_image('topic'), ' </td>
<td><span class="smalltext"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">' . $row['title'] . '  (' . $row['commenttotal'] . ')</a></span></td>
</tr>';
}
mysql_free_result($dbresult);

echo'
</table><hr />
', sp_embed_image('dot'), ' <span class="smalltext"><i><b><a href="' . $scripturl . '?action=articles">Read ALL Reviews</a></b></i></span>';
Title: Re: A Better "SMF ARTICLES" Block
Post by: Daydreamer on June 02, 2009, 07:20:03 PM
I used this style.. This code should work on 2.0.
Code: [Select]
function makale()
{
global $smcFunc, $scripturl;
isAllowedTo('view_articles');
$dbresult = $smcFunc['db_query']('', "
SELECT a.ID_ARTICLE, a.title, a.description, a.ID_CAT, imageurl
FROM {db_prefix}articles AS a
LEFT JOIN {db_prefix}articles_cat AS c ON (a.ID_CAT = c.ID_CAT)
WHERE a.approved = 1
ORDER BY a.date DESC
LIMIT 6
");
echo'<div class="clearfloat" id="article">';
while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
echo '
<div class="clearfloat" style="border-bottom:1px solid #111111;">
<a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">
   <img src="' . $row['imageurl'] . '" alt="',$item['title'],'"  class="left" />
   </a>
   <div class="info"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '" class="title">',shorten_subject($row['title'], 50),'</a><br />
  <div class="meta" style="font-size:10px;">',shorten_subject($row['description'], 100), '</div>
</div></div>
';
}
echo'</div>';
$smcFunc['db_free_result']($dbresult);
}
makale();
This style code requires..
Code: [Select]
#article .info {
padding:5px 0;
width:190px;
}
#article .clearfloat {
margin-bottom:8px;
margin-top:7px;
display:block;
}
#article a img {
margin-right:10px;
margin-top:2px;
padding:5px 0;
}
.left, .alignleft {
float:left;
}
Seems like in attachment
Title: Re: A Better "SMF ARTICLES" Block
Post by: primetime on August 04, 2009, 11:05:15 PM
problem solved
Title: Re: A Better "SMF ARTICLES" Block
Post by: kcmartz on April 18, 2010, 07:38:20 PM
Does this work for SMF 2.0RC3?
Title: Re: A Better "SMF ARTICLES" Block
Post by: Nathaniel on April 19, 2010, 03:02:25 AM
Does this work for SMF 2.0RC3?

Well, despite the fact that SMF Articles hasn't been updated yet. That block code works fine.
Title: Re: A Better "SMF ARTICLES" Block
Post by: haito on July 14, 2010, 12:10:56 AM
I used this style.. This code should work on 2.0.
Code: [Select]
function makale()
{
global $smcFunc, $scripturl;
isAllowedTo('view_articles');
$dbresult = $smcFunc['db_query']('', "
SELECT a.ID_ARTICLE, a.title, a.description, a.ID_CAT, imageurl
FROM {db_prefix}articles AS a
LEFT JOIN {db_prefix}articles_cat AS c ON (a.ID_CAT = c.ID_CAT)
WHERE a.approved = 1
ORDER BY a.date DESC
LIMIT 6
");
echo'<div class="clearfloat" id="article">';
while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
echo '
<div class="clearfloat" style="border-bottom:1px solid #111111;">
<a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">
   <img src="' . $row['imageurl'] . '" alt="',$item['title'],'"  class="left" />
   </a>
   <div class="info"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '" class="title">',shorten_subject($row['title'], 50),'</a><br />
  <div class="meta" style="font-size:10px;">',shorten_subject($row['description'], 100), '</div>
</div></div>
';
}
echo'</div>';
$smcFunc['db_free_result']($dbresult);
}
makale();
This style code requires..
Code: [Select]
#article .info {
padding:5px 0;
width:190px;
}
#article .clearfloat {
margin-bottom:8px;
margin-top:7px;
display:block;
}
#article a img {
margin-right:10px;
margin-top:2px;
padding:5px 0;
}
.left, .alignleft {
float:left;
}
Seems like in attachment
it doesnt work anymore :'(
update please
Title: Re: A Better "SMF ARTICLES" Block
Post by: haito on July 17, 2010, 12:06:07 AM
anyone? :(
Title: Re: A Better "SMF ARTICLES" Block
Post by: haito on August 01, 2010, 05:41:06 AM
bump. update please  :(
Title: Re: A Better "SMF ARTICLES" Block
Post by: excaliburj on August 02, 2010, 01:42:06 PM
Not sure about the styling, but this code should pull up the article info:

Code: [Select]
global $smcFunc, $scripturl;
isAllowedTo('view_articles');
$dbresult = $smcFunc['db_query']('', "
SELECT a.ID_ARTICLE, a.title, a.description, a.ID_CAT, imageurl
FROM {db_prefix}articles AS a
LEFT JOIN {db_prefix}articles_cat AS c ON (a.ID_CAT = c.ID_CAT)
WHERE a.approved = 1
ORDER BY a.date DESC
LIMIT 6", array());

echo'<div class="clearfloat" id="article">';
while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
echo '
<div class="clearfloat" style="border-bottom:1px solid #111111;">
<a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '">
   <img src="' . $row['imageurl'] . '" alt="',$item['title'],'"  class="left" />
   </a>
   <div class="info"><a href="' . $scripturl . '?action=articles;sa=view;article=' . $row['ID_ARTICLE'] . '" class="title">',shorten_subject($row['title'], 50),'</a><br />
  <div class="meta" style="font-size:10px;">',shorten_subject($row['description'], 100), '</div>
      </div></div>
';
}
echo'</div>';
$smcFunc['db_free_result']($dbresult);
Title: Re: A Better "SMF ARTICLES" Block
Post by: Morph on November 19, 2010, 06:37:39 AM
i'm sorry for the question, i don't understand well, maybe the language.
Where can i put that code? i try to add a php block with this code on my sp 2.3.1, but i obtain this error:

Code: [Select]
Table 'Sql215428_4.smf_articles' doesn't exist
File: /web/htdocs/www.nkgcommunity.it/home/forumb/Sources/PortalBlocks.php(3461) : eval()'d code
Linea: 8

I naturally use simple portal articles...

Many thanks
Title: Re: A Better "SMF ARTICLES" Block
Post by: AngelinaBelle on November 19, 2010, 08:20:06 AM
This block is intended to work with the SMF ARTICLES mod.
Title: Re: A Better "SMF ARTICLES" Block
Post by: Morph on November 19, 2010, 09:45:30 AM
oh, so, i have to install this mod:
http://custom.simplemachines.org/mods/index.php?mod=1354
and then i must add a php block with the code that i can find in this topic.
Is it correct?
Thank you again!
Title: Re: A Better "SMF ARTICLES" Block
Post by: AngelinaBelle on November 19, 2010, 11:05:40 AM
I think that is the general idea.
 
It is also possible to simply use the SimplePortal articles system, and use a SimplePortal articles block.  Please give it a try and see if it does what you need it to do.  I think the idea of SMF ARTICLES is a bit more akin to SimplePortal pages. But not exactly.
Title: Re: A Better "SMF ARTICLES" Block
Post by: fdr77 on December 10, 2010, 09:09:19 PM
in which file,  enter the code css?
Title: Re: A Better "SMF ARTICLES" Block
Post by: AngelinaBelle on December 12, 2010, 10:50:14 PM
portal.css might be a good place to add CSS for blocks.
This block works with SMF ARTICLES mod.
Title: Re: A Better "SMF ARTICLES" Block
Post by: barbar on January 17, 2011, 05:09:17 PM
how can i set the limit for number of characters per article and also display the embeded video? i dont use my forums so i cant use simple articles
Title: Re: A Better "SMF ARTICLES" Block
Post by: AngelinaBelle on January 17, 2011, 05:16:28 PM
Articles are just certain designated topic posts from your forum.
You can use the [cutoff] tag instead of character limit.
Title: Re: A Better "SMF ARTICLES" Block
Post by: barbar on January 18, 2011, 02:29:44 AM
no i mean i use vb gamer articles and i want more than just a title, and expose according to how many words
Title: Re: A Better "SMF ARTICLES" Block
Post by: AngelinaBelle on January 18, 2011, 08:55:54 AM
Sorry.  I slipped a gear there.
You should start by checking the options SMF ARTICLES provides for truncating articles.
Title: Re: A Better "SMF ARTICLES" Block
Post by: lgice on March 15, 2011, 07:31:13 PM
I was wondering if it was possible to add something like this for the SMF article system, where you have the latest articles in a list on the right and a slideshow of them from top to bottom and then it showing maybe a background image and a small bit of the article in the larger space. any help by any chance or is this even possible?

(http://img14.imageshack.us/img14/8615/articlesr.th.jpg) (http://img14.imageshack.us/i/articlesr.jpg/)

Uploaded with ImageShack.us (http://imageshack.us)
Title: Re: A Better "SMF ARTICLES" Block
Post by: AngelinaBelle on March 15, 2011, 09:05:23 PM
This is most likely possible.
You would have to go through the code for SMF ARTICLES, find the bits you want, and pop them into a php block.


Sounds like quite a bit of custom coding.
Title: Re: A Better "SMF ARTICLES" Block
Post by: lgice on March 25, 2011, 05:13:30 PM
could anyone tell me what part of the code actually displays the 5 articles im trying to write something for a block here is what i have

Code: [Select]
<center>
<table
 style="text-align: left; width: 800px; height: 280px;"
 border="1" cellpadding="2" cellspacing="2">
  <tbody>
    <tr>
      <td style="width: 558px;">
<marquee direction="left" scrolldelay="120">
<a href="http://www.realgamers.org/index.php?action=articles;sa=view;article=1">
<img src="http://i56.tinypic.com/21kk02g.jpg" width="380" height="280"></a>

<a href="http://www.realgamers.org/index.php?action=articles;sa=view;article=1">
<img src="http://i52.tinypic.com/23j07z9.jpg" width="380" height="280"></a>

<a href="http://www.realgamers.org/index.php?action=articles;sa=view;article=1">
<img src="http://i53.tinypic.com/1zc2v04.gif" width="380" height="280"></a>
</marquee></td>
      <td style="width: 222px;">Latest Article List Will Go Here

I WANT THE LIST OF 5 OR MORE ARTICLES TO GO HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

</td>
    </tr>
  </tbody>
</table>
</center>





', sp_embed_image('dot'), ' <span class="smalltext"><font color="#CCCCCC"><b><a href="' . $scripturl . '?action=articles">Read ALL Articles</a></b></span>';

Title: Re: [BLOCK] A Better "SMF ARTICLES" Block
Post by: donidion on April 08, 2011, 06:35:25 AM
It's done eheh :P

See for yourself:
http://simpleportal.net/index.php?topic=2206.0 (http://simpleportal.net/index.php?topic=2206.0)

hi nice to see you,thanks
Title: Re: A Better "SMF ARTICLES" Block
Post by: robotron on June 03, 2011, 11:25:08 PM
how I can implement the code in smf 1.1.13?

I have this error when testing the code:

Note: It appears that your database may require an upgrade. The version of your forum files are in SMF version 1.1.13, while your database is in the version of SMF 1.1.12. I suggest running the latest version of upgrade.php.




Title: Re: A Better "SMF ARTICLES" Block
Post by: EvilGeneral on August 19, 2011, 02:11:42 PM
Look: @@

Quote
Table 'mydatabase.smf1_articles' doesn't exist
Arquivo: /home/myfolder/public_html/Sources/PortalBlocks.php(3351) : eval()'d code
Linha: 9

 :o
Title: Re: A Better "SMF ARTICLES" Block
Post by: AngelinaBelle on August 22, 2011, 08:37:21 AM
You must have the smf articles mod installed for this to work.
SimplePortal 2.3.8 © 2008-2024, SimplePortal