Tuesday

Add the new position {loadposition position_name} automatically in the Article


The previous lesson showed how to Add a new module position Inside an Article. In this article we will explain how to add {loadposition position_name} sentence automatically .

The first idea is to print this code when creating a new Article, that means when we click on "add new" the code appears in the editor as this:






Open the file:
/administrator/components/com_content/admin.content.html.php

and find the following code:


<?php
// parameters : areaname, content, width, height, cols, rows
echo $editor->display( 'text',  $row->text , '100%', '550', '75', '20' ) ;
?>


We need a condition to check if we are adding new article not opening old one to edit. If we don't add this condition then the code {loadposition related_position } will be added each time we update the article.

One way is to check the value of "$row->text" variable, when it is empty that means its new article.


<?php

// parameters : areaname, content, width, height, cols, rows


if (  $row->text == '' ) {echo $editor->display( 'text', $row->text.'{loadposition related_position }' , '100%', '550', '75', '20' ) ;}
else
{echo $editor->display( 'text', $row->text , '100%', '550', '75', '20' ) ;}

?>