SimplePortal
Customization => Blocks and Modifications => Topic started 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 :)
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>';
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!
-
Looks cool, good job!
-
Thanks ;) Next block is going to be an Admin Block eheh ;D
-
That sounds great. Looking forward to seeing that.
-
It's done eheh :P
See for yourself:
http://simpleportal.net/index.php?topic=2206.0 (http://simpleportal.net/index.php?topic=2206.0)
-
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:
', sp_embed_image('topic'), '
That function will load any images in the 'sp' image folder. :)
-
That's a good suggestion but if I put:
', 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
-
Thanks for sharing this :-)
I have problem , i have this error:
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
-
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:
-
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
-
I'm glad I helped you ;)
-
Hi Blue,
Any chance of making this available for smf 1.1.8?
I would LOVE this mod on my portal
Thanks
Hellan
-
Maybe :P I just need to see the things I need to change.
hum... I'll try
-
Try this:
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>';
-
Thank you works great
-
i modified the code a little, but getting missing arguments 2 and 3 for db_query()
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>';
-
Hum... The code seams correct.
What do you mean by: "getting missing arguments 2 and 3 for db_query()"? :0
-
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. :(
-
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
-
Sorry for the delay, and this is for 1.1.8 :)
-
Ok, I think I know what the problem is:
in line 238 of your Subs.php says:
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:
__FILE__, __LINE__
eheh :P
So, try this in a php block and see if it works ;)
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>';
-
Working fine :) and i also found out the same last day :)
-
Glad I helped you :P
-
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 :)
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>';
-
I used this style.. This code should work on 2.0.
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..
#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
-
problem solved
-
Does this work for SMF 2.0RC3?
-
Does this work for SMF 2.0RC3?
Well, despite the fact that SMF Articles hasn't been updated yet. That block code works fine.
-
I used this style.. This code should work on 2.0.
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..
#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
-
anyone? :(
-
bump. update please :(
-
Not sure about the styling, but this code should pull up the article info:
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);
-
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:
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
-
This block is intended to work with the SMF ARTICLES mod.
-
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!
-
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.
-
in which file, enter the code css?
-
portal.css might be a good place to add CSS for blocks.
This block works with SMF ARTICLES mod.
-
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
-
Articles are just certain designated topic posts from your forum.
You can use the [cutoff] tag instead of character limit.
-
no i mean i use vb gamer articles and i want more than just a title, and expose according to how many words
-
Sorry. I slipped a gear there.
You should start by checking the options SMF ARTICLES provides for truncating articles.
-
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)
-
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.
-
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
<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>';
-
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
-
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.
-
Look: @@
Table 'mydatabase.smf1_articles' doesn't exist
Arquivo: /home/myfolder/public_html/Sources/PortalBlocks.php(3351) : eval()'d code
Linha: 9
:o
-
You must have the smf articles mod installed for this to work.