Advertisement
Banner

Note to Forum Users

Please search the forum before posting. Odds are that someone has experienced your issue before and has already begun a thread. Please use the convenient Joomla! search option to identify part of your error or idea so locate existing threads before beginning a new one. This makes it much easier to locate AND supply answers. Thank you!

Support: General Support
Please use this forum to post general queries, tips, and conversation.Back to Forum List >> Back to Topic List >> VIEW ALL POSTS
how to display username in topic list?
Posted Monday, 09 March 2009 By isabel
Hi,

I need to display the topic list in such a way that it shows only 3 fields, ie:
- Topic
- Posted by
- Replies

If possible, I also want to add a short description of the message (eg. the first 100 chars)

The topic item gets displayed allright, but for the "posted by" field, I've put the <?php echo $item->name; ?> code where I want the username displayed (in topiclist>template>default.php) but it doesn't seem to do the trick..

Can somebody help me on this one? (as well as advising me how to insert the first 100 chars to be displayed as well in the topiclist?)

So, for example:
Topic - posted by - descr. - replies
Topic1 - usernameY - lorem dolor ipsum.. - 3

Many thanks in advance!!
best regards,
isabel
Subscribe to this Thread | Respond to this Message
re: user in topic list
Posted Monday, 09 March 2009 By Cullen Linn
Hello Isabel,

That information isn't currently supplied to the template. On approach to adding that functionality that I can imagine would require a couple of steps:

(1) A new method would need to be added to the /componets/som_simplestforum/models/topiclist.php file which extracts the latest post for a given topic;
(2) Add a loop in the model's getData function which iterates over the items to be returned and gets the latest post by calling the newly added latest post method
(3) Add the latest post as a new field of each topic
(4) echo the new latest post fields as desired in the template

There are other ways that would use less queries but more PHP loops, etc. but this one is quick and easy to implement. Here is some sample code:

Add at line 143 of /components/com_simplestforum/models/topiclist.php:

/**
* Returns the latest post associated with the specified topic id.
* @param $topicId int the id of the topic
* @return object the most recent post
*/
function _getLatestPost($topicId)
{
$where = array(
'a.thread = '.(int)$topicId,
);

require_once(JPATH_COMPONENT.DS.'helpers'.DS.'forum.php');
if (!ForumHelper::verifyPermissions('moderate', $this->_forumId)) {
$where[] = 'a.published = true';
}

$query = 'SELECT a.*, IF(b.id IS NOT NULL, b.name, IF(LENGTH(a.authorId) > 0 AND a.authorId != '.$this->_db->Quote('0').', a.authorId, '.$this->_db->Quote(JText::_('ANONYMOUS')).')) AS name
FROM #__simplestforum_post AS a
LEFT JOIN #__users AS b ON b.id = a.authorId
WHERE '.implode(' AND ', $where).'
ORDER BY a.date DESC
LIMIT 1'
;
$this->_db->setQuery($query);

return ($item = $this->_db->loadObject())?$item:new stdClass();
} //end _getLatestPost


Add at line 134 of /components/com_simplestforum/models/topiclist.php:

foreach ($this->_data as $topic) {
$topic->latestPost = $this->_getLatestPost($topic->id);
}



Then modify the template as you see fit taking advantage of the newly added latestPost field for each item. For example:


// display the name of the user that made the last post
echo $item->latestPost->name;

// OR display the *unprocessed* text of the last post (to process the message check out the code in /components/com_simplestforum/view/postlist/tmpl/default.php and see how it's done there
echo $item->latestPost->message;


Cheers!
Subscribe to this Thread | Respond to this Message
Can you explain that template thing
Posted Wednesday, 20 January 2010 By Simple forumist
Can you explain which template i have modify?
Subscribe to this Thread | Respond to this Message
Power by Simplest Forum - Copyright Ambitionality Software LLC 2008. All rights reserved.

Latest Posts

Login Form



Joomla Templates by Joomlashack