Post Class for Custom Taxonomy Error

I'm getting two errors with the following code. I'm essentially trying to go through all the custom taxonomies and add them to the post class. Notice: Array to string conversion in /Applications/MAMP/htdocs/Dev/wp-includes/taxonomy.php on line 3317 Notice: Array to string conversion in /Applications/MAMP/htdocs/Dev/wp-includes/category-template.php on line 1253 if ( ! function_exists('custom_taxonomy_class') ) { function custom_taxonomy_class($classes, $class, $ID) { $args = array( 'public' => true, '_builtin' => false ); $output = 'names'; // or objects $operator = 'and'; // 'and' or 'or' $taxonomies …
Category: Web

Wordpress Loop - Style rows of posts differently

I am trying to adapt the Wordpress loop to style posts differently in rows that get infinitely smaller until all posts are displayed The concept here is to display posts in rows first row 1 post second row 2 posts third row 3 posts fourth row 4 posts fifth row 5 posts sixth row 6 posts seventh row 7 posts ...and onward until all posts have been retrieved. The below code is limited and does not do the above how …
Category: Web

Where to use Post class in a real theme, title, content or parent div or article tag?

I am extending discussion from one another article posted on the same website → Where should I use post_class()?. This is the portion from content-single.php → Where should I put the post-class? in the h2 tag that will print the title or on the parent article tag, which has one other div,which is a sibling to h2, title class? <h4><?php the_title(); ?></h4> <p><?php the_content(); ?></p> I browsed this link, but still, I could not get the clarity → https://developer.wordpress.org/reference/functions/post_class/ REQUIRED: …
Category: Web

Set class if a meta value is set within post archive

I'm attempting to add a class to posts when the meta key 'checkbox' is clicked. Here's what I have: <?PHP $checkbox = get_post_meta($post->ID, 'checkbox', true); if (!empty($checkbox)){ $has_video = 'icon-has_video'; } else {$has_video = '';} ?> <a class='<?php echo $has_video; ?>' href='<?php the_permalink(); ?>'> ... but so far it's not working. Any suggestions?
Category: Web

How to add classes to post_class?

In the following code I would like to remove the div that wrap all the code and pass its class to article, but I do not know how to pass the variable $termString inside the post_class. Can anybody help me? <div class="<?php echo $termsString;?>"> <article id="post-<?php the_ID(); ?>" <?php post_class('card'); ?>> <?php echo get_the_post_thumbnail($post_id, 'large', array('class' => 'img-fluid card-img-top')); ?> <div class="overlay"></div> <div class="card-body text-right"> <h6 class="card-title"><?php the_title(); ?></h6> <p>Text description for this item</p> </div> <a class="card-link" href="<?php the_permalink(); ?>" …
Category: Web

Correct way adding External classes to Custom Post type and output their methods to template

So I'm creating Custom Post Type, and I have 3 external classes with namespace Test\Events\Model; Those 3 classes are final class Location, final class Event, and final class Person. Example of method: public function street(): string { return 'Street name 2'; }` For template, I'm using single-event.php. My question is, How to hook all those classes and their methods? Everything I have tried it's not working, so I'm missing something for sure. Thank you all!
Category: Web

How do I add a custom body class for a specific page ID?

I have added this code to my child theme's functions.php file and use the new class but it styles the entire site, not the page I added to the code. What am I doing wrong? add_filter('body_class','custom_body_class'); function custom_body_class($classes) { if( is_page('38034') ) { $classes[] = 'new-class'; return $classes; } }
Category: Web

add active class based on permalink and url

i am facing a issue, on my wordpress site in left side i loaded post list with title and excerpt, and when you click on that content will get load on right side of page and its working fine but i like to add active or current class when any link from list get clicked and open in side, and first one as active already as it is already displaying content on right side please check code on left side …
Category: Web

Add filter to wp_list_categories and query what type of taxonomy-terms it use?

This is probably a confusing title of my question, but it's exactly what's describing my problem best. I want to add the category-slug as classname to my wp_list_categories() output. I found a really simple function that does exactly that it works perfectly. add_filter('wp_list_categories', 'add_slug_css_list_categories'); function add_slug_css_list_categories($list) { $cats = get_categories(); foreach($cats as $cat) { $find = 'cat-item-' . $cat->term_id . '"'; $replace = 'category-' . $cat->slug . '"'; $list = str_replace( $find, $replace, $list ); $find = 'cat-item-' . $cat->term_id …
Category: Web

adding additional class to get the post thumbnail

I'm just starting to create new theme and i'm new to code. I'm stuck in customizing the post thumbnail code, i tried add <?php previous_post_link(get_the_post_thumbnail(get_previous_post(), array( 'class' => 'rounded-lg object-cover' )) . '<h4 class="text-center">%link</h4>', '%title',false ); ?> but it doesn't seem to work. did my array mistakenly placed in the code?
Category: Web

Add all category as classes in foreach loop

I am trying to modify a portfolio plugin with filter function. The current code for listing to post items is: <?php class FullwidthPortfolioGallery extends ET_Builder_Module { public $slug = 'fullwidth_portfolio_gallery'; public $vb_support = 'on'; protected $module_credits = array( 'module_uri' => '', 'author' => '', 'author_uri' => '', ); public function init() { $this->name = esc_html__('Portfolio Gallery', 'divi-modules'); $this->fullwidth = true; $this->advanced_fields = [ 'background' => false, 'fonts' => false, 'max_width' => false, 'link_options' => false, ]; } public function get_fields() …
Category: Web

How do I use $wp_query->current_post with get_template_part? I'm trying to add post classes (first/last/even/odd) to custom loops

... but $wp_query->current_post and the like don't work when I use get_template_part to pull in content.php files as modeled by themes like twentynineteen. The variables don't carry over I guess? Is there a way to add custom post classes to posts created by a custom query while also using get_template_part? Thank You.
Category: Web

current-menu-item class for custom post type parent

Im having a problem with my menu and custom post type. I have a custom post type of "services". I have created new page for it called Services. On that page Im displaying a list of all the post from that custom post type. The current-menu-item class is working as itended. But the problem is when I click on one of the services and go to mysite.com/services/service-1, the current-menu-item from services page in menu dissapears. I need to show that …
Category: Web

Remove and add class with body_class() function

I want to remove the default body class on the theme and add a new class. I use this code to do this: //REMOVE / ADD HOME CLASS FROM BODY add_filter('body_class', function (array $classes) { if (in_array('home', $classes)) { unset( $classes[array_search('home', $classes)] ); } return $classes; }); add_filter('body_class', function (array $classes) { if (in_array('blog', $classes)) { unset( $classes[array_search('blog', $classes)] ); } return $classes; }); add_action( 'body_class', 'my_custom_class'); function my_custom_class( $classes ) { $classes[] = 'my-custom-class'; return $classes; } The code …
Category: Web

PHP Use Declared array Variable inside already Declared Array

i have created one class in which i declared public associative array. class test{ public $basicCols= array( array('title'=>'KEY', 'field'=>'slug','options'=>$optList), array('title'=>'KEY', 'field'=>'slug'), } public $optList= array("one"=>"One","two"=>"Two"); } But when i execute code its giving me error. I tried $this->$optList $this->optList $optlist is there any other way to declare variable inside variable in class. thank you in advance.
Category: Web

Remove Extra Classes from Post Title

I want to remove tag, category classes from Post Titles of my WordPress blog. On the frontend, Wordpress generates extra classes for every single article title. For Example, this article, has these article title classes "category-tips-guides" "tag-indian-army" as displayed in the following image: I have tried the following snippet to remove some extra classes (shared on this page) and it works: function lsmwp_remove_postclasses($classes, $class, $post_id) { $classes = array_diff( $classes, array( 'hentry', 'type-' . get_post_type($post_id), 'status-' . get_post_status($post_id), ) ); …
Category: Web

Remove classes from post_class()

I am trying to tidy up the post_class function. I've managed to remove "hentry" class using the filter below, but I would also like to remove the "post-id", "type-" and "status-" classes as well. How can I use my filter to do this? function lsmwp_remove_postclasses( $classes ) { $classes = array_diff( $classes, array( 'hentry' ) ); return $classes; } add_filter( 'post_class','lsmwp_remove_postclasses' );
Category: Web

Get categories list with category name in custom WP_List_Table class

Im building a plugin and i made custom wp_list_table class to suit my needs and display items with native wordpress look. The problem is that i can't get to list categories with categories names. I use data from database table and list of my categories in database is in comma separated list of categories id's so the data looks like 136, 8, 10, 11, 110 And when i output that on website i get list just like that comma separated …
Category: Web

Child Pages Loop

If anyone can help that'd be great. I've found a snippet of code that I've used which is pretty much doing what I want it to do, which lists out subpages of the parent, adds a thumbnail if there is one, and added a custom excerpt. However, the problem is that I can't add individual <?php post_class(); ?> to a div inside the loop, its using the class from the parent and repeating for the subpages. <?php $child_pages = $wpdb->get_results("SELECT …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.