Newsmag. Show category and subcategory on module.

Posted in: Newsmag
Post count: 12

Hi. I have two questions if I may.

First of all. In order to show category on modules we use echo $this->get_category(). However, if you need to show both category and subcategory on module, what do you use and how?

I have tried :

<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if($categories){
foreach($categories as $category) {
$output .= 'term_id ).'" class= "cats" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.''.$separator;
}
echo trim($output, $separator);
}
?>

It works fine, but only for the theme pages (authors, categories, search etc.). The modules just ignoring the php and do not show any category/subcategory on the pages created through visual composer.

Second question. In order to get rid of the title tool-tips I have used some JS snippets.

var imgs = document.getElementsByTagName('img');
for (var i = 0; i < imgs.length; i++) {
imgs[i].removeAttribute('title');
}
var alinks = document.getElementsByTagName("a"); for (var i = 0; i < alinks.length; i++) { alinks[i].removeAttribute("title"); }

Or

var titled = document.querySelectorAll('[title]'); // gets all elements with a 'title' attribute, as long as the browser supports the css attribute-selector
var numTitled = titled.length;

for (i=0; i<numTitled; i++){
titled[i].setAttribute('data-title',titled[i].title); // copies from 'title' to 'data-title' attribute
titled[i].removeAttribute('title'); // removes the 'title' attribute
}

They both work fine. However, after Ajax (load more, filters, mega menu etc.) they come back. So, basically JS resets after the ajax process. Is it possible to somehow implement JS so it works even after ajax?

Any help would be appreciated. Thank you in advance.

Post count: 1291

Hi,

We have a lot of messages lately and for the moment the time doesn’t allow me to test your code and provide a solution for this, it’s a complicated section of the code and my advice is to look for professional developer to help you solve this, sorry for this. If you don’t know anyone you could look on places like – http://studio.envato.com/

Thank you, Emil G.

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