Issue with the theme api plugin (probably url or path problem)

Posted in: Newspaper
Post count: 101

Hello,
I had made two custom modules, editing the td config file directly. Upon updating the theme I quickly found out I should have used the theme api plugin to avoid having everything erased. However I can’t get it to work.

I followed the tutorial offered on the site, creating the td-api-plugin folder and php file.
The php file includes following text, do I need to alter the $this->plugin_url and $this->plugin_path ?
If so how would I need to do this.

I am working with a newspaper-child theme and the address of the site is currently v2.enola.be,
which will change in the future to http://www.enola.be so I want to be prepared for that too.

thanks for your kind assistance

Nick

<?php
/*
Plugin Name: td-api-plugin
Plugin URI: http://tagdiv.com
Description: tagDiv API plugin
Author: tagDiv
Version: 1.0
Author URI: http://tagdiv.com
*/
class td_api_plugin {
var $plugin_url = '';
var $plugin_path = '';
function __construct()
{
$this->plugin_url = plugins_url('', __FILE__); // path used for elements like images, css, etc which are available on end user
$this->plugin_path = dirname(__FILE__); // used for internal (server side) files

add_action('td_global_after', array($this, 'hook_td_global_after')); // hook used to add or modify items via Api
}
function hook_td_global_after() {

//Add new modules

td_api_module::add('td_module_20',
array(
'file' => $this->plugin_path . "/includes/modules/td_module_20.php",
'text' => 'Module 20',
'img' => $this->plugin_url . '/images/panel/modules/td_module_20.png',
'used_on_blocks' => array('td_block_25'),
'excerpt_title' => 30,
'excerpt_content' => 50,
'enabled_on_more_articles_box' => false,
'enabled_on_loops' => true,
'uses_columns' => true, // if the module uses columns on the page template + loop
'category_label' => true,
'class' => 'td_module_wrap td-animation-stack',
'group' => '' // '' - main theme, 'mob' - mobile theme, 'woo' - woo theme
)
);

td_api_module::add('td_module_21',
array(
'file' => $this->plugin_path . "/includes/modules/td_module_21.php",
'text' => 'Module 21',
'img' => $this->plugin_url . '/images/panel/modules/td_module_21.png',
'used_on_blocks' => array('td_block_21'),
'excerpt_title' => 15,
'excerpt_content' => '',
'enabled_on_more_articles_box' => true,
'enabled_on_loops' => true,
'uses_columns' => true, // if the module uses columns on the page template + loop
'category_label' => true,
'class' => 'td_module_wrap',
'group' => '' // '' - main theme, 'mob' - mobile theme, 'woo' - woo theme
)
);

}
}

new td_api_plugin();

Post count: 20688

Hi,

So you want to add new modules by API. There may be a different way to have custom modules. The new flex blocks have a considerable amount of options, all aspects of the module can be customized
https://demo.tagdiv.com/newspaper/flex-block/
One flex block can be used and modified to look in endless ways. It would also be easier then adding modules, you could give it a try.

Post count: 101

I’ll look into it, will probably come in handy for the front page.
we’d like to use this however on a category page, would this method work there as well ?
http://v2.enola.be/category/muziek/muziek-recensies/

Post count: 101

ok I think I got it. I had created custom category pages by hand, but I can now make a page via tagdiv, display the category I choose and adjust accordingly.

two questions though.
I want to add in an additional menu below like the way it is shown currently on http://v2.enola.be/category/muziek/muziek-recensies/

Also I need to set the image size to be square, is there any place I can set this ?

Post count: 20688

Indeed, the category templates can now be created with the tagDiv composer and cloud library plugin, use any elements available. We will add more beautiful ready made templates in coming updates.

So you are referring to this menu? – https://www.screencast.com/t/IatOqgCMPu
That seems to be made with a plugin or some other implementation, can’t say exactly. You could use the list menu element instead
https://www.screencast.com/t/4u8sycOspJ

The thumbnails in the post loop section in the cloud category templates can be modified, the loop uses a flex module
https://www.screencast.com/t/JFgzUSts

Post count: 101

the menu was made via wordpress itself. odd thing is that I can get menu to show there, but ticking the box inline doesnt alter it, it keeps showing as a list though. might have to add some additional css there.

Post count: 101

Also, the need to implement the api is still there.
We have painstakingly created a custom “alphabetical letter” taxonomy to display all posts on one page using a keyword, all posts that have keyword A on page A etc etc.

However since we can not select a custom taxonomy on the tagdiv composer when filtering posts (only categories are allowed) we are stuck.

We have implemented this text into the plugin, which gets us the ARTICLE DISPLAY VIEW icons on the theme panel. however when we select them the page reverts back to the default. could you point us in the right direction please ?

<?php
/*
Plugin Name: td-api-plugin
Plugin URI: http://tagdiv.com
Description: tagDiv API plugin
Author: tagDiv
Version: 1.0
Author URI: http://tagdiv.com
*/
class td_api_plugin {
    var $plugin_url = '';
    var $plugin_path = '';
    var $root = '';
    function __construct()
    {
        $this->root = get_site_url();
        $this->plugin_url = plugins_url('', __FILE__); // path used for elements like images, css, etc which are available on end user
        $this->plugin_path = dirname(__FILE__); // used for internal (server side) files

        add_action('td_global_after', array($this, 'hook_td_global_after')); // hook used to add or modify items via Api
    }
    function hook_td_global_after() {

//Add new modules
   
td_api_module::add('td_module_20',
            array(              
                'file' => $this->root . "/wp-content/themes/newspaper-child/includes/modules/td_module_20.php",
                'text' => 'Module 20',
                'img' =>  $this->root . '/wp-content/themes/newspaper-child/images/panel/modules/td_module_20.png',
                'used_on_blocks' => array('td_block_25'),
                'excerpt_title' => 30,
                'excerpt_content' => 50,
                'enabled_on_more_articles_box' => false,
                'enabled_on_loops' => true,
                'uses_columns' => true,                      // if the module uses columns on the page template + loop
                'category_label' => true,
                'class' => 'td_module_wrap td-animation-stack',
                'group' => '' // '' - main theme, 'mob' - mobile theme, 'woo' - woo theme
            )
        );

        td_api_module::add('td_module_21',
            array(
                'file' => $this->root . "/wp-content/themes/newspaper-child/includes/modules/td_module_21.php",
                'text' => 'Module 21',
                'img' => $this->root . '/wp-content/themes/newspaper-child/images/panel/modules/td_module_21.png',
                'used_on_blocks' => array('td_block_21'),
                'excerpt_title' => 15,
                'excerpt_content' => '',
                'enabled_on_more_articles_box' => true,
                'enabled_on_loops' => true,
                'uses_columns' => true,                      // if the module uses columns on the page template + loop
                'category_label' => true,
                'class' => 'td_module_wrap',
                'group' => '' // '' - main theme, 'mob' - mobile theme, 'woo' - woo theme
            )
        );

    }
}

new td_api_plugin();

the text in module 20 for instance looks like this:

<?php

class td_module_20 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('m20_tl');
        ?>

        <div class="<?php echo $this->get_module_classes();?>">
            <div class="td-module-image">
                <?php echo $this->get_image('td_150x150');?>
                <?php if (td_util::get_option('tds_category_module_20') == 'yes') { echo $this->get_category(); }?>
            </div>
            <?php echo $this->get_title($title_length);?>

            <div class="td-module-meta-info">
                <?php echo $this->get_author();?>
                <?php echo $this->get_date();?>
                <?php echo $this->get_comments();?>
            </div>

            <?php echo $this->get_quotes_on_blocks();?>

        </div>

        <?php return ob_get_clean();
    }
}

We have created pages for each letter which each run their specific post template, which looks like this:
<?php
/*
Template Name: archief albumrecensie a
*/

get_header();

//set the template id, used to get the template specific settings
$template_id = 'archive';

//prepare the loop variables
global $loop_module_id, $loop_sidebar_position, $part_cur_auth_obj;
$loop_module_id = td_util::get_option('tds_' . $template_id . '_page_layout', 1); //module 1 is default
$loop_sidebar_position = td_util::get_option('tds_' . $template_id . '_sidebar_pos'); //sidebar right is default (empty)

// sidebar position used to align the breadcrumb on sidebar left + sidebar first on mobile issue
$td_sidebar_position = '';
if($loop_sidebar_position == 'sidebar_left') {
$td_sidebar_position = 'td-sidebar-left';
}

//read the current author object - used by here in title and by /parts/author-header.php
$part_cur_auth_obj = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));

//prepare the archives page title
{
$td_archive_title = get_the_title();
}

?>

<div class="td-main-content-wrap td-container-wrap">
<div class="td-container <?php echo $td_sidebar_position; ?>">
<div class="td-crumb-container">
<?php echo td_page_generator::get_archive_breadcrumbs(); // get the breadcrumbs - /includes/wp_booster/td_page_generator.php ?>
</div>
<div class="td-pb-row">
<?php
switch ($loop_sidebar_position) {
default:
?>
<div class="td-pb-span8 td-main-content">
<div class="td-ss-main-content">
<div class="td-page-header">
<h1 class="entry-title td-page-title">
<span><?php echo $td_archive_title; ?></span>
</h1>
</div>

<?php locate_template('loop-albumrecensies-a.php', true);?>

<?php echo td_page_generator::get_pagination(); // get the pagination - /includes/wp_booster/td_page_generator.php ?>
</div>
</div>

<div class="td-pb-span4 td-main-sidebar">
<div class="td-ss-main-sidebar">
<?php get_sidebar(); ?>
</div>
</div>
<?php
break;

case 'sidebar_left':
?>
<div class="td-pb-span8 td-main-content <?php echo $td_sidebar_position; ?>-content">
<div class="td-ss-main-content">
<div class="td-page-header">
<h1 class="entry-title td-page-title">
<span><?php echo $td_archive_title; ?></span>
</h1>
</div>

<?php locate_template('loop-albumrecensies-a.php', true);?>

<?php echo td_page_generator::get_pagination(); // get the pagination - /includes/wp_booster/td_page_generator.php ?>
</div>
</div>
<div class="td-pb-span4 td-main-sidebar">
<div class="td-ss-main-sidebar">
<?php get_sidebar(); ?>
</div>
</div>
<?php
break;

case 'no_sidebar':
?>
<div class="td-pb-span12 td-main-content">
<div class="td-ss-main-content">
<div class="td-page-header">
<h1 class="entry-title td-page-title">
<span><?php echo $td_archive_title; ?></span>
</h1>
</div>
<?php locate_template('loop-albumrecensies-a.php', true);?>

<?php echo td_page_generator::get_pagination(); // get the pagination - /includes/wp_booster/td_page_generator.php ?>
</div>
</div>
<?php
break;
}
?>
</div> <!-- /.td-pb-row -->

<div class="archiefmenutitel"></br></br><h1 class="entry-title td-page-title">ARCHIEF</h1></div>
<div class="albumrecensiesabc">
<?php wp_nav_menu( array( 'theme_location' => 'albumrecensiesabc' ) ); ?>
</div>
</div> <!-- /.td-container -->
</div> <!-- /.td-main-content-wrap -->

<?php
get_footer();

and finally the loop it uses
<?php
/**
* If you are looking for the loop that's handling the single post page (single.php), check out loop-single.php
**/

// $global_flag_to_hide_no_post_to_display - comes from page-category-big-grid.php and is a flag to hide the 'No posts to display' message if on category page there are between 1 and 5 posts
global $loop_module_id, $loop_sidebar_position, $global_flag_to_hide_no_post_to_display;

///if we are in wordpress loop; used by quotes in blocks to check if the blocks are displayed in blocks or in loop
td_global::$is_wordpress_loop = true;

$td_template_layout = new td_template_layout($loop_sidebar_position);

if (empty($loop_module_id)) { //not sure if we need a default here
$loop_module_id = 1;
}

$td_module_class = td_api_module::_helper_get_module_class_from_loop_id($loop_module_id);

//disable the grid for some of the modules
$td_module = td_api_module::get_by_id($td_module_class);
if ($td_module['uses_columns'] === false) {
$td_template_layout->disable_output();
}

$args = array(
'post_type' => 'post',
'posts_per_page' => '-1',
'meta_key' => 'keyword',
'orderby' => 'meta_value',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'alphabetical_letter',
'field' => 'term_id',
'terms' => array( '441' ), //this is by slug
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'muziek-recensies' ), //this is by id
),
),

);

// The Query
query_posts( $args );

// The Loop

if (have_posts()) {
while ( have_posts() ) : the_post();
echo $td_template_layout->layout_open_element();

if (class_exists($td_module_class)) {
$td_mod = new $td_module_class($post);
echo $td_mod->render();
} else {
td_util::error(__FILE__, 'Missing module: ' . $td_module_class);
}

echo $td_template_layout->layout_close_element();
$td_template_layout->layout_next();
endwhile; //end loop
echo $td_template_layout->close_all_tags();

} else {
/**
* no posts to display. This function generates the __td('No posts to display').
* the text can be overwritten by the themplate using the global @see td_global::$custom_no_posts_message
*/

echo td_page_generator::no_posts();
}

all of this was working fine since all of the code was directly implemented in the td config php file, which gets overwritten when you update the theme. all I thought I would have to do is implement the said code in the plugin api but clearly this isn’t how it should be done. I’m fearful that weeks of work on this alphabetical archive have been for nought…

Post count: 22421

Hello,

Unfortunately, the theme api does not allow this kind of implementation to be done through a plugin. If you alter the main theme php files, you will have to re-apply the modification after updating. There is no update proof way of customizing the theme files. Sorry

Thanks

Post count: 101

Ok.

The tagdiv composer uses categories but not custom taxonomies to choose from to display a list of posts.

However it does support custom post type. Is it possible to show custom posts, with the custom taxonomy “alphabetical letter” ?

For instance the cd “Blackstar” would have category “albumreview” and alphabetical letter “ B”

If i can make a custom post type alphabetical letter, show the a,b,c… taxonomy there, would the tagduv composer then show a drop down list of the custom post type with the alphabet in it ?

If so what would be a good way to achieve this ?

Post count: 20688

The blocks for example can display custom post types and you can sort them by alphabetical order. But the posts can’t be filtered by a taxonomy.

The theme is somewhat limited when it comes to custom post types and taxonomies. I am not aware of any plans to expand the options and capabilities of the theme in the matter. All there is at the moment would be the settings mentioned in this guide
https://forum.tagdiv.com/custom-post-type-support/

All the post displaying elements would be more capable regarding default posts and categories. Sorry for the inconvenience.

Viewing 10 posts - 1 through 10 (of 10 total)
The forum ‘Newspaper’ is closed to new topics and replies.