How to add css class to approved comment - wordpress

In my theme, I use wp_list_comments() to display comments, I want to add a css class to new approved comment, I have tried to find a filter or something like this but couldn't find anything. Does anyone has a solution to do it, I don't want to edit in wp-includes/comment-template.php. Thank a lot!

You Will Find Code Into wp-includes/comment-template.php
Into Line 1997
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- .comment-content -->
Add Your Custom HTML Here
<?php
ob_start();
comment_form();
echo str_replace('class="comment-form"','class="comment-form your-custom-class"',ob_get_clean());
?>
Now the standard class comment-form will be replaced by itself plus the custom class.

Related

Add class to comment in Genesis

I have a custom callback that's rebuilding the comment list, and I used some of the default options from Genesis including:
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
How do I add an additional class? When I just try to add it at the end of this <li>, it doesn't work. But I want to also include all the default classes that come from comment_class();
Nevermind, you can just add a class name into the comment_class('test-class'); function

template management with wordpress (underscore boilerplate)

I am using underscore to develop a wordpress theme.
I have a custom post type name project, thus I have, for instance, this url: http://a.site.local/projects/a-beauty/.
I have in my template-parts/ directory the file content-projects.
$ cat template-parts/content-projects.php
<h1>Project</h1>
When I browse http://a.site.local/projects/a-beauty/, I have my title but also the sidebar and the footer (even if they do not appear in my content-project.php nor in index.php).
Where are those widgets coming from / loaded ?
Add conditions to the header, footer and sidebar.
For whole custom post archive:
<?php if( !is_post_type_archive( 'project' ) ) : ?>
// wrap the code you don't want to show on that archive
<?php endif; ?>
For custom post only:
<?php if( !is_singular( 'project' ) ) : ?>
// wrap the code you don't want to show on the post
<?php endif; ?>
If you want to put the code you WANT to show, remove the '!' before condition.
P.S.
You can put the whole content in a condition, but keep the
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
otherwise the page will break :)
Please share some more code from your project so we can easy to understand the real problem.

Aptana 3 format phtml files

i've been using aptana for a while now, and i have a little question because it is driving me mad. It is possible to recode formmat rules if there is no option in the preferences options (Windows->Preferences->Aptana studio->Formmatter).
I want to recode format rules of .phtml files for a simple rule, <?php ... ?> tag. Everytime i autoformat .phtml files, the "tag" ?> adds a line. I do not want that new line, i want it keep at the same line as the initial tag.
if i write in a .phtml file something like this:
<?php if ($this->x > 10) : ?>
<p> It is not greater than 10 </p>
<?php else : ?>
<p> It is greater than 10 </p>
<?php endif : ?>
and do autoformat, the autoformat return this:
<?php if ($this->x > 10) :
?>
<p> It is not greater than 10 </p>
<?php else :
?>
<p> It is greater than 10 </p>
<?php endif :
?>
I hope you can understand my question. How can anybody recode a format rule or show me the option where i can say do not add a new line in ?> tag.
Thanks in advance.
P.D.
Excuse if i have some grammars errors, if been a while since i have to write in english.
It's not possible (yet) with the current formatter capabilities. However, I've created an issue for that at http://jira.appcelerator.org/browse/APSTUD-3340 and you are more than welcome to add yourself as a watcher, so you will get notified.
That main problem is that the current formatter works partition-by-partition, and not by looking at the entire content as a whole.
Cheers

How to add a class to a Drupal 7 region?

I am trying to add a .clearfix class to my footer region in a Drupal 7. Is there a way to do this?
I am currently using the following to print my footer region:
<?php print render($page['footer']); ?>
Which outputs:
<div class="region region-footer">
<div id="block-1>....</div>
<div id="block-2>....</div>
</div>
Here's the code snippet:
function MY_THEME_NAME_preprocess_region(&$variables, $hook) {
if($variables['region'] == "MY_REGION_NAME"){
$variables['classes_array'][] = 'MY_CLASS_NAME';
}
}
Or if you'd rather insert the class into all of the regions:
function MY_THEME_NAME_preprocess_region(&$variables, $hook) {
$variables['classes_array'][] = 'MY_CLASS_NAME';
}
Copy region.tpl.php (found in modules/system directory) to your theme directory. Then copy everything inside it and create a new file. Paste into that file and make any changes you like to the template. Once finished, save it as region--footer.tpl.php and clear the cache on your site to see the changes.
The region.tpl.php contains (along with a lot of comments explaining possible variables):
<?php if ($content): ?>
<div class="<?php print $classes; ?>">
<?php print $content; ?>
</div>
<?php endif; ?>
So all you would need to do is add a class on that DIV.
It is even better if you use a hook, you can use template_preprocess_region.
Try adding the include to the footer.php.tpl file. You may have to create it.

Wordpress if else requirements for comments

I am not sure where to start, but I want to add in a symbol or change the css for the comments for registered users. Show a difference between non registered user comments and registered user comments.
How would I go about adding this to my wordpress website?
<div class="commentdetails">
<p class="commentauthor"><?php comment_author_link() ?></p>
<?php if ($comment->comment_approved == '0') : ?>
<em>Your review is pending approval by gsprating staff.</em>
<?php endif; ?>
<p class="commentdate"><?php comment_date('F jS, Y') ?>
IP/Hostname: <small>(coming soon)</small>
<?php edit_comment_link('Edit Comment','',''); ?>
</p>
I want to add make it so that the entire class is a different color if the user is a registered logged in user.
Here's an all php version of Saladin's code using the standard if/else sysntax:
<?php
if ($comment->user_ID) {
echo "<div class='comment_registeredUser'>";
}
else { // The user is not logged in
echo "<div class='commentdetails'>";
}
?>
Putting all the code in php has fixed execution errors for me. Of course, that may have been because I was doing something else wrong.
As comments are displayed in the wp_list_comments() function, you will need to edit the code there. The easiest way to achieve this is to use a simple if/else statement checking whether or not the comment has a user ID associated with it. If it does, that means the comment was made by a registered user.
Of course, as well as this, you will need to create a new CSS class to give the distinction. Here is some example code:
<?php if($comment->user_ID) : ?>
<div class="comment_registeredUser"> <!-- Or whatever you decide to call the CSS class -->
<?php else : ?> <!-- The commenter isn't a registered user -->
<div class="commentdetails">
<?php endif; ?>
// Then include the rest of the code as is
The $comment->user_ID variable will return a true if the comment poster is a registered user and was logged in when they posted the comment. The code above will assign your custom CSS class to the div if it does indeed return true. If not, it will simply apply the standard class and styling.
There is also a really good tutorial for developing themes over at the Wordpress Codex. Definitely worth having a read through if you are unsure on what you need to do to create/edit your WordPress theme.
Edit: Cleaned up the answer and better explained the correct logic.

Resources