Hey guys,
OK, I have created the following .php page which “reads” the 5 best articles form another portal via JSON.
I don’t to mess up with extra CSS code and using iframe so I thought it would be a good idea to create a block which will show these articles. I want the block’s layout to be exactly the same as Block 1.
So, I copied all the HTML code for Block 1 and I ended up with the following:
<?php
$carStr = file_get_contents('http://www.caranddriver.gr/xml/json/getjson.asp?platform=web&ret=cu&method=oPublicationJSON.getCategoryPublications(41547,1,5)');
//Now decode the JSON using json_decode():
$carJson = json_decode($carStr, true);
// decode the JSON into an associative array
$i = 1;
?>
<?php
function trunc($phrase, $max_words) {
$phrase_array = explode(' ',$phrase);
if(count($phrase_array) > $max_words && $max_words > 0)
$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...';
return $phrase;
}
?>
<?php
echo '<div id=car>';
echo '<div class="td-block-row">
<div class="td-block-span6">
<div class="td_module_4 td_module_wrap td-animation-stack td-meta-info-hide">
<div class="td-module-image">
<div class="td-module-thumb">';
$counter = 1;
foreach ($carJson['publications'] as $row) {
$srcid = $row['src_id'];
$imgid = $row['photos'][0]['img_id'];
$img_type_small = 14000;
if($counter == 1) {
$img_type = 14001;
echo '';
echo '</div></div>';
echo '<h3 class="entry-title td-module-title">' . $row['art_title'] .'</h3>';
echo '<div class="td-module-meta-info"></div>';
echo '<div class="td-excerpt">' . $row['art_summary'] . '</div></div></div> <!-- ./td-block-span6 -->';
} //end if
else {
$img_type = 14001;
echo '<div class="td-block-span6"><div class="td_module_6 td_module_wrap td-animation-stack td-meta-info-hide"><div class="td-module-thumb">';
echo '';
echo '</div></div>';
echo '<div class="item-details"><h3 class="entry-title td-module-title">';
echo '' . $row['art_title'].'</h3>';
echo '<div class="td-module-meta-info"></div>
</div>
</div>
</div> <!-- ./td-block-span6 -->';
}//end else
$i++;
$counter++;
};// end foreach
echo '</div></div>';
?>
I went to Developer Info and read the instructions of creating a new block using a shortcode.
However, the example is simple. It doesn’t help me a lot.
Can anyone guide me to a more relative tutorial which will help me make this code to a block same as Block 1?
Thank you in advance.
Hi,
If you want to create your own custom block, you need to create it via API implementation according to our useful guide from here -> https://forum.tagdiv.com/td_api_blockadd/
As a hint, you should follow the steps where block 1 has been made and replicate it for your custom block. Also, please notice that guide is addressed only for advanced users and if you are not aware of the steps which are needed to make in this case, please consider hiring a freelancer/developer to help you because we cannot provide support for API implementation and custom work, sorry!
Thanks for your understanding!
Hi Catalin,
I have installed the td_api_plugin and I have already used Block 77, although it doesn’t show up in TDComposer.
OK, let’s say I want to create another block: Block 88.
When I go to the API tutorial, it says: “First create a folder and name it for example “td-api-plugin””
Where exactly should I do that? There is already a folder “td-api-plugin” which is part of Block 77.
What about my new Block 88? Where should I create the folder and the files needed?
should I open the same .php file and add td_api_block::add(‘td_block_88 etc?
Can you, please, be more specific?
Thank you in advance.
Hi,
If you want your block to appears in TD Composer element, this one should have to be mapped in TD Composer. If you are using the plugin, the right path should be like this
-> https://www.screencast.com/t/0dm6sH825h Please follow the next documentation if you need want to add a custom block in TD Composer from here -> https://forum.tagdiv.com/developer-info/
Hope this helps!
Thanks for your understanding!
Hi,
Please notice that here -> https://forum.tagdiv.com/practical-example-how-to-add-a-new-block-and-module/ are explained all of the steps which you need to follow. It’s not complicated. You should only download the plugin and edit the td-API-plugin.php and rename the 77 with your desired block name or simply multiplicate the code to create your own block like this -> https://www.screencast.com/t/TSyyjlCf
I hope that you understand the process!
Thanks.
