PDA

View Full Version : display last written blog article


ohadpartuck
07-12-2012, 10:49 AM
Hi,
I want to display the last written blog article on the top of my forum.
The information is in the template 'FORUMHOME' under:
{vb:raw template_hook.forumhome_wgo_stats}
but in there i get all the data I don't need also (number of blog, articles in the last 24h ).

So I need to know where can I extract the exact data I need.

Thanks
:D

kh99
07-12-2012, 11:10 AM
That's a good question - took me a while to figure it out. :) But the code that sets the blog stats on the forum home page is in the plugin "Forum Home: Process Blog Stats" (in the "Product : vBulletin Blog" section under the Plugin Manager).

ohadpartuck
07-12-2012, 12:28 PM
I found it , but how do I extract the last article tilte and who wrote it?

I tried :
1. vB_Template::preRegister('FORUMHOME',array(
'last_article' => $latestentry['blogtitle']
));
2. $template_hook['last_article'] = $latestentry['blogtitle'];

kh99
07-12-2012, 02:16 PM
Here's the structure of $vbulletin->blogstats, with junk from my test server.

Array
(
[lastentry] => Array
(
[username] => Kevin
[userid] => 1
[title] => fdsasdfafsda
[blogid] => 1
[categories] =>
[postedby_username] => Kevin
[postedby_userid] => 1
[blogtitle] =>
[guestcanview] => 1
)

[total_blog_users] => 1
[total_blog_entries] => 1
[entries_in_24hours] => 1
)



So you probably want something like:

require_once(DIR . '/includes/blog_functions_shared.php');

if (is_array($vbulletin->blogstats) AND is_array($vbulletin->blogstats['lastentry']))
{
$user = $vbulletin->blogstats['lastentry']['username'];
$userid = $vbulletin->blogstats['lastentry']['userid'];
$title = $vbulletin->blogstats['lastentry']['title'];
$url = '<a href="' . fetch_seo_url('entry', array('blogid' => $vbulletin->blogstats['lastentry']['blogid'], 'title' => $title)) .
"\">" . $title . '</a>';
}

ohadpartuck
07-12-2012, 03:15 PM
thanks kh99,
1. i think you have a mistake in the $title = $user = .. row (don't know why you did that).
2. I am trying to also get the user link to his profile
I tried several ways (non worked ):
$link = 'http://www.s-maof.com/members/' . urlencode( $userid. '-'. preg_replace("/ /","-",$user));
$userlink = '<a href="'. $link . '" \>' . $user . '</a>';

i'm sutre there is an easier way..

kh99
07-12-2012, 03:24 PM
thanks kh99,
1. i think you have a mistake in the $title = $user = .. row (don't know why you did that).

Just a cut and paste error - I was in a hurry.


2. I am trying to also get the user link to his profile
I tried several ways (non worked ):
$link = 'http://www.s-maof.com/members/' . urlencode( $userid. '-'. preg_replace("/ /","-",$user));
$userlink = '<a href="'. $link . '" \>' . $user . '</a>';

i'm sutre there is an easier way..


What I posted was just meant to be some examples of getting the info, some of which might be useful. If you're trying to make a link to the user, maybe this:

$userlink = '<a href="' . fetch_seo_url('member', array('userid' => $userid, 'username' => $user)) . '"/>' . $username . '<a/>';



(Sorry for any typos - I haven't actually tried this code).

ohadpartuck
07-15-2012, 05:25 AM
thanks, kh99, it works,
but instead of the $username , you have to use $user according to this thread example.

So the whole plug in looks like this,

require_once(DIR . '/includes/blog_functions_shared.php');

if (is_array($vbulletin->blogstats) AND is_array($vbulletin->blogstats['lastentry']))
{
$user = $vbulletin->blogstats['lastentry']['username'];
$userid = $vbulletin->blogstats['lastentry']['userid'];
$title = $vbulletin->blogstats['lastentry']['title'];
$url = '<a href="' . fetch_seo_url('entry', array('blogid' => $vbulletin->blogstats['lastentry']['blogid'], 'title' => $title)) .
"\">" . $title . '</a>';
$userlink = '<a href="' . fetch_seo_url('member', array('userid' => $userid, 'username' => $user)) . '"/>' . $user . '<a/>';
}

vB_Template::preRegister('FORUMHOME',array(
'url' => $url,
'userlink' => $userlink
));