By Kenneth Koppervik on Sunday, 04 January 2015
Posted in General Issues
Replies 11
Likes 0
Views 449
Votes 0
Hi, I was wondering if you guys could tell me how to obtain the title of the current activ blog item with php?
I want to insert the title in a custom module. thanks.
You need to add more checking to the codes above to ensure that they are on the entry view.


<?php
$view = JRequest::getVar('view');

$blog = EasyBlogHelper::getTable('blog');
$blog->load(JRequest::getVar('id')); // get the current blog id

if ($view == 'entry' && $blog->title) {
echo '<h1>' . $blog->title . '</h1>';
} else {
echo '<h1>Artikler</h1>';
}
·
Saturday, 10 January 2015 15:34
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Kenneth,

You can use this code to get the title:

$blog = EasyBlogHelper::getTable('blog');
$blog->load('3'); // 3 is the ID of the current blog.
echo $blog->title;


Hope this helps.
·
Monday, 05 January 2015 10:34
·
0 Likes
·
0 Votes
·
0 Comments
·
It worked, but its static. that would mean I have to load a module for each blog.

this is more what I need it to do:

if($blog->title){ // check if Im reading a blog item, and if so set the current blog title.

echo $blog->title;

} else{ // If not, just show standard custom title

echo "generic title";

}

Robert
·
Monday, 05 January 2015 15:39
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Robert,

Can you provide us your backend and FTP access so we can have a better look on that module?
·
Monday, 05 January 2015 16:27
·
0 Likes
·
0 Votes
·
0 Comments
·
its a mod_custom modul.. core in joomla.. I use sourcers to insert the php.

the code you provided worked, only problem was that it was static and not dynamic.
·
Monday, 05 January 2015 16:41
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Kenneth,

I am sorry for the late reply. I believe my colleague just give you an example of the code. Here I give you the fixed code. Can you try it again.

$blog = EasyBlogHelper::getTable('blog');
$blog->load(JRequest::getVar('id')); // get the current blog id
echo $blog->title;


Hope this will help.
Thanks.
·
Monday, 05 January 2015 19:46
·
0 Likes
·
0 Votes
·
0 Comments
·
nice, thanks!!

heres my working edit of your code:

<?php
$blog = EasyBlogHelper::getTable('blog');
$blog->load(JRequest::getVar('id')); // get the current blog id

if($blog->title){
echo '<h1>'.$blog->title.'</h1>'; ;

}else{

echo '<h1>'.'Artikler'.'</h1>';
}


?>



thanks,

Robert
·
Tuesday, 06 January 2015 19:25
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

You're welcome. May I ask, is your issue is resolved?

Please update us back.
·
Wednesday, 07 January 2015 00:46
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Mohd,

The code worked, but on category view it just got a random titel from the blogs insted of echoing the else statement.

Any ideas on how to fix it?

My code now:
<?php 
$blog = EasyBlogHelper::getTable('blog');
$blog->load(JRequest::getVar('id')); // get the current blog id




if($blog->title){
echo '<h1>'.$blog->title.'</h1>'; ;

}else{

echo '<h1>'.'Artikler'.'</h1>';
}


?>
·
Saturday, 10 January 2015 04:46
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Mark, That was my idea aswell, but I was not sure how to do it.

Thank you for sharing this knowledge.
·
Saturday, 10 January 2015 18:28
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Kenneth,

You're welcome.
·
Sunday, 11 January 2015 01:04
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post