Customizing children comments in wp_list_comments in wordpress - wordpress

What I want is like this: Click to see the picture
But,at last It came up with like this:
Click to see the picture
(I can't put images, so I put the picture url here!)
Here Is Code In My comment.php Where Show The Comments:
`<?php wp_list_comments('type=comment&callback=comment_activity_list');?>`
and this is the code of function "comment_activity_list" in my function.php:
<?php if (!function_exists("comment_activity_list")){
function comment_activity_list($comment, $args, $depth){
$GLOBALS['comment'] = $comment;
?>
<ol class="clist">
<li id="discussion-<?php comment_ID() ?>" class="discussion">
<div class="discussion-post clearfix">
<div class="gravatar"><?php echo get_avatar( $comment, 45); ?></div>
<div class="block">
<a class="discussion-username"><?php echo get_comment_author_link() ?></a>
<div class="discussion-text">
<?php comment_text()?>
<?php if ($comment->comment_approved == '0') : ?>
<p><em><?php _e('Your comment is awaiting moderation.'); ?></em></p>
<?php endif; ?>
</div>
<!--.discussion-text-->
<div class="discussion-meta">
<?php delete_comment_link($comment->comment_ID,'class="btn red"')?>- <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?> - <?php if(!function_exists('how_long_ago')){comment_date('M d, Y'); } else { echo how_long_ago(get_comment_time('U')); } ?>
</div>
<!--.discussion-meta-->
</div>
<!-- .discussion-post -->
</div>
<!-- .discussion-post -->
</li>
</ol>
<?php
}
}?>
How can I Customize the children comments ? Any one can hepl me?
Thx In Advance!

You can check if a comment is a child by checking the following
<?php if( $comment->comment_parent ) : ?>
// This is a CHILD comment
<?php else: ?>
// This is a NORMAL comment
<?php endif; ?>

Related

How to override a function in parent WordPress theme

I am building a child theme using Flaxseed as a parent. This theme includes several 'content styles' which can be selected using Theme > Customizer. Each of these styles has a function in the parent functions.php file that renders the CSS and wordpress content into one. I want to edit some of the Loop functions that are in here, specifically updating the_excerpt to the_content, but I want to do so in a way that works with my child theme.
Since this code is in the parent functions.php, and since the theme customizer calls it specifically by name, I cannot simply add a new function, and I cannot override it using the same function name.
My best guess is that I need to somehow remove this function from the parent functions.php before loading a new function of the same name in my child function.php, but I cannot seem to figure out how.
Below is the code from the template file where the function is loaded into the template:
<?php for ($i = 1; $i < 8; $i++)
if (get_theme_mod('flaxseedpro_fa_'.$i) != 'none') {
flaxseedpro_display_featured_area(
get_theme_mod('flaxseedpro_fa_'.$i),
get_theme_mod('flaxseedpro_fa_title'.$i),
get_theme_mod('flaxseedpro_fa_cat'.$i)
);
}
?>
Here, the $i variable is the value that is set in the Theme > Customizer screen. This file and code could be modified easily as a part of the child theme.
Below are two code snips from the parent functions.php which select the appropriate featured area code:
function flaxseedpro_display_featured_area($style, $fa_title, $cat) {
if (is_home()) :
switch ($style) {
case 'carousel':
flaxseedpro_carousel($fa_title, $cat);
break;
case 'style1':
flaxseedpro_featured_style1($fa_title, $cat);
break;
case 'style2':
flaxseedpro_featured_style2($fa_title, $cat);
break;
case 'style3':
flaxseedpro_featured_style3($fa_title, $cat);
break;
case 'style4':
flaxseedpro_featured_style4($fa_title, $cat);
break;
default:
break;
}
endif;
}
which leads to several functions such as this:
function flaxseedpro_featured_style2($fa_title, $cat) {
?>
<div class="featured-style1 featured-style2">
<?php if ('' !== $fa_title) : ?>
<h2 class="featured-section-title container">
<?php echo esc_html($fa_title); ?>
</h2>
<?php endif; ?>
<div class="featured-posts-inner container">
<?php
$args = array(
'posts_per_page' => 5,
'cat' => $cat,
);
$fa_posts = new WP_Query($args);
if ($fa_posts->have_posts()) :
$counter = 0;
while ($fa_posts->have_posts()) :
$fa_posts->the_post();
$counter++;
if (1 === $counter) {
?>
<div class="feat-col1 md-6 sm-6">
<div class="md-12 pr-0 pl-0">
<article id="post-<?php the_ID(); ?>" <?php post_class('featured-post-item'); ?>>
<div class="item-container mb-3">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail('medium-large', array('class' => 'featured-post-thumbnail-primary')); ?>
<?php else : ?>
<img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/placeholder.png'); ?>">
<?php endif; ?>
</div>
<div class="post-title-parent">
<a class="post-title title-font" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<div class="post-author">
<?php esc_html_e('By', 'flaxseed-pro'); ?> <?php the_author(); ?> <i class="fa fa-clock-o"></i> <?php the_time('F j, Y'); ?>
</div>
<div class="entry-excerpt body-font mb-3"><?php the_excerpt(); ?></div>
</div>
<?php _e('Read More','flaxseed-pro') ?>
</article>
</div>
</div>
<?php
} else {
?>
<div class="feat-col2 md-6 sm-6">
<article id="post-<?php the_ID(); ?>" <?php post_class('featured-post-item'); ?>>
<div class="md-4 xs-4">
<div class="item-container">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail('medium', array('class' => 'featured-post-thumbnail-secondary')); ?>
<?php else : ?>
<img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/placeholder.png'); ?>">
<?php endif; ?>
</div>
</div>
<div class="md-8 xs-8">
<div class="post-title-parent">
<a class="post-title title-font" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<br><small><?php esc_html_e('By', 'flaxseed-pro'); ?> <?php the_author(); ?> <i class="fa fa-clock-o"></i> <?php the_time('F j, Y'); ?></small>
</div>
</div>
</article>
</div>
<?php
}
endwhile;
endif;
wp_reset_postdata();
?>
</div>
</div>
<?php
}
This is the the code I've been trying to override but unable to find a solution as a part of the child theme. All of the answers I've found seem to require a hook, which I cannot discern from this code.
This is solved.
I changed the function name that is called in my template file (flaxseedpro_display_featured_area >> flaxseedpro_display_featured_area2), then redefined the switch function to replace 'style3' with a new 'style5'. Then added the new 'style5' function with updated CSS code.

Worpress sort the posts

In wordpress Tag page(tag.pgp). I have a left menu like this.
<div class="well">
<div>
ALphabatically <br/>
</div>
<div >
By category <br/>
</div>
</div>
I have all the posts on right side in The loop.
<?php
while(have_posts()) {
the_post(); ?>
<div >
<h2><?php the_title(); ?></h2>
<div>
<p>Posted by <?php the_author_posts_link(); ?> on <?php the_time('n.j.y'); ?> in <?php echo get_the_category_list(', '); ?></p>
</div>
<div>
<?php the_excerpt(); ?>
<p>Continue reading »</p>
</div>
</div>
<?php }
echo paginate_links();
?>
How can I sort the post alphabetically and by category by clicking on the links on left.
<?php
$args_product = array(
'post_type' => 'product',
'posts_per_page' => 10,
'orderby'=>'title',
'order'=>'ASC',
'product_cat' => $all_categories_data->slug
);
$loop_product = new WP_Query( $args_product );
while ( $loop_product->have_posts() ) : $loop_product->the_post();
?>
<div >
<h2><?php the_title(); ?></h2>
<div>
<p>Posted by <?php the_author_posts_link(); ?> on <?php the_time('n.j.y'); ?> in <?php echo get_the_category_list(', '); ?></p>
</div>
<div>
<?php the_excerpt(); ?>
<p>Continue reading »</p>
</div>
<div>
<span><?php echo $all_categories_data->name;?></span>
</div>
</div>
<?php endwhile;?>
Use pre_get_posts action hook provided by WordPress.
Then, in your functions.php add the following code below:
function custom_pre_get_posts($query) {
// validate
if(!is_admin() && $query->is_main_query()) {
if(is_archive()) {
$query->set('orderby', 'title'); // order posts by title
$query->set('order', 'ASC'); // and in ascending order
}
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
For futher information visit https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

WP-PageNavi Issues, Url changes but the posts remain the same?

The issue I am having is I have created a new blog page on its own page template page being called blog.php, I have pulled 5 posts into each page and the first page work great and link to the single posts that they are attached too.
When I try to add wp-pagenavi into my nav-below I run into an issue. What happens is I will click to go the next page and it changes the url, but the posts remain the same as before, when it should be switching them to the next set.
I don't know if you can use wp-pagenavi outside of index.php, but if anyone can let me know what I am doing wrong here and why I continue to get the same posts that would be awesome and greatly appreciated. I have one of my blogs on blog.php and that is the file I am trying to get to work. I have posted the code for it below.
<?php
/**
* Template Name: Blog Page <?php query_posts("posts_per_page=8"); ?>
*/
get_header(); ?>
<div id="content">
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5' ) ); ?>
<?php
//THE LOOP.
if( have_posts() ):
while( have_posts() ):
the_post(); ?>
<article id="post-1" <?php post_class( 'clearfix' ); ?>>
<h2 class="entry-title"> <a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
<div class="postmeta">
<span class="author"> Posted by: <?php the_author(); ?> </span>
<span class="date"> <?php the_date(); ?> </span>
<span class="num-comments">
<?php comments_number('No comments yet', 'One comment', '% comments'); ?></span>
<span class="categories">
<?php the_category(); ?>
</span>
<span class="tags">
<?php the_tags(); ?>
</span>
</div><!-- end postmeta -->
<?php if( has_post_thumbnail() ): ?>
<div class="thumb">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</div>
<?php endif; ?>
<div class="entry-content">
<?php
if( is_single() OR is_page() ):
the_content();
else:
the_excerpt();
endif;
?>
</div>
<?php comments_template(); ?>
</article><!-- end post -->
<?php
endwhile;
else: ?>
<h2>Sorry, no posts found</h2>
<?php endif; //END OF LOOP. ?>
<div id="nav-below" class="pagination">
<?php if( function_exists('wp_pagenavi') ):
wp_pagenavi();
else:
?>
<?php next_posts_link( '← Older Posts' ); ?>
<?php previous_posts_link( 'Newer Posts →' ); ?>
<?php endif; ?>
</div><!-- end #nav-below -->
</div><!-- end content -->
<?php get_footer(); ?>
After <div id="content"> have this code:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5', 'paged' => $paged ) ); ?>

Wordpress Pagination

I have a wordpress site : There is a problem with the pagination.. When I click on 2'nd page it shows up the first one(index page). The other pages are working. Can you help me?
I looked up for errors in the loop but i didn't found anything!
this my index.php code
<?php get_header(); ?>
<div id="content">
<?php if(get_option('freshlife_featured_content_enable') == 'on') { ?>
<div id="featured-content">
<div class="heading">
<span class="heading-text"><?php _e('Featured Articles', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<ul>
<?php
$counter = 1;
query_posts( array(
'showposts' => get_option('freshlife_featured_post_num'),
'tag' => get_option('freshlife_featured_post_tags')
) );
if( have_posts() ) : while( have_posts() ) : the_post();
?>
<li class="featured-<?php echo $counter; ?>"><?php the_post_thumbnail('featured-thumb', array('class' => 'entry-thumb')); ?><span class="entry-date"><abbr title="<?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . __(' ago', 'themejunkie'); ?></abbr></span><h2 class="entry-title"><?php the_title(); ?></h2></li>
<?php $counter++; endwhile; endif; wp_reset_query(); ?>
</ul>
</div> <!-- end #featured-content -->
<?php } ?>
<div class="heading">
<span class="heading-text"><?php _e('All Stories', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include(TEMPLATEPATH. '/includes/templates/loop.php'); ?>
<?php endwhile; ?>
<div class="clear"></div>
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(); else { ?>
<div class="pagination">
<div class="left"><?php previous_posts_link(__('Newer Entries', 'themejunkie')) ?></div>
<div class="right"><?php next_posts_link(__('Older Entries', 'themejunkie')) ?></div>
<div class="clear"></div>
</div> <!-- end .pagination -->
<?php } ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It's hard to say without looking at the WP_Query generated by the requests.
But I do see something that might be causing problems, query_posts alters the main query, that could be messing with the pagination.
Try to use get_posts instead query_posts, so the main loop is not affected.
A more detailed explanation can be found here

the_author is empty when not logged in

Is there a reason why the_author should return an empty string on the first page when the user is not logged in, but return the author name just as it should when more posts are loaded through AJAX ?
The loop is the same in both cases.
Please help me resolve this issue as I'm clueless and I need it fixed ASAP to launch my site.
Here's the whole index.php:
<?php
get_header();
get_sidebar();
?>
<!-- MAIN DIV -->
<div id='content_and_floater'>
<?php get_template_part('social_floater'); ?>
<div id='content'>
<?php get_template_part('loop'); ?>
</div>
</div>
<?php get_template_part('loader'); ?>
<!-- MAIN DIV -->
<?php
get_footer();
?>
And here's how the infinitePaginator calls the loop in functions.php (the function is called when scrolled down to the bottom or the loader link is clicked):
function wp_infinitepaginate(){
$loopFile = $_POST['loop_file'];
$paged = $_POST['page_no'];
$posts_per_page = get_option('posts_per_page');
# Load the posts
query_posts(array('paged' => $paged ));
get_template_part( $loopFile );
exit;
}
You can see the behaviour at test.nowillnoskill.net.
In single posts it's not working either. My guess is that query_posts(array('paged' => $paged )); changed something in the query, but I don't know what is it.
I tried to insert setup_postdata($post); just after the_post() in loop.php as I found that worked for someone, but it doesn't for me.
I also tried to insert
query_posts(array('paged' => 1 ));
before calling the loop file in index.php, but no posts at all were shown.
Here is my loop.php:
<?php while ( have_posts() ) : the_post() ?>
<!-- POST1 -->
<article class='post'>
<header class='post_header'>
<?php
global $current_user;
$current_user = wp_get_current_user();
if (!empty($current_user)) {
$pid = get_the_id();
$uid = $current_user->ID;
$title = (is_favorite($pid, $uid)) ?
'Remove from favorites' :
'Add to favorites';
$trans = (is_favorite($pid, $uid)) ?
'' :
' transparent';
?>
<div>
<h2>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php if (is_user_logged_in()) { ?>
<a title='<?php echo $title ?>' class='post_favorite' href='#' alt='fpid=<?php echo $pid ?>uid=<?php echo $uid ?>'>
<span class='symbol<?php echo $trans ?>'>R</span>
</a>
<?php } ?>
</div>
<div class='post_header_div'>
<strong class='post_category'>
<?php echo get_the_category_list(', '); ?>
</strong>
<strong class='post_author'>
<span class='symbol'>U</span>
<?php the_author(); ?>
</strong>
</div>
<div>
<span class='post_author'>
<?php edit_post_link('[edit]'); ?>
</span>
</div>
<?php } ?>
</header>
<figure class='post_image'>
<!--<img src='design/img/flashkick.png' alt='logo' />-->
<?php the_post_thumbnail(); ?>
</figure>
<div class='post_perex'>
<?php the_content('Read more'); ?>
</div>
<div class='space'></div>
<footer class='post_footer'>
<div class='post_footer_top'>
<div class='post_tags'>
<?php the_tags('', '', ''); ?>
</div>
<div class='post_time'>
<time datetime="<?php the_time('Y-m-d'); ?>" pubdate>
<span class='symbol'>P </span>
<?php relative_post_the_date(); ?>
</time>
</div>
</div>
</footer>
<div class='space'></div>
</article>
<?php endwhile; ?>
Author informations are given by Wordpress in post informations.
Try to do a var_dump on your query_posts result, you should find where the author name is stored, to display it properly.
Can you please show your loop template ? At least the part displaying the author.

Resources