Hi,
I have Newspaper 9.7.2 installed and have tried to follow this, https://forum.tagdiv.com/practical-example-how-to-add-a-new-block-and-module/ to create a new version of block 9 in which I have custom code (for the purposes of the learning exercise i have called it block and module 77 as per the exercise).
The php for the shortcode is,
<?php
class td_block_77 extends td_block {
static function cssMedia( $res_ctx ) {
// fonts
$res_ctx->load_font_settings( ‘f_header’ );
$res_ctx->load_font_settings( ‘f_ajax’ );
$res_ctx->load_font_settings( ‘f_more’ );
// module 77 fonts
$res_ctx->load_font_settings( ‘m77f_title’ );
$res_ctx->load_font_settings( ‘m77f_cat’ );
$res_ctx->load_font_settings( ‘m77f_meta’ );
}
public function get_custom_css() {
// $unique_block_class – the unique class that is on the block. use this to target the specific instance via css
$unique_block_class = $this->block_uid . ‘_rand’;
$compiled_css = ”;
$raw_css =
“<style>
/* @f_header */
.$unique_block_class .td-block-title a,
.$unique_block_class .td-block-title span {
@f_header
}
/* @f_ajax */
.$unique_block_class .td-subcat-list a,
.$unique_block_class .td-subcat-dropdown span,
.$unique_block_class .td-subcat-dropdown a {
@f_ajax
}
/* @f_more */
.$unique_block_class .td-load-more-wrap a {
@f_more
}
/* @m77f_title */
.$unique_block_class .td_module_77 .entry-title {
@m77f_title
}
/* @m77f_cat */
.$unique_block_class .td_module_77 .td-post-category {
@m77f_cat
}
/* @m77f_meta */
.$unique_block_class .td_module_77 .td-module-meta-info,
.$unique_block_class .td_module_7 7.td-module-comments a {
@m77f_meta
}
</style>”;
$td_css_res_compiler = new td_css_res_compiler( $raw_css );
$td_css_res_compiler->load_settings( __CLASS__ . ‘::cssMedia’, $this->get_all_atts() );
$compiled_css .= $td_css_res_compiler->compile_css();
return $compiled_css;
}
function render($atts, $content = null) {
parent::render($atts); // sets the live atts, $this->atts, $this->block_uid, $this->td_query (it runs the query)
if (empty($td_column_number)) {
$td_column_number = td_global::vc_get_column_number(); // get the column width of the block from the page builder API
}
$buffy = ”; //output buffer
$buffy .= ‘<div class=”‘ . $this->get_block_classes() . ‘ td-column-‘ . $td_column_number . ‘ td_block_padding td_block_bot_line” ‘ . $this->get_block_html_atts() . ‘>’;
//get the block js
$buffy .= $this->get_block_css();
//get the js for this block
$buffy .= $this->get_block_js();
// block title wrap
$buffy .= ‘<div class=”td-block-title-wrap”>’;
$buffy .= $this->get_block_title(); //get the block title
$buffy .= $this->get_pull_down_filter(); //get the sub category filter for this block
$buffy .= ‘</div>’;
$buffy .= ‘<div id=’ . $this->block_uid . ‘ class=”td_block_inner”>’;
$buffy .= $this->inner($this->td_query->posts); //inner content of the block
$buffy .= ‘</div>’;
//get the ajax pagination for this block
$buffy .= $this->get_block_pagination();
$buffy .= ‘</div> <!– ./block –>’;
return $buffy;
}
function inner($posts, $td_column_number = ”) {
$buffy = ”;
$td_block_layout = new td_block_layout();
if (empty($td_column_number)) {
$td_column_number = td_global::vc_get_column_number(); // get the column width of the block from the page builder API
}
$td_post_count = 0; // the number of posts rendered
$td_current_column = 1; //the current column
if (!empty($posts)) {
foreach ($posts as $post) {
$td_module_77 = new td_module_77($post, $this->get_all_atts());
switch ($td_column_number) {
case ‘1’: //one column layout
$buffy .= $td_block_layout->open12(); //added in 010 theme – span 12 doesn’t use rows
$buffy .= $td_module_77->render($post);
$buffy .= $td_block_layout->close12();
break;
case ‘2’: //two column layout
$buffy .= $td_block_layout->open_row();
$buffy .= $td_block_layout->open6(); //added in 010 theme – span 12 doesn’t use rows
$buffy .= $td_module_77->render($post);
$buffy .= $td_block_layout->close6();
if ($td_current_column == 2) {
$buffy .= $td_block_layout->close_row();
}
break;
case ‘3’: //three column layout
$buffy .= $td_block_layout->open_row();
$buffy .= $td_block_layout->open4();
$buffy .= $td_module_777->render($post);
$buffy .= $td_block_layout->close4();
if ($td_current_column == 3) {
$buffy .= $td_block_layout->close_row();
}
break;
}
//current column
if ($td_current_column == $td_column_number) {
$td_current_column = 1;
} else {
$td_current_column++;
}
$td_post_count++;
}
}
$buffy .= $td_block_layout->close_all_tags();
return $buffy;
}
}
And the php for the module is,
<?php
class td_module_77 extends td_module {
function __construct($post, $module_atts = array()) {
//run the parrent constructor
parent::__construct($post, $module_atts);
}
function render() {
ob_start();
$title_length = $this->get_shortcode_att(‘m77_tl’);
$modified_date = $this->get_shortcode_att(‘show_modified_date’);
///print_r($this->post->ID);
$choosen_post_functionality = get_field( “choose_post_functionality”, $this->post->ID );
// For Element One
$title_lo = get_field( “title_lo”, $this->post->ID );
$title_link_lo = get_field( “title_link_lo”, $this->post->ID );
$media_name_lo = get_field( “media_name_lo”, $this->post->ID );
$media_link_lo = get_field( “media_link_lo”, $this->post->ID );
$publish_date_lo = get_field( “publish_date_lo”, $this->post->ID );
//$abstract_excerpt_lo = get_field( “abstract_excerpt_lo”, $this->post->ID );
$abstract_excerpt = get_post_field(‘post_content’, $this->post->ID);
// For Element Two
$title_lt = get_field( “title_lt”, $this->post->ID );
$title_link_lt = get_field( “title_link_lt”, $this->post->ID );
$author_name_lt = get_field( “author_name_lt”, $this->post->ID );
$media_name_lt = get_field( “media_name_lt”, $this->post->ID );
$publish_date_lt = get_field( “publish_date_lt”, $this->post->ID );
$citations_title_lt = get_field( “citations_title_lt”, $this->post->ID );
$citations_link_lt = get_field( “citations_link_lt”, $this->post->ID );
//$abstract_excerpt_lt = get_field( “abstract_excerpt_lt”, $this->post->ID );
?>
<div class=”<?php echo $this->get_module_classes();?>”>
<?php if($choosen_post_functionality == “ext_lo_one”) { ?>
<div class=”item-details”>
<?php //echo $this->get_title($title_length);?>
<h3 class=”entry-title td-module-title”>” rel=”bookmark” title=”<?php echo get_the_title( $this->post->ID );//$title_lo; ?>”><?php echo get_the_title( $this->post->ID ); //$title_lo; ?></h3>
<div class=”td-module-meta-info”>
<?php //if (td_util::get_option(‘tds_category_module_77’) == ‘yes’) { echo $this->get_category(); }?>
<?php //echo $this->get_author();?>
<div class=”media_date” style=”margin-top:5px;”>
<span class=”td-post-author-name”>“><?php echo $media_name_lo; ?> <span>-</span> </span>
<?php //echo $this->get_date($modified_date);?>
<span class=”td-post-date”><time class=”entry-date updated td-module-date”><?php echo $publish_date_lo; ?></time></span>
</div>
<div class=”td-post-content” style=” margin-top: 5px; padding: 0; “><?php echo $abstract_excerpt; //$abstract_excerpt_lo; ?> </div>
<?php //echo $this->get_comments();?>
</div>
</div>
<?php } elseif($choosen_post_functionality == “ext_lo_two”) { ?>
<div class=”item-details”>
<?php //echo $this->get_title($title_length);?>
<h3 class=”entry-title td-module-title”>” rel=”bookmark” title=”<?php echo get_the_title( $this->post->ID ); ?>”><?php echo get_the_title( $this->post->ID ); ?></h3>
<div class=”td-module-meta-info”>
<?php //if (td_util::get_option(‘tds_category_module_77’) == ‘yes’) { echo $this->get_category(); }?>
<?php //echo $this->get_author();?>
<div style=”margin-top: 5px;”>
<span class=”td-post-author-name”><?php echo $author_name_lt; ?> </span>
</div>
<div class=”media_date” style=”margin-top:5px;”>
<span class=”td-post-author-name”><?php echo $media_name_lt; ?> </span>
<?php //echo $this->get_date($modified_date);?>
<span class=”td-post-date”><time class=”entry-date updated td-module-date”><?php echo $publish_date_lt; ?></time></span>
</div>
<span style=” display: block; margin-top:5px;” class=”td-post-author-name”>“><?php echo $citations_title_lt; ?> </span>
<div class=”td-post-content” style=” margin-top:5px; padding: 0;”><?php echo $abstract_excerpt; ?> </div>
<?php //echo $this->get_comments();?>
</div>
</div>
<?php }else { ?>
<div class=”item-details”>
<?php echo $this->get_title($title_length);?>
<div class=”td-module-meta-info”>
<?php if (td_util::get_option(‘tds_category_module_77’) == ‘yes’) { echo $this->get_category(); }?>
<?php echo $this->get_author();?>
<?php echo $this->get_date($modified_date);?>
<?php echo $this->get_comments();?>
</div>
</div>
<?php } ?>
<?php echo $this->get_quotes_on_blocks();?>
</div>
<?php return ob_get_clean();
}
}
I have set up the folders as per the tutorial but am not sure where to pull the two CSS files needed that set out the style for Block 9.
NOTE: I also wish to create custom block versions for the Flex Blocks.
Please can you advise as to where these are located and if any additional considerations need to be made in view of the Envato-required changes.
Finally, another question. Given the change to follow Envato rules when I come to update to a new release version will this overwrite any custom blocks?
Thanks.
Best
Gary
Hi,
That plugin has been removed, it will not work anymore with the latest theme version and future updates. There is a new plugin now with an example
– https://forum.tagdiv.com/developer-info/
We will update the documentation as soon as possible.
However I can’t say if there will be any future modifications in this matter, in coming updates. Remains to be seen. We are also working on a way to provide the same capabilities for the child theme as before the previous updates (prior to 9.7).
Thanks
Hi Simon
Thanks for getting back. I’m now confused as to hoe I use Block 9/module 8 in this new scenario.
Do I simply create a td_block_textlist.php file by copying and renaming the existing .php file for block 9 and then drop the shortcode in under the API call? (both are above)
All help appreciated
Thanks.
Best
Gary
Hi garyjones,
The new plugin differ just a little from the old one, but what you what achieve? maybe this can be achieve using the flex blocks that have more option for customize.
Why You Should Try the New Flexible Big Grids with Newspaper Theme
tagDiv Composer: Big Grid Flex elements
Thank you!
Hi Calin
I have restructured my ACF custom fields and have looked into your suggestion. As an example if I place the following code into the previous modules I mentioned, i.e. module 8 or 9, this sits appends an external URL (stored in a custom field) to the relevent post title –
<h3 class=”entry-title td-module-title”>post->ID); ?>” rel=”bookmark” title=”<?php echo get_the_title( $this->post->ID );//$title; ?>”><?php echo get_the_title( $this->post->ID ); //$title; ?></h3>
However, I can seem to get this to work with Flex Block 1.
Any help appreciated as always.
Best
G
Hi,
Please check this similar topic similar topic with custom filed, maybe you can find something that will help you -> https://forum.tagdiv.com/topic/add-additional-fields-to-posts-in-category-grid/
Thank you!