Questions tagged [post-class]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
42 views

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 ...
user avatar
0 votes
1 answer
17 views

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)){ $...
user avatar
0 votes
0 answers
26 views

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:...
user avatar
1 vote
1 answer
1k views

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 ...
user avatar
0 votes
2 answers
294 views

adding additional class to get the post thumbnail [duplicate]

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(...
user avatar
  • 11
0 votes
2 answers
324 views

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 ...
user avatar
  • 3
0 votes
0 answers
261 views

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 ...
user avatar
  • 1
-1 votes
1 answer
22 views

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('...
user avatar
  • 13
1 vote
2 answers
282 views

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 ...
user avatar
0 votes
2 answers
1k views

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 ...
user avatar
4 votes
2 answers
9k views

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 ...
user avatar
1 vote
1 answer
1k views

Adding Filter to Homepage only

I want to execute the following code only on the homepage for the default post loop. I added this to the functions.php, but it doesn't work. It works and adds the according altering classes if I use ...
user avatar
  • 127
3 votes
2 answers
989 views

Add a different class name to each sticky post?

I am trying to set up a featured content section of my blog. This will contain two sticky posts. I have a custom loop which will only display the two sticky posts, in the loop I then get a content-...
user avatar
1 vote
0 answers
516 views

Is it possible to store Custom Post Type data in separate set of tables and still have wp_post class functionality?

I have a couple of custom post types (course and assignment) for an custom LMS plugin that I'm building. The course CPT represents content that is produced internally by the company. The assignment ...
user avatar
  • 763
0 votes
1 answer
85 views

How can i show post_class() within output loop?

I am trying to use show post_class() within $output loop.Though i tried it different way i failed. Here is my codes $output = '<div '; post_class('blog-list-vertical-content'); $output .= '" id=' ...
user avatar
0 votes
2 answers
590 views

How to add padding between posts

Ultimately, I'm really confused on how exactly you create a single class that affects each post in a static home page "recent post" type content area. I want to essentially have it where there's a ...
user avatar
3 votes
1 answer
6k views

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) { ...
user avatar
  • 179
0 votes
1 answer
296 views

get_post_class not working properly

I have a plugin on my WordPress site that lists the most visited pages. I recently realized that it was displaying certain pages that I don't want to display. I also want to be able to disable pages ...
user avatar
0 votes
1 answer
75 views

How to add post classes?

I can use post_class() to echo all classes for a post. How can I output only the category-ID as a class, and how can I include this while using heredoc string syntax? I got this function in which I ...
user avatar
0 votes
2 answers
2k views

How to edit the styles for the table of pages/post listed in the admin when you click on pages/posts?

It seems that some of the css on the table that shows the list of all the pages adversely reacts with one of my plugins, which adds a bunch of columns to the table. I'm pretty sure this is edit.php. ...
user avatar
  • 274
0 votes
1 answer
90 views

Highlight a Post on archive page if it has a new comment?

I have been searching for a solution to highlight a post if it has a new comment but there is no plugin/forum answer about this. Basically I have a custom post type listings on a page. I want to add ...
user avatar
  • 101
0 votes
1 answer
2k views

How can I add a class to particular paragraphs in my post?

The effect I'm looking for in the end is to have the first line in some paragraphs bolded. These would be the first paragraph of each section in my post. This kind of effect is used on this Bloomberg....
user avatar
1 vote
2 answers
717 views

Change Post Class function

I wish to change/remove parts of the automatic post class function that's built in to wordpress, lets say when i make a post, the html code generated looks like this: <div id="post-106" class="...
user avatar
0 votes
1 answer
2k views

How to change "post_class()" for a custom post type?

I am trying to keep the classes the exact same on my normal (blog) posts, and a custom post type I have called "locations". When I post a "normal post" I get the following classes: class="post-# ...
user avatar
7 votes
1 answer
7k views

How to specify a class added to my gallery

I would like to add a class to my gallery short code, this is how I have added my class: [gallery class="small" columns="2" ids="350,349,302,305"]. Now the confusion comes in, I am not sure how to ...
user avatar
  • 71
1 vote
0 answers
125 views

How to load post_class() locally

I'm using post_class() function to retrieve WordPress provided classes for a post. I've successfully implemented an AJAX powered "Favorite Post" functionality to each and every post, and I'm changing ...
user avatar
1 vote
2 answers
1k views

Where should I use post_class()?

I am trying to learn WP Theme development. And as I have understod it is important to use "post_class()" since plugins may need to use it. But what I not understand is where I should use it? Should ...
user avatar
  • 375
2 votes
1 answer
2k views

Indirect modification of overloaded property WP_Post::$classes has no effect

I'm working on a child theme and while everything works the Walker_Nav_Menu and Walker classes are causing all the fuss. My parent theme overrides Walker_Nav_Menu as below: if ( ! class_exists( '...
user avatar
0 votes
1 answer
657 views

Custom query with post_class filter using current_post not working

I have a new WP_Query on my archive page. I also have a post_class filter conditionally adding a class of first so I can display them in rows of 3 reliably. This is the post_class filter function ...
user avatar
  • 899
1 vote
1 answer
117 views

Is post_class(); going to slow Wordpress page speed

I just have a general question about the post_class(); function. As it gets category and tag classes relating to a post, is it database/server intensive to call this on a category page, or even a ...
user avatar
0 votes
1 answer
2k views

Wordpress call post-ID in jquery

I explain the situation I'm having here: On my home page, I have a list of post being display. I've code to have like a modal box to share this post. Basically, on each post you have a button share. ...
user avatar
  • 297
1 vote
1 answer
43 views

WordPress post arrangement using post_class

I want to create post layout in the following way: +--------------------+ | 1 Full Width Post | +----------+---------+ | 2 | 3 | +--------------------+ | 4 Full Width Post | +----------...
user avatar
  • 591
0 votes
1 answer
53 views

Method 'post_title' not found in class.

I'm running some code through phpStorm and am getting an error: Method 'post_title' not found in class. at this line: echo $post->post_title(); Is that phpStorm getting things wrong or am I ...
user avatar
  • 307
0 votes
2 answers
752 views

How to style posts selecting a CSS post_class (added through custom_fields?)?

Here is what I tried and couldn't reach it. Maybe I need a whole different approach? 1) I created a custom field in a post, called post-class and inserted the value cita-flow800000 (weird class name ...
user avatar
0 votes
1 answer
946 views

Every second post different class in blog view

To assign different classes to every 2nd post in blog view in WordPress adding this code into function.php was suggested as solution. Most people claim it is helpful, but to me it just adds odd at the ...
user avatar
0 votes
1 answer
91 views

What Generated Classes and IDs That Is Always Used On All Themes?

Just wondering if there is a way to get a complete list of wordpress generated css classes and ids that is always automatically assigned to any themes. I've read here, but it seem not list them ...
user avatar
  • 1,097
0 votes
1 answer
871 views

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 /...
user avatar
  • 913
0 votes
1 answer
1k views

post_type_exists keeps returning false

I have a little helper class for registering new custom post types. However, it seems it is registering the custom post type on each page load. I put in a small check for this: if( ! post_type_exists(...
user avatar
0 votes
1 answer
113 views

Different styles for categories - need to edit a plugin

I'm using a plugin to add recent posts to home page and I am using different styles for the categories. I have the different styles working on the blog page but not on the posts output from the ...
user avatar
1 vote
2 answers
14k views

Adding class to featured image

I have specified a loop to show featured images for my custom post type and wish to add a img-responsive class from bootstrap to my featured image. How can I do this? Thanks! Code: <div class=...
user avatar
  • 113
0 votes
1 answer
285 views

Add a class to post if it has been recently updated

I'm trying to add 'updated recently' after the post title. I've discovered some code which works but because of plugins and some theme coding it affects numerous instances of the_title that it shouldn'...
user avatar
0 votes
1 answer
289 views

Microformats in a single post - layout conflict

WordPress uses microformats, for example, when we use the function post_class() in the DIV containing the article. It automatically includes the class called hentry, which is used in microformats. ...
user avatar
  • 605
3 votes
2 answers
4k views

Wordpress: How to use post_class() in an echo

I am working on a foreach loop in Wordpress and want to add 'post_class()' to a div within it. Currently the code looks like this: if ( is_array( $posts ) && !empty( $posts ) ) { echo '&...
user avatar
0 votes
1 answer
138 views

wordpress add field to post_class

I need to add a custom field to my article post but not sure how to add an additional class to it. Currently the classes get pulled through like this <?php post_class($classes); ?>. However I ...
user avatar
0 votes
2 answers
993 views

post_class not working with css

through the codex I read about how to use the post_class() function to create a css hook for styling the content. Here is the code I have, PHP: <li class="<?php post_class();?>"> <?...
user avatar
  • 93
1 vote
1 answer
22k views

How to add class or id to shortcode HTML elements?

I have a row elements and 3 columns inside : [row] [one_third]1[/one_third] [one_third]2[/one_third] [one_third]3[/one_third] [/row] How can I add a custom class or id to [row] element ? I need to ...
user avatar
  • 113
0 votes
1 answer
205 views

Wordpress Tags in class

I have added tags to my Custom Post Type. Now I want to use them to create a isotope portfolio, I can load all tags with this code: <?php $args = array( 'post_type' => 'portfolio', '...
user avatar
0 votes
1 answer
143 views

Help with output of post classes using apply_filters

I’m new to scripting, this is a plugin I'd like to modify to output post classes. When I try using: apply_filters( 'post_class', $page->post_class ) it only outputs array=" ". Do I need an ...
user avatar
  • 11
3 votes
1 answer
4k views

Adding body class when post contains a specific shortcode

Simple shortcode function : function my_shortcode_function($atts,$content=null){ // Do something return $content; } add_shortcode('my_shortcode','my_shortcode_function'); I wonder how to add ...
user avatar
  • 847
0 votes
1 answer
2k views

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 ...
user avatar