For the first part of this tutorial, I m going to use NV recent topics as example.
When it is installed, if you had already applied attributes to topics, you'll see no attributes in the table.
Where to begin ? In a first time, let's search where the topic title is displayed in the HTML code.
So, let's open the styles/prosilver/template/recent_topics_body.html file.
Let's search
TOPIC_TITLE
(generally, MODs authors use the same variables names than the sourcecode of phpBB).We find it on line 33 :
Code: Select all
<dt style="<!-- IF recent_topics.TOPIC_ICON_IMG -->background-image: url({T_ICONS_PATH}{recent_topics.TOPIC_ICON_IMG}); background-repeat: no-repeat;<!-- ENDIF -->" title="{recent_topics.TOPIC_FOLDER_IMG_ALT}"><!-- IF recent_topics.S_UNREAD_TOPIC --><a href="{recent_topics.U_NEWEST_POST}">{NEWEST_POST_IMG}</a> <!-- ENDIF --><a href="{recent_topics.U_VIEW_TOPIC}" class="topictitle">{recent_topics.TOPIC_TITLE}</a><!-- IF U_VIEW_UNREAD_POST and not S_IS_BOT --> • <a href="{U_VIEW_UNREAD_POST}">{L_VIEW_UNREAD_POST}</a> • <!-- ENDIF -->
There is here an important information to take down, the loop name. Here, it is
recent_topics
.As the topic attribute is external of the topic title, we must now find the link of this one.
Look back, you'll find it quickly :
<a href="{recent_topics.U_VIEW_TOPIC}" class="topictitle">
Just before it, we now must add the HTML code, which will be used to display the topic attribute.
The code to add is the following :
Code: Select all
<!-- IF recent_topics.S_TOPIC_ATTR -->{recent_topics.TOPIC_ATTRIBUTE} <!-- ENDIF -->
You'll observe that we used the loop name we had taken down previously.
If our loop was named
row.foo
, we should use it and the code to add would be :Code: Select all
<!-- IF row.foo.S_TOPIC_ATTR -->{row.foo.TOPIC_ATTRIBUTE} <!-- ENDIF -->
We have now finished ... with the HTML part .
It was maybe the easiest part, but it was necessary to do it .
For information, that method is exactly the same for subsilver2
We are now going to modify the PHP file(s).
Let's open the includes/functions_recenttopics.php file, and search
TOPIC_TITLE
like earlier.We find it on line 385 :
Code: Select all
'TOPIC_TITLE' => censor_text($row['topic_title']),
There are here two important information to take down. The first concerns the content of the brackets.
If it is not
'topic_title'
, it is not the good line. The second is the variable name of the array. It corresponds to the text before the last opened bracket, and it always begin by the $ character. Here, it is $row
.So after, let's add that :
Code: Select all
//-- mod : quick title edition -------------------------------------------------
//-- add
'S_TOPIC_ATTR' => !empty($row['topic_attr_id']) ? true : false,
'TOPIC_ATTRIBUTE' => $qte->attr_display($row['topic_attr_id'], $row['topic_attr_user'], $row['topic_attr_time']),
//-- fin mod : quick title edition ---------------------------------------------
If the line was
$topic_data['topic_title']
, the variable name of the array would be $topic_data
and the code to add would be :Code: Select all
//-- mod : quick title edition -------------------------------------------------
//-- add
'S_TOPIC_ATTR' => !empty($topic_data['topic_attr_id']) ? true : false,
'TOPIC_ATTRIBUTE' => $qte->attr_display($topic_data['topic_attr_id'], $topic_data['topic_attr_user'], $topic_data['topic_attr_time']),
//-- fin mod : quick title edition ---------------------------------------------
If the line was
$row[$i]['topic_title']
, the variable name of the array would be $row[$i]
and the code to add would be :Code: Select all
//-- mod : quick title edition -------------------------------------------------
//-- add
'S_TOPIC_ATTR' => !empty($row[$i]['topic_attr_id']) ? true : false,
'TOPIC_ATTRIBUTE' => $qte->attr_display($row[$i]['topic_attr_id'], $row[$i]['topic_attr_user'], $row[$i]['topic_attr_time']),
//-- fin mod : quick title edition ---------------------------------------------
Save your modifications, and upload the files to their proper locations.
Refresh the index page.
Oups, we has a mistake message .
Fatal error: Call to a member function attr_display() on a non-object in includes/functions_recenttopics.php on line 389
Why do we have ? Because we try to call a function which is not loaded.
Let's return in the includes/functions_recenttopics.php file and go up the line.
On the line 110, we will notice we are in a function
Code: Select all
function display_recent_topics($topics_per_page, $num_pages, $excluded_topics, $tpl_loopname = 'recenttopicrow', $spec_forum_id = 0, $include_subforums = true)
If we are in a function, we must call the global variable
$qte
So, after those global variables :
Code: Select all
global $auth, $cache, $config, $db, $template, $user;
global $phpbb_root_path, $phpEx;
We add :
Code: Select all
//-- mod : quick title edition -------------------------------------------------
//-- add
global $qte;
//-- fin mod : quick title edition ---------------------------------------------
Save your file, and upload it to its proper location. Now, refresh the page.
And ... the mistake message is always here .
Where is that topics list displayed ? On the index page of course .
So now, let's open the index.php page.
Is the functions file of the MOD is loaded ? No !
Then, let's do it. Let's search :
Code: Select all
// Start session management
And let's add before :
Code: Select all
//-- mod : quick title edition -------------------------------------------------
//-- add
include_once $phpbb_root_path . 'includes/functions_attributes.' . $phpEx;
//-- fin mod : quick title edition ---------------------------------------------
I recommend you to paste those lines always before that comment.
Save your modification and upload your file to its proper location.
Refresh the page, and ... That works now .
As you can see on the screenshot, our attributes are good displayed on the topics list .
I hope that tutorial is not too hard to understand .
In reality, it's not very difficult. When you will have adapted a few MODs, you'll agree it is not so difficult .