View Full Version : Getting the latest Article to display
Necrophyte
10-05-2016, 06:19 PM
So I'm trying to use one of the modules on my home page to list the latest article that has the tag 'spotlight' in it. Will only display the latest one, not all of them. I've no idea where to even start. I haven't figured out how to edit modules themselves yet, but I imagine I can find what I'm looking for in the 'Slider' Module.
Any hints on where or how would be awesome.
You can almost do this with the Search Module.
Using JSON:
{"tag":["spotlight"],"channel":["13"],"sort":{"created":"desc"},"view":null,"exclude_type":["vBForum_PrivateMessage"]}
Can't figure out what possible views other than compact, and topic. If there was a full, or post (Yes I tried those) and it showed the full article. That would have been awesome so there has to be another way.
noypiscripter
10-05-2016, 07:29 PM
You can use PHP module and do a search with that JSON criteria. You can style it the way you want to.
Necrophyte
10-05-2016, 08:55 PM
Glenn,
Thanks for the quick response as always. I'm lost on how I can get it to search and display the data in a PHP though. I can get the search function to find it properly, but I can't get it to display just the entire article without the click more.
Lynne
10-06-2016, 12:29 AM
So you are saying your aren't familiar with how to write PHP/MySQL code to do this or that you don't know the exact query because you are unfamiliar with the database schema?
Necrophyte
10-06-2016, 01:49 AM
I could run the queries to show but then I have BB code through out. Is there a way to parse this to HTML?
noypiscripter
10-06-2016, 02:32 AM
There's a parse function called parseNodeText in the bbcode frontend controller that you can call.
Necrophyte
10-06-2016, 03:35 AM
TY, that's what I needed to know!
--------------- Added 1475776484 at 1475776484 ---------------
For anyone that comes to this page looking for answers. You can open a PHP Module.
I wanted mine to be displayed in a max height of 800px. You can change that to what you want or remove it.
In the Query if you do not wish to have a taglist search. Just remove : 'AND taglist LIKE '%spotlight%''
You'll also need to know the nodeid for articles. Mine is 13. Change 13 to whatever your article nodeid is. You can find them in the channel manager.
Put the following code:
global $vbulletin;
echo "<div style='height: 800px; max-height: 800px; overflow: auto;'>";
$result = $vbulletin->db->query("SELECT nodeid FROM " . TABLE_PREFIX . "node WHERE parentid = 13 AND taglist LIKE '%spotlight%' ORDER BY created DESC LIMIT 1");
if ($row = $result->fetch_assoc()){
echo vB5_Frontend_Controller_Bbcode::parseNodeText($row['nodeid']);
}else{
echo "<div style='text-align: center; padding: 10px;'><h2>Could not find any articles using tag 'spotlight'</h2></div>";
}
unset($row);
unset($result);
echo "</div>";
noypiscripter
10-06-2016, 09:05 PM
You will also need to add the table prefix (if any). This is not required if the TABLE_PREFIX global variable is added in the query.
"SELECT nodeid FROM " . TABLE_PREFIX . "node ....";
There was also a typo in your CSS. Should be:
max-height: 800px;
instead of:
max-height= 800px;
Use colon instead of equal sign.
Necrophyte
11-13-2016, 02:43 PM
You are correct sir. I edited the post to use your changes.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.