I'm working on my comment-section.
I have a very basic custom Comment_Walker. But it doesn't show the "Awaiting Moderation" string after posting a comment.
Comments are posted successfully to the backend. I have ticked that comments have to be manually approved in the settings in the backend.
A comment shows in the comment section in the backend as "pending". But I won't get the message when posting the comment.
My Walker File (very basic reduced to demonstrate)
<?php
/** Custom Comment Walker Basic */
class Custom_Comment_Walker extends Walker_Comment {
protected function html5_comment( $comment, $depth, $args ) {
$tag = ( $args['style'] === 'div' ) ? 'div' : 'li';
?>
<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'has-children col-12 p-0' : 'p-0 col-12 list-unstyled' ); ?>>
<div>
<?php echo get_comment_text(); ?>
<?php if ( '0' == $comment->comment_approved ) : ?>
Awaiting Moderation
<?php endif; ?>
</div>
<?php
}
}
Accessing it via:
<div class="comment-list">
<?php
wp_list_comments( array(
'walker' => new Custom_Comment_Walker()
) );
?>
</div>
I don't quite understand why the message wouldn't show up. Do I oversee something here? Using the latest WordPress 4.9.6 on a localhost. I did deactivate literally every plugin I've had active before posting here. I have also tested this with different accounts and roles.
Apparently the solution was to have the "Save my name, email, and website in this browser for the next time I comment." checkbox selected in order for the message to show up.
So you have to have the GDPR checkbox to be checked in order to have the comment and message appearing before approval.
Sorry for bothering.
Related
How to show login link for non-logged in users instead Buddypress Activity Loop?
Is there an easy way to do this in theme functions.php file?
I know how to add notice before loop with: action_activity_loop_start but how to hide the whole loop?
Option 1
You can use something like this:
add_filter( 'bp_get_template_part', static function( $templates, $slug, $name ) {
if ( $slug === 'activity/index' && ! is_user_logged_in() ) {
$templates = [];
}
return $templates;
}, 10, 3 );
This snippet will completely hide the default activity loop, with all filters, forms, etc, rendering an empty page instead of all BuddyPress Activity.
This may not be a desirable way.
Option 2
In the $templates variable you can also define your own path to a custom template (like activity/logged-out.php, so it will look like this:
$templates = [ 'activity/logged-out.php' ];
You will need to create a wp-content/themes/theme-name/buddypress/activity/logged-out.php file with something like this:
<?php do_action( 'bp_before_directory_activity' ); ?>
<div id="buddypress">
<?php do_action( 'bp_before_directory_activity_content' ); ?>
<div id="template-notices" role="alert" aria-atomic="true">
<?php do_action( 'template_notices' ); ?>
</div>
<?php do_action( 'bp_before_directory_activity_list' ); ?>
<div class="activity" aria-live="polite" aria-atomic="true" aria-relevant="all">
CUSTOM TEXT FOR LOGGED OUT USERS.
</div><!-- .activity -->
</div>
You can check activity/index.php file to decide what you need and what you don't, but I think this is a good idea to remove the majority of content and hooks.
Option 3
If you use the BuddyPress Legacy Template Pack (check in BuddyPress settings) you can copy /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/activity/index.php file into your theme: wp-content/themes/theme-name/buddypress/activity/index.php and do the modification where needed. Check the line around 235 which has this: <?php bp_get_template_part( 'activity/activity-loop' ); ?>.
For BuddyPress Nouveau Template Pack everything is basically the same, but you will need to deal with wp-content/plugins/buddypress/bp-templates/bp-nouveau/buddypress/activity/index.php file. You will need to wrap its div#activity-stream into is_user_logged_in() check before display the whole div and its content, something like this:
<?php if ( is_user_logged_in() ) : ?>
<div id="activity-stream" class="activity" data-bp-list="activity">
<div id="bp-ajax-loader"><?php bp_nouveau_user_feedback( 'directory-activity-loading' ); ?></div>
</div><!-- .activity -->
<?php endif; ?>
This way you will basically override the default BuddyPress template file with your own.
Please remember about the ajax functionality of the page (filtering etc).
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am new to WordPress, and coding in general. I am trying to start a news website. Now, I have created a grid hero section for featured posts.
I would like to be able to select which posts are placed in a hero grid.I assume that one of the ways is to fetch them by post_title.I have watched a couple tutorials
and tryed to implement that functionality with ACF plugin but with no success. So far I am only able to display posts in a grid but they are not displayed by my personal preference which is what I would like to achieve. Tnx in advnace. Here is the code:
<section class="page-wrap">
<div class="container-sm">
<h1><?php the_title();?></h1>
<?php get_template_part('includes/section','content');?>
</div>
<?php
$args = array(
'post_type'=>'post',
'posts_per_page' => 3
);
$_posts = new WP_Query($args);
?>
<?php if($_posts->have_posts()):?>
<div class="row mt-5">
<?php while($_posts->have_posts()) : $_posts->the_post();?>
<?php if(has_post_thumbnail()) {
$thumbnail_data = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'caursel' );
$thumbnail_url = $thumbnail_data[0];
}
?>
<div id="post-<?php the_ID(); ?>" style="background-image:url('<?php echo $thumbnail_url ?>');width:440px;margin-left:3px;padding:10px; border-radius:10px;display:flex;align:center;" >
<a href="<?php the_permalink();?>">
<h3><?php the_title();?></h3>
</a>
<h6><?php the_excerpt();?></h6>
</div>
<?php endwhile;?>
</div>
<?php endif;?>
</section>`
If you have tried ACF and you are accustomed with it, I would go for the 'Relationship' custom field.
With this field, you can choose what posts can be chosen (I.e by category, tag, etc), as well as the minimum and maximum posts which can be chosen (in your case, maybe one, since it is a featured post).
Once you have set up this custom field in the back end, you can add a post to the field.
In your text editor, you can access the ACF like so:
<?php
$post_objects = get_field('name_of_acf_relation_field');
if( $post_objects ) {
foreach( $post_objects as $single) {
$ID = $single->ID; ?>
// write html code here and use your $ID to access the post
// you can access other custom fields too by using the $ID
// i.e <?php the_field('field_name', $ID); ?>
<?php } ?>
<?php } ?>
Am using The7 Theme. Since I wanted to create a NEWS section to post latest news (apart from the Blog, which is separate), I used the Custom Post Type UI plugin to create a custom post type named news
I created a new file in my child theme, by copying the contents of the parent theme's archive.php file and named it as archive-news.php, with a minor modification:
<?php
/**
* Archive pages.
*
* #since 1.0.0
*
* #package The7\Templates
*/
defined( 'ABSPATH' ) || exit;
$config = presscore_config();
$config->set( 'template', 'archive' );
$config->set( 'layout', 'masonry' );
$config->set( 'template.layout.type', 'masonry' );
get_header();
?>
<!-- Content -->
<div id="content" class="content" role="main">
<div class="news_years text-center">
<?php for( $i = date('Y'); $i >= 2009; $i-- ) { ?>
<?php echo $i; ?>
<?php } ?>
</div>
<?php
//the_archive_description( '<div class="taxonomy-description">', '</div>' );
if ( have_posts() ) {
the7_archive_loop();
} else {
get_template_part( 'no-results', 'search' );
}
?>
</div><!-- #content -->
<?php do_action( 'presscore_after_content' ); ?>
<?php get_footer(); ?>
So the modification done was that I commented out the description that would be shown at the top of the page, and added year buttons.
After this, when the www.mysite.com/news was accessed, it pretty well loaded all my news items and when clicking an item, it loaded the detailed page as well. And the pagination also works very well, as it inherits the parents theme's template files.
The problem am facing is, I want to make it display year wise items also. Say for example, right now, when accessing the www.mysite.com/news url, it loads up all the News items with pagination. I want to filter it based on a particular year. That's why I included the additional FOR loop in the above code.
Upon searching, I found that the WP Query has date parameters that can be used which will resolve my issue.
But am not sure how to apply this as this archive page is already doing the fetching of posts. And also, how to pass the year in the URL as well. Any pointers would be highly appreciated.
If this is not the right forum to ask this question, please feel free to move this thread to the apt forum. Thank you.
I have a woocommerce store and want to show wocommerce error messages in specific place of my theme, for example under submit button.
I know wocommerce error messages come from here:
<ul class="woocommerce-error">
<?php foreach ( $messages as $message ) : ?>
<li><?php echo wp_kses_post( $message ); ?></li>
<?php endforeach; ?>
</ul>
But, when i put this code in my page (for example edit-my-address.php page), its giving error!
What is working or simple code for showing messages in woocommerce?
Thanks in advance.
you can use both methods here..
woocommerce_show_messages();
wc_print_notices();
You can also show woocommerce custom notices according to your condition like...
wc_add_notice( 'This is a Success notice', 'success' );
wc_add_notice( 'This is a Error notice', 'error' );
wc_add_notice( 'This is a \'Notice\' notice\'', 'notice' );
You can add this piece of code to functions.php of your child theme
add_shortcode('woocommerce_notices', function($attrs) {
if (wc_notice_count() > 0) {
?>
<div class="woocommerce-notices-shortcode woocommerce">
<?php wc_print_notices(); ?>
</div>
<?php
}
});
And then use it as a shortcode [woocommerce_notices] in any desired post or page, or use <?php echo do_shortcode('[name_of_shortcode]'); ?> in a desired PHP template.
Tested and works. Good luck.
A bit late to the party but here is a solution.
Try to use the following piece of code (taken from the original file here: wp-content/plugins/woocommerce/templates/single-product.php)
<?php
/**
* woocommerce_before_main_content hook.
*
* #hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* #hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
Hope it helps
you missed to add this line of code:
<?php wc_print_notices(); ?>
Add this to your functions.php file inside your child theme (or main theme if there is no child).
add_shortcode('woocommerce_notices', function($attrs) {
if (function_exists('wc_notice_count') && wc_notice_count() > 0) {
?>
<div class="woocommerce-notices-shortcode">
<?php wc_print_notices(); ?>
</div>
<script>
(function($) {
$(window).on("load", function(){
// You can execute some js here
});
})(jQuery);
</script>
<?php
// You can execute some php here
wc_clear_notices();
}
});
Then add a shortcode to your page as:
[woocommerce_notices]
The notices and the code will get executed wherever you paste the shortcode.
We can't seem to get the template-tags.php the_posts_navigation function to care about basic edits at all:
if ( ! function_exists( 'the_posts_navigation' ) ) :
/**
* Display navigation to next/previous set of posts when applicable.
*
* #todo Remove this function when WordPress 4.3 is released.
*/
function the_posts_navigation() {
// Don't print empty markup if there's only one page.
if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
return;
}
?>
<nav class="navigation posts-navigation" role="navigation">
<h2 class="screen-reader-text"><?php _e( 'Posts navigation', 'mytheme' ); ?></h2>
<div class="nav-links">
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( __( 'Older posts!!', 'mytheme' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts!!', 'mytheme' ) ); ?></div>
<?php endif; ?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
endif;
As you can see we added some exclamation marks to the posts links but WordPress could care less on the front end. It should show up on the index.php where there are plenty of posts to be seen and it stubbornly only shows "Posts navigation" as a main heading and "Older posts".
Please help! Thank you!
It appears that in 4.1 Wordpress added the the_posts_navigation to its core functionality. Prior to that it didn't exist and _s actually uses a function by that exact same name in template-tags.php. So now, instead of calling what used to be the custom _s function, it defaults to the Wordpress version, basically ignoring the one in template-tags.php.
To fix this I just changed the name of the _s function. Personally, I chopped off the "the" so it becomes posts_navigation in template-tags.php and then anywhere it was referenced in the theme (index.php, single.php etc.). Worked like a charm and any changes I'd made to the function in template-tags.php (adding my own arrow icons) showed right up.
It appears that function in the template-tags.php file only has compatibility for WordPress versions prior to 4.1 and they are part of WordPress core.
Using the_posts_pagination() and/or next_posts_link() / previous_posts_link() is effective enough.