vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4.x Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=245)
-   -   vBulletin CMS Widgets - Widget: Latest Articles In Category (https://vborg.vbsupport.ru/showthread.php?t=232440)

OcR Envy 01-06-2010 10:00 PM

Widget: Latest Articles In Category
 
1 Attachment(s)
Latest Articles In Category

What is does:
vBCMS only has one option for latest articles and that is all sections and categories. This widget will allow you to display the latest articles in a specific category.

Change Log:
1.0 - Initial Release
1.1 - Updated to allow more than one category & display published date.
1.2 - Small update, no need to update unless you are using a table prefix.
1.3 - Added full page text if no previewtext row exists.
1.4 - Updated to not display unpublished articles.
1.5 - Updated read more link to be more vBulletin like.
1.6 - Small change to fix 4.0.2 [ATTACH] showing in text.

Installation:
  • Goto AdminCP-vBullietin CMS-Widgets->Create New Widget
  • Choose PHP Direct Execution as Widget's Type
  • Enter A Title IE: "Latest (Insert Your Category Name Here)"
  • Click Save
  • Click Configure
  • Remove all the default code.
  • Copy and Paste the code below first editing $category and $limit to your liking
  • Click Save
  • Goto AdminCP-vBullietin CMS-Layout Manager
  • Add the Widget to your Layout
  • Click Save
How do I find my category id?
When in your article you should see something like this:
The number after / in this case 11 is your category id.

Can I enter more than one category id?
Yes simply change $category = '11' to something like $category='11, 12, 13'

Code to copy(make sure you change $category and $limit!)
PHP Code:

// Set Your Category ID Here
$category '47';
// Set The Number of Articles To Display
$limit '1';
// Set The Height of The Thumbnail Image
$height '250';
// Set The Width of The Thumbnail Image
$width '250';


$articlegrab vB::$db->query_read("
SELECT "
.TABLE_PREFIX."cms_nodeinfo.nodeid
     , "
.TABLE_PREFIX."cms_nodeinfo.title
     , "
.TABLE_PREFIX."cms_article.previewimage
     , "
.TABLE_PREFIX."cms_article.previewtext
     , "
.TABLE_PREFIX."cms_article.pagetext
     , "
.TABLE_PREFIX."cms_article.contentid
     , "
.TABLE_PREFIX."cms_node.nodeid
     , "
.TABLE_PREFIX."cms_node.parentnode
     , "
.TABLE_PREFIX."cms_node.contentid
     , "
.TABLE_PREFIX."cms_node.url
     , "
.TABLE_PREFIX."cms_node.publishdate
     , "
.TABLE_PREFIX."cms_category.category
     , "
.TABLE_PREFIX."cms_category.categoryid 
    , "
.TABLE_PREFIX."cms_node.setpublish
  FROM "
.TABLE_PREFIX."cms_node
INNER
  JOIN "
.TABLE_PREFIX."cms_article
    ON "
.TABLE_PREFIX."cms_article.contentid = ".TABLE_PREFIX."cms_node.contentid
INNER
  JOIN "
.TABLE_PREFIX."cms_nodeinfo
    ON "
.TABLE_PREFIX."cms_nodeinfo.nodeid = ".TABLE_PREFIX."cms_node.nodeid
INNER
  JOIN "
.TABLE_PREFIX."cms_nodecategory
    ON "
.TABLE_PREFIX."cms_nodecategory.nodeid = ".TABLE_PREFIX."cms_node.nodeid
INNER
  JOIN "
.TABLE_PREFIX."cms_category
    ON "
.TABLE_PREFIX."cms_category.categoryid = ".TABLE_PREFIX."cms_nodecategory.categoryid
 WHERE "
.TABLE_PREFIX."cms_category.categoryid IN ($category)
   AND ("
.TABLE_PREFIX."cms_node.setpublish != 0)
ORDER 
    BY "
.TABLE_PREFIX."cms_node.publishdate DESC LIMIT $limit
"
);

while(
$articleinfo vB::$db->fetch_array($articlegrab)) {

    
$title $articleinfo['title'];
    
$image $articleinfo['previewimage'];
    
$text $articleinfo['previewtext'];
    
$nodeid $articleinfo['nodeid'];
    
$url $articleinfo['url'];
    
$unixdate $articleinfo['publishdate']; 
    
$date date("F j, Y, g:i a"$unixdate);  
    
$fulltext strip_bbcode($fulltext);
    
$text preg_replace('/\[ATTACH\=CONFIG\]\d\d\[\/ATTACH\]/'''$text);
    
$text strip_bbcode($text);


   if(
$text == ''$text substr($fulltext0,150);
    
    
$output .= '<center>';
    if(
$image != ''$output .= "<img src='".$image."' width='".$width."px' height='".$height."px' /><br />";
    
    
$output .= "<a href='content.php?".$nodeid."-".$url."'>".$title."</a><br /><p>Publish Date: ".$date."</p></br></center><p>".$text." <a href='content.php?".$nodeid."-".$url."'>Read More <img alt='Read More' src='images/cms/read_more-right.png' title='Read More' border='0'></a></a></p><br />";


Preview:
https://vborg.vbsupport.ru/attachmen...1&d=1265896837

For Section Mod See Here:
https://vborg.vbsupport.ru/showthread.php?p=1949493

kingMOB 01-07-2010 12:08 PM

Thank you very much OcR Envy, this should be a default widget for VB4.

I'm changing the output layout, how can I put the publishing date of the article?

Can more than one category be used in on single widget?

The widget could be modified to work with sections and sub-sections?

OcR Envy 01-07-2010 01:03 PM

There ya go king update to allow for published date & more than one category :)

For sections see my other mod here: https://vborg.vbsupport.ru/showthread.php?t=232443

1.2 Updated - Small update for users who have a table prefix should resolve any database errors. No need to update otherwise.

saYRam 01-14-2010 06:12 PM

good widget. can we do this?

i have a Section named Columnist. And there are a lot of Categories.

how can i display "Only first article" from every categories?.

i mean only one (Latest) article must listed from every cats i specified?

if there are 10 categories widget must display 10 articles from each categories.

OcR Envy 01-19-2010 09:06 AM

Sayram,

It isn't setup like that currently. You could try modifying the code a bit yourself but I don't think many people would use something like that.

Datenpapst 01-20-2010 09:08 AM

1 Attachment(s)
Hi,
I took the whole code you said just removed the align center and the hight and width of the image but still no preview text :(

I am using vb 4.0.1

OcR Envy 01-20-2010 09:15 AM

Quote:

Originally Posted by Datenpapst (Post 1960997)
Hi,
I took the whole code you said just removed the align center and the hight and width of the image but still no preview text :(

I am using vb 4.0.1

Are you willing to run some test queries for me? Or possibly give me AdminCP access to your forum?

Datenpapst 01-20-2010 09:20 AM

you got mail :)

OcR Envy 01-20-2010 11:43 AM

Updated to 1.3 no need to update unless previewtext was not appearing for you.

For some reason Daten(and I assume others) had no previewtext row in some articles. The update will pull from the full text, strip bbcode and then limit the text to 150 characters.

Datenpapst 01-22-2010 03:18 PM

possible to add the number of comments given? ^^ like:

Comments: (1)

while the (1) is a link to the comments

OcR Envy 01-22-2010 03:24 PM

Quote:

Originally Posted by Datenpapst (Post 1963499)
possible to add the number of comments given? ^^ like:

Comments: (1)

while the (1) is a link to the comments


Haha Daten you always want something more don't you? ;)

Kidding of course. I will work on that now.

Datenpapst 01-22-2010 03:39 PM

there is always something to do ;)

OcR Envy 01-22-2010 03:49 PM

Quote:

Originally Posted by Datenpapst (Post 1963518)
there is always something to do ;)

Comments are way more complicated then I thought. I'll have to put it on the back burner for the time being but eventually I'll get to it.

Datenpapst 01-22-2010 04:13 PM

maybe take the code from the recent article widget?

Naidoo 01-28-2010 02:24 PM

Nice widget ..

I have one question.
This widget is perfect for VB4 without VBSEO

How about VBSEO installed VB4 forum ..
It dont work out for me, since I have installed VBSEO

Can you help me out how to work it out

1) Changing output code ? (or)
2) Additional Custom Rewrite Code is needed in vbseo ?

Thanks in advance ..

OcR Envy 02-02-2010 03:30 PM

Quote:

Originally Posted by Naidoo (Post 1968982)
Nice widget ..

I have one question.
This widget is perfect for VB4 without VBSEO

How about VBSEO installed VB4 forum ..
It dont work out for me, since I have installed VBSEO

Can you help me out how to work it out

1) Changing output code ? (or)
2) Additional Custom Rewrite Code is needed in vbseo ?

Thanks in advance ..


What do you have your vbSEO CMS urls looking like?

OcR Envy 02-26-2010 11:40 AM

Updated to 1.6
- 4.0.2 started inserting [ATTACH] into the text fields. Simply add:

Code:

    $text =  preg_replace('/\[ATTACH\=CONFIG\]\d\d\[\/ATTACH\]/', '', $text);
    $text = strip_bbcode($text);

Before:

Code:

if($text == '') $text = substr($fulltext,  0,150);
And you should be good to go.

ahmedipa 03-10-2010 03:57 AM

so nice

Wild Bronco 04-12-2010 11:50 PM

Verry nice but I can not find a way to translate months? june etc ...

and if Image would take you to the article that would be nice-er :)

360themes 05-17-2010 10:51 PM

I can't make it work. Here is the error

Quote:

Parse error: syntax error, unexpected $end in /home/pandatec/public_html/packages/vbcms/widget/execphp.php(177) : eval()'d code on line 65
My code here:
Code:

// Set Your Category ID Here
$category = '48';
// Set The Number of Articles To Display
$limit = '2';
// Set The Height of The Thumbnail Image
$height = '50';
// Set The Width of The Thumbnail Image
$width = '50';


$articlegrab = vB::$db->query_read("
SELECT ".TABLE_PREFIX."cms_nodeinfo.nodeid
    , ".TABLE_PREFIX."cms_nodeinfo.title
    , ".TABLE_PREFIX."cms_article.previewimage
    , ".TABLE_PREFIX."cms_article.previewtext
    , ".TABLE_PREFIX."cms_article.pagetext
    , ".TABLE_PREFIX."cms_article.contentid
    , ".TABLE_PREFIX."cms_node.nodeid
    , ".TABLE_PREFIX."cms_node.parentnode
    , ".TABLE_PREFIX."cms_node.contentid
    , ".TABLE_PREFIX."cms_node.url
    , ".TABLE_PREFIX."cms_node.publishdate
    , ".TABLE_PREFIX."cms_category.category
    , ".TABLE_PREFIX."cms_category.categoryid
    , ".TABLE_PREFIX."cms_node.setpublish
  FROM ".TABLE_PREFIX."cms_node
INNER
  JOIN ".TABLE_PREFIX."cms_article
    ON ".TABLE_PREFIX."cms_article.contentid = ".TABLE_PREFIX."cms_node.contentid
INNER
  JOIN ".TABLE_PREFIX."cms_nodeinfo
    ON ".TABLE_PREFIX."cms_nodeinfo.nodeid = ".TABLE_PREFIX."cms_node.nodeid
INNER
  JOIN ".TABLE_PREFIX."cms_nodecategory
    ON ".TABLE_PREFIX."cms_nodecategory.nodeid = ".TABLE_PREFIX."cms_node.nodeid
INNER
  JOIN ".TABLE_PREFIX."cms_category
    ON ".TABLE_PREFIX."cms_category.categoryid = ".TABLE_PREFIX."cms_nodecategory.categoryid
 WHERE ".TABLE_PREFIX."cms_category.categoryid IN ($category)
  AND (".TABLE_PREFIX."cms_node.setpublish != 0)
ORDER
    BY ".TABLE_PREFIX."cms_node.publishdate DESC LIMIT $limit
");

while($articleinfo = vB::$db->fetch_array($articlegrab)) {

    $title = $articleinfo['title'];
    $image = $articleinfo['previewimage'];
    $text = $articleinfo['previewtext'];
    $nodeid = $articleinfo['nodeid'];
    $url = $articleinfo['url'];
    $unixdate = $articleinfo['publishdate'];
    $date = date("F j, Y, g:i a", $unixdate); 
    $fulltext = strip_bbcode($fulltext);
    $text = preg_replace('/\[ATTACH\=CONFIG\]\d\d\[\/ATTACH\]/', '', $text);
    $text = strip_bbcode($text);

$text =  preg_replace('/\[ATTACH\=CONFIG\]\d\d\[\/ATTACH\]/', '', $text);
    $text = strip_bbcode($text);
  if($text == '') $text = substr($fulltext, 0,150);
   
    $output .= '<center>';
    if($image != '') $output .= "<img src='".$image."' width='".$width."px' height='".$height."px' /><br />";
   
    $output .= "<a href='content.php?".$nodeid."-".$url."'>".$title."</a><br /><p>Publish Date: ".$date."</p></br></center><p>".$text." <a href='content.php?".$nodeid."-".$url."'>Read More <img alt='Read More' src='images/cms/read_more-right.png' title='Read More' border='0'></a></a></p><br />";


kingMOB 06-01-2010 01:23 PM

Hi OcR Envy,

is there a way to the widget show articles that only matchs two categories?

Something like $category = '17(but have to be in the category 49 as well),66(but have to be in the 49 category as well),67(but have to be in the 49 category as well)';

Thanks =)

NJMane 06-23-2010 09:29 PM

If i only want the TITLE of the article to show up in the widget how would i make that happen. I dont want any of the extra stuff (i.e. pictures, publish date, article text, etc.). Thanks.

Macindy 07-18-2010 05:02 PM

Hi there!

I want to show articles only which are not in a category, so I used NOT IN
But, what if the article have more categories, so now the query adds it so often how categories are there. e.g. the article have categorieids = 1,30,24
And now I say NOT IN 24 - now it shows two times, because it is not in 1 and not in 30.

Can somebody help me?

dang3rzon3 12-15-2010 08:48 PM

doesn't work with vbseo.

Exaple of link:

http://www.pianetagay.com/forum/cont...-pompieri.html
http://www.pianetagay.com/forum/cont...clericali.html

BadGuy 05-16-2011 03:57 PM

Till now still no preview text

stopchan 08-31-2011 08:12 PM

Quote:

Originally Posted by BadGuy (Post 2196388)
Till now still no preview text

For me too :(

And thumbnail proportions (heigh to width) doesn't much original image proportions. Thumbnail fits to defined into widget thumbnail height/width.

inigo 10-04-2011 09:51 AM

I am using random category,

$category = rand(1,15);

Each time (impression) the first articles of one category will be printed.

but I would like to print at the top of the widget (before the articles) the name (title) of the category, do you know how to do this?

Thanks,

S S0DEN 11-02-2011 02:42 PM

does not work 4.1.7


All times are GMT. The time now is 05:50 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01905 seconds
  • Memory Usage 1,845KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (28)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete