How To display child comments under parent comment in WordPress - php

Currently child comments are not shown under parent comments
Below is the code
<ul class="comments-list">
<?php foreach ($comments as $comment): ?>
<li>
<div class="my-4">
<div class="comment-author-image">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/avatar.jpg" alt="search" class="search-icon-white">
</div>
<div class="comment-text">
<div class="comment-text-author"><?php echo $comment->comment_author; ?></div>
<div class="comment-text-content"><?php echo $comment->comment_content; ?></div>
<div class="comment-text-date"><?php display_human_readable_time($comment->comment_date); ?></div>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>

This can be done by following code:
$args = array(
'parent' => $comment_ID,
'hierarchical' => true,
);
$child_comments = get_comments($args);
You can also refer this documentation.

Related

how to display url taxonomy in loop taxonomy wordpress?

i have a custom taxonomy genre, i want to show all taxonomy in genre.php page. when I try to use this code php echo $term->slug;
the result does not meet my expectations :
http://localhost/site/action
I want the result like this :
http://localhost/site/genre/action
I don't know where the error is, I've been looking but haven't found a solution.
this is my code genre.php
<?php
/*
Template Name: Genre
*/
get_header(); ?>
<div class="content">
<div class="main-content">
<div class="main-container">
<div id="list_categories_categories_list">
<?php get_template_part( 'template-parts/ads-bottom' ); ?>
<div class="headline">
<h1>
Genre
</h1>
</div>
<div class="box">
<div class="list-categories">
<div class="margin-fix" id="list_categories_categories_list_items">
<?php
$terms = get_terms( array(
'taxonomy' => 'genre',
'hide_empty' => false,
'number' => 20
) );
foreach ($terms as $term){ ?>
<?php $image = get_term_meta( $term->term_id, 'image', true ); ?>
<a class="item" href="<?php echo $term->slug; ?>" title="<?php echo $term->name; ?>">
<div class="img">
<?php if ( $image != '' ) {
echo wp_get_attachment_image( $image, "", ["class" => "thumb"]);
}
?>
</div>
<strong class="title"><?php echo $term->name; ?></strong>
<div class="wrap">
<div class="videos">0 videos</div>
<div class="rating positive">
81%
</div>
</div>
</a>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
get_footer();
You can use this code it will give results as per your requirement.
<?php
/*
Template Name: Genre
*/
get_header(); ?>
<div class="content">
<div class="main-content">
<div class="main-container">
<div id="list_categories_categories_list">
<?php get_template_part( 'template-parts/ads-bottom' ); ?>
<div class="headline">
<h1>
Genre
</h1>
</div>
<div class="box">
<div class="list-categories">
<div class="margin-fix" id="list_categories_categories_list_items">
<?php
$terms = get_terms( array(
'taxonomy' => 'genre',
'hide_empty' => false,
'number' => 20
) );
foreach ($terms as $term){ ?>
<?php $image = get_term_meta( $term->term_id, 'image', true ); ?>
<a class="item" href="<?php echo get_term_link($term->term_id); ?>" title="<?php echo $term->name; ?>">
<div class="img">
<?php if ( $image != '' ) {
echo wp_get_attachment_image( $image, "", ["class" => "thumb"]);
}
?>
</div>
<strong class="title"><?php echo $term->name; ?></strong>
<div class="wrap">
<div class="videos">0 videos</div>
<div class="rating positive">
81%
</div>
</div>
</a>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
get_footer();?>

Show name, image and link of wordpress categories

I need to show some categories in my home page, and show the category image, and also the link of the same. Using the WORDPRESS.
For them to stick to the same style of example is not the problem. I'm having difficulties appearing, that is, the problem is in the code that calls the categories and their attributes like: image, link and title.
Example
Here's what I'm trying to do:
<section id=""
class="projects">
<div class="js-projects-gallery">
<div class="projects_block row">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$args = array(
'show_option_all' => '',
'echo' => 1,
'hide_empty' => 0,
'style' => 'list',
'title_li' => __('Categorias')
);
?>
<div class="project project_item col-sm-6 col-md-4 col-lg-3">
<?php foreach (get_categories($args) as $cat) : ?>
<a class="link" href="<?php echo get_category_link($cat->term_id); ?>"
title="<?php echo $cat->cat_name; ?>">
<figure>
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>"
class="size-goarch-image-480x880-croped">
<figcaption>
<h3 class="project-title">
<?php echo $cat->cat_name; ?>
</h3>
<h4 class="project-category">
<?php echo $cat->cat_name; ?>
</h4>
<div class="project-zoom"></div>
</figcaption>
</figure>
</a>
<?php endforeach; ?>
</div>
<?php endwhile; else: ?>
<div class="project project_item col-sm-6 col-md-4 col-lg-3">
<p><?php echo "Sorry, we have nothing posted yet."; ?></p>
</div>
<?php endif; ?>
</div>
</div>
</section>

Page navigation not working wordpress

So this is driving me kind of crazy, I just can't seem to get the page navigation to work. I installed a plugin wp-pagenavi but it still doesn't work. Is there anyone that could help me getting it to work. Here is my code (the loop):
<?php $args = array(
'post_type' => 'portfolio',
'posts_per_page'=> 10,
'orderby' => 'ID',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'foto_video_type',
'field' => 'slug',
'terms' => 'foto'
)
)
);
$products = new WP_Query( $args );
if( $products->have_posts() ) {
while( $products->have_posts() ) {
$products->the_post();
?>
<?php $naam = get_field('naambedrijf');
$soort = get_field('soort_uitje');
$foto = get_field('flickr_fotoset'); ?>
<div class="col s12">
<div class="title">
<h2 class="truncate" style="line-height:20px;"><?php echo $naam; ?> | <?php echo $soort; ?></h2>
<a class="fotos" href="https://www.flickr.com/photos/../sets/<?php echo $foto; ?>" target="_blank"><small>Bekijk alle foto's</small></a>
</div>
<div class="flickrphotoset">
<?php echo do_shortcode('[slickr-flickr id="" search="sets" set="' . $foto . '" size="large" items="9" bottom="10" responsive="on" type="thumbnail" galleria_options="lightbox:true;thumbnail:lazy"]'); ?>
</div>
</div>
<?php
}
}
else {
echo 'There seems to be a problem, please try searching again or contact customer support!';
} ?>
<?php wp_pagenavi(); ?>
And this is my archive code:
<section id="collaps">
<div class="row">
<div class="col s12 offset-s0 m12 l7 offset-l5">
<ul class="collapsible z-depth-1" data-collapsible="accordion">
<li>
<div class="collapsible-header"><i class="fa fa-camera" aria-hidden="true"></i><p>Foto</p></div>
<div id="portfolio" class="collapsible-body">
<div class="row">
<?php get_template_part('loop-foto'); ?>
<div class="col s12">
</div>
</div>
</div>
</li>
<li>
<div class="collapsible-header"><i class="fa fa-video-camera" aria-hidden="true"></i><p>Video</p></div>
<div id="portfolio" class="collapsible-body">
<div class="row">
<?php get_template_part('loop-video'); ?>
</div>
</div>
</li>
</ul>
</div>
</div>
</section>
When i add the "older" Wordpress code:
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries', '1000') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »', '1000') ?></div>
</div>
It kind of works. But page/2/ give a 404 error... What am I doing wrong?
I'm not sure if it is your case, but as I faced a similar case, I'm going to post my solution here:
In my case the problem was that I had a page with a permalink equal to the post type, so just changing the page slug solved the problem.

Carousel uneven when there aren't equal number of posts

If I don't have 8 posts the carousel looks like this.
Here is the Wordpress loop
<div class="section-title">
<h1>Most Recent Post</h1>
</div>
<div id="recent-post-carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#recent-post-carousel" data-slide-to="0" class="active"></li>
<li data-target="#recent-post-carousel" data-slide-to="1"></li>
</ol>
<div class="carousel-inner">
<?php
// Get posts (tweak args as needed)
$i=0;
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'orderby' => "date",
'order' => "desc"
);
$posts = get_posts( $args );
?>
<?php foreach (array_chunk($posts, 4, true) as $posts) : ?>
<div class="item <?php if ($i==0){echo 'active';}?>">
<div class="row">
<?php foreach( $posts as $post ) : setup_postdata($post); ?>
<div class="col-sm-6">
<div class="single-post">
<div class="pull-left post-image">
<a href="#">
<?php the_post_thumbnail( 'full' ); ?>
<i class="fa fa-angle-right"></i>
</a>
</div>
<div class="pull-right post-details">
<p class="post-date">03 Dec 2014</p>
<p><?php echo $i?></p>
<h5><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?>
</h5></a>
<span>John doe</span>
<p><?php echo substr(get_the_excerpt(), 0,99).' [...]'; ?></p>
</div>
</div>
</div>
<?php $i++ ?>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
Not sure if it has something to do with wordpress, i tried it on a static page and it worked fine. one way to fix it is to remove left or right margin from the col-sm-6, but i don't think this is a good way to do things.
I have created a fiddle for you. In fiddle above one is your case and the below one is Case with min-height(solved).
**https://jsfiddle.net/Anuj_Kumar/L5uduxLr/1/embedded/result/**
If still it's not fixed then try adding class "cleafix" with "single-post".

Why isn't my WP Query showing posts from a specified category?

I'm working on a Wordpress site. I'm trying to make a category with the id 968 show up on the Wordpress site under the stories and successes div. However for some reason the stories and successes div is not having the content from the category inserted into it. Any information on how I can improve my query or PHP is much appreciated. If I need to update this post with more information please let me know. Below you will see the php template file I am using.
<?php
/**
* Template name: Random Template
*
*
*/
// Custom styles
wp_enqueue_style('stories-styles', get_bloginfo('stylesheet_directory') . '/assets/css/stories.css');
// TEMP -- Get the category from the slug
the_post();
$categorySlugs = array(
'religious-freedom' => 'religious-freedom',
'social-and-economic-justice' => 'social-and-economic-justice',
'civil-and-human-rights' => 'civil-and-human-rights'
);
// Get category
$categorySlugs = $categorySlugs[$post->post_name];
$storyQuery = new WP_Query(array(
'post_type' => array('stories', 'press-releases'),
'category_name' => $categorySlugs,
'posts_per_page' => 4,
'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
));
$successesQuery = new WP_Query(array(
'post_type' => 'stories',
'cat' => 968,
'posts_per_page' => 1,
'offset' => 5
));
// Remove yarpp
remove_filter('the_content', array($yarpp, 'the_content'), 1200);
?>
<?php get_header(); ?>
<div class="category-title">
<div class="container">
<h2><?php the_title() ?></h2>
</div>
</div>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div class="container">
<div class="row">
<div class="col-md-12">
<?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?>
<article class="featured-issue-article">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail('full', array( 'class' => "img-responsive attachment-post-thumbnail")); ?>
</div>
<?php endif; ?>
<div class="content">
<?php the_content() ?>
</div>
</article>
</div>
</div>
<hr class="large blue" />
<div class="row">
<div class="col-md-8">
<ul class="section-list">
<?php while ($storyQuery->have_posts()) : $storyQuery->the_post(); ?>
<li>
<h3><?php the_title() ?></h3>
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail('post-thumbnail', array( 'class' => "img-responsive attachment-post-thumbnail")); ?>
<?php endif; ?>
<?php if( get_field('custom_excerpt', $values_id)): ?>
<p><?php echo the_field('custom_excerpt'); ?></p>
<?php endif; ?>
<a class="more" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">Read More...</a>
</li>
<?php endwhile; ?>
</ul>
<?php
set_query_var('category_slug', $categorySlug);
get_template_part('issues-nav', 'bottom')
?>
<hr class="small blue" />
<div class="success-stories">
<h2>Stories & Successes</h2>
<ul>
<?php while ($successesQuery->have_posts()) : $successesQuery->the_post(); ?>
<li>
<h4>
<?php the_title() ?>
</h4>
<?= strip_tags($post->post_excerpt) ?>
<a class="more" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">Read More...</a>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
</div>
</div>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>

Categories