Add comment date to comment author div wordpress - wordpress

I'm trying to learn to use wordpress.
I'm trying to change comments layout and I want to join comment date to comment author data. But I am not getting it. For example, I have what is in first image but I want what it is in second. Can you help please? Thanks so much!

I think your main problem is that you want to customize the way the date is placed using only css but that's extremely hard.
The best thing for you to do is have your own custom comment code.
Wordpress let's you have your own comments code.
For example when you call the comment template code instead of doing this:
wp_list_comments( array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 42,
) );
You can do something like this:
<ol class="commentlist">
<?php wp_list_comments( 'type=comment&callback=mytheme_comment' ); ?>
</ol>
And on the function.php file you can add the mytheme_comment function with the original comment code that wp has and reaarrange the classes and html code placement so you can have the date where you want.
function mytheme_comment($comment, $args, $depth) {
if ( 'div' === $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
?>
</div>
<?php comment_text(); ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php
}
In the default code you can see that the code:
<?php
/* translators: 1: date, 2: time */
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() );
?>
is what gives you the date information.
Hope you understanded this.
Here's the original WP documentation about this:
wp list comments

Related

wordpress blog homepage customization

please don't give a negative feed like always and instead tell me the mistake.
I have a blog.
can i make the homepage display a summary of an article instead of the whole article?
if yes then where or how can i do it?
I have this pre-set in one of my WordPress sites. Here is what this looks like and it is in Appearance/Editor/Posts Page (home.php)
<div class="post-content">
<?php $content = get_the_content(); ?>
<?php echo wp_trim_words(strip_tags($content), 30); ?>
</div>
<a class="blog-post-read-more" href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>"><?php echo esc_html( get_theme_mod( 'relia_blog_read_more', __( 'Read More', 'relia' ) ) ); ?></a>
</div>
So what this does is it will strip the words up to 30, wp_trim_words. And below that is the how to insert Read More.
Here are some links for you to check out:
https://codex.wordpress.org/Excerpt
https://codex.wordpress.org/Customizing_the_Read_More
Create one custom template that template you can assign your home page
/*
Template Name: Blog
*/
query_posts( array( 'post_type' => 'post', 'posts_per_page' => 6, 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ) ) );
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format()); ?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
wp_reset_postdata();

Wordpress List Child Pages like a Category

I'm trying to create a page in Wordpress that acts like a Category page listing the child pages. (like it would on the category page). I would like to add a custom field as the excerpt since pages don't have excerpts (unless there's a simple plugin suggestion for this)
I've been trying to merge a few examples, but not getting the correct end result.
<?php if ( is_page( 777 ) ) : ?>
<?php
$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( 'the_content', $content );
?>
<div class="entry-header"><h2 class="entry-title"><?php echo $page->post_title; ?></h2></div>
<?
$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT');
if ( $child_pages ) :
foreach ( $child_pages as $pageChild ) :
setup_postdata( $pageChild );
$thumbnail = get_the_post_thumbnail($pageChild->ID, 'thumbnail', array( 'class' => 'alignleft' ));
?>
<div class="child-thumb">
<a href="<?= get_permalink($pageChild->ID) ?>" rel="bookmark" title="<?= $pageChild->post_title ?>">
<?= $thumbnail ?>
</a>
</div>
<div class="entry-summary"><?php the_excerpt(); ?></div>
<? endforeach; endif; ?>
<?php } ?>
<?php endif; ?>
Found two simple plugins that do the trick.
https://wordpress.org/plugins/page-list/
https://wordpress.org/plugins/page-excerpt/

WordPress - How to get the category name in WP_Query

I'm querying custom posts types and can't get the name of the category the post belongs to. Feel like I've tried everything but sure it must be possible!
<?php
global $wpdb;
$currentuser_id = get_current_user_id();
$args = array(
'post_type' => 'location',
'author' => $currentuser_id,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="pindex">
<?php if ( has_post_thumbnail() ) { ?>
<div class="pimage">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="ptitle">
<h2><?php echo get_the_title(); ?></h2>
</div>
<div class="pcategory">
</div>
</div>
<?php endwhile;
if ( $query->max_num_pages > 1 ) : ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Previous', 'domain' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Next <span class="meta-nav">→</span>', 'domain' ) ); ?></div>
</div>
<?php endif;
endif;
wp_reset_postdata();
?>
Does anybody know the code that would go between the below to get the category name?
<div class="pcategory">
</div>
Thanks in advance for any help!
<?php
$terms = get_the_terms( $post->ID , 'gd_placecategory' );
foreach ( $terms as $term ) {
echo $term->name;
}
?>
As it's a custom post type get_the_terms() is required
Note that you pass the custom post type into the WP_Query - 'location' in this case, however you need the custom taxonomy in get_the_terms() 'gd_placecategory'

Wordpress Attachment Page Title

I would like to change the download link title on the attachment page to say Download link : ATTACHMENT_TITLE. Where do I start? The theme has no attachment.php
EDIT :
I've found that I could edit single.php
<?php if ( is_attachment() ) { echo "Download Link : "; } ?>
<?php get_template_part( 'content', 'single' ); ?>
That puts the text above the link. It would be nice to be inline with the link. I am looking at content-single.php now. That calls a function called the_content(); If I could follow where that function goes maybe I could put the "Download Link : " text within the div itself before the link.
content-single.php
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php do_action( 'esteem_before_post_content' ); ?>
<div class="entry-content clearfix">
<?php
the_content();
$esteem_tag_list = get_the_tag_list( '', ' ', '' );
if( !empty( $esteem_tag_list ) ) {
?>
<div class="tags">
<?php
_e( 'Tagged on: ', 'esteem' ); echo $esteem_tag_list;
?>
</div>
<?php
}
wp_link_pages( array(
'before' => '<div style="clear: both;"></div><div class="pagination
clearfix">'.__( 'Pages:', 'esteem' ),
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>'
) );
?>
</div>
<div class="entry-meta-bar clearfix">
<div class="entry-meta clearfix">
<span class="icon-user"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID'
) ); ?>"><?php the_author(); ?></a></span>
<span class="icon-time"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr(
get_the_time() ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a></span>
<?php if( has_category() ) { ?>
<span class="icon-tag"><?php the_category(', '); ?></span>
<?php } ?>
<?php if ( comments_open() ) { ?>
<span class="icon-comment-alt"><?php comments_popup_link( __( 'No Comments', 'esteem' ), __(
'1 Comment', 'esteem' ), __( '% Comments', 'esteem' ), '', __( 'Comments Off', 'esteem' ) ); ?></span>
<?php } ?>
<?php edit_post_link( __( 'Edit', 'esteem' ), '<span class="icon-pencil">', '</span>' ); ?>
</div><!-- .entry-meta -->
</div><!-- .entry-meta-bar -->
<?php
do_action( 'esteem_after_post_content' );
?>
</article>
Here is the base code you can use in the page template:
<?php
$attachment_id = 1; // ID of attachment
$attachment_page = get_attachment_link( $attachment_id );
?>
Download Link**
Reference: http://codex.wordpress.org/Function_Reference/get_attachment_link
Note: If you want to modify the attachment page, you can either modify (if it exists) the attachments.php template or create one. The template hierarchy reference is here: http://codex.wordpress.org/Template_Hierarchy
EDIT:
Ok I found a simpler solution for you. On your single.php page wrap the content-single.php template part in an if statement. You can use this for the base of what you're trying to do. Give it a shot and let me know how it goes.
<?php if ( is_attachment() ) {
$attachment_link = wp_get_attachment_url();
echo 'Download Link';
} else {
get_template_part( 'content', 'single' );
} ?>

How do you get the mp3 file extension from an iTunes feed and display it in a WP loop?

I want to pull the 5 most recent podcasts from an iTunes feed and post them along with their audio to a WP page.
The code I have is below
its pulling the feed and displaying the name, details, etc fine but its using the same podcast audio for each item.
<div class="podcastfeed">
<h4>Recent Podcasts</h4>
<?php // Get $feed Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$hpFeed=get_post_meta($post->ID, "cmb_hp_feed", true);
$feed = fetch_feed( $hpFeed );
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items() as $item)
{
if ($enclosure = $item->get_enclosure())
{
$enclosure->get_link();
}
}
if ( ! is_wp_error( $feed ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $feed->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$feed_items = $feed->get_items( 0, $maxitems );
endif;
$attr = array(
'src' => $enclosure->get_link(),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
?>
<ol>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( 'No items', 'my-text-domain' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $feed_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>">
<p>
<span>
<?php echo esc_html( $item->get_title() ); ?>
</span>
<span><?php printf( __( '%s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?></span>
</p>
</a>
<?php echo wp_audio_shortcode( $attr );?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ol>
</div>
I got it working in the end though it took some fiddling with
The page is now displaying each of the podcasts as audio.
<div class="podcastfeed">
<?php // Get $feed Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$hpFeed=get_post_meta($post->ID, "cmb_hp_feed", true);
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( $hpFeed );
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<?php if ( $maxitems == 0 ) : ?>
<ol style="display:none;"><?php _e( 'No items', 'my-text-domain' ); ?></ol>
<?php else : ?>
<h4>Recent Podcasts</h4>
<ol>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>">
<p>
<span>
<?php echo esc_html( $item->get_title() ); ?>
</span>
<span>
<?php printf( __( '%s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>
</span>
</p>
</a>
<?php
if ($enclosure = $item->get_enclosure()){
$enclosure->get_link();
}
?>
<?php
$attr = array(
'src' => $enclosure->get_link(),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
?>
<?php echo wp_audio_shortcode( $attr );?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ol>
</div>

Resources