-
AuthorPosts
-
October 4, 2015 at 5:58 am #610057
Jonathan SParticipantHi folks is there anyway of adding a category tag/text to recent post containers? (example attached)
style is irrelevant – i just want something to differentiate each one based on their category…
https://goo.gl/photos/Phbf5NedQgLUBARs8October 4, 2015 at 6:45 am #610079
ChristopherModeratorHi there,
Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.
Add following code in child theme’s functions.php :
// Add category name to recent posts shortcode // ============================================================================= function x_shortcode_recent_posts_v2code( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => '', 'count' => '', 'category' => '', 'enable_excerpt' => '', 'offset' => '', 'orientation' => '', 'no_image' => '', 'fade' => '' ), $atts ) ); $id = ( $id != '' ) ? 'id="' . esc_attr( $id ) . '"' : ''; $class = ( $class != '' ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf'; $style = ( $style != '' ) ? 'style="' . $style . '"' : ''; $type = ( $type == 'portfolio' ) ? 'x-portfolio' : 'post'; $count = ( $count != '' ) ? $count : 3; $category = ( $category != '' ) ? $category : ''; $category_type = ( $type == 'post' ) ? 'category_name' : 'portfolio-category'; $offset = ( $offset != '' ) ? $offset : 0; $orientation = ( $orientation != '' ) ? ' ' . $orientation : ' horizontal'; $no_image = ( $no_image == 'true' ) ? $no_image : ''; $fade = ( $fade == 'true' ) ? $fade : 'false'; $enable_excerpt = ( $enable_excerpt == 'true' ) ? true : false; $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} data-fade=\"{$fade}\">"; $q = new WP_Query( array( 'orderby' => 'date', 'post_type' => "{$type}", 'posts_per_page' => "{$count}", 'offset' => "{$offset}", "{$category_type}" => "{$category}" ) ); if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); if ( $no_image == 'true' ) { $image_output = ''; $image_output_class = 'no-image'; } else { $image_output = '<div class="x-recent-posts-img">' . get_the_post_thumbnail( get_the_ID(), 'entry-' . get_theme_mod( 'x_stack' ) . '-cropped', NULL ) . '</div>'; $image_output_class = 'with-image'; } $cat_name = get_the_category(); $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ) . '">' . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">' . '<div class="entry-wrap">' . $image_output . '<div class="x-recent-posts-content">' . '<div class="latest-post-cat">' . $cat_name[0]->name . '</div>' . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>' . '<span class="x-recent-posts-date">' . get_the_date() . '</span>' // . '<span class="x-recent-posts-excerpt">' . excerpt(25) . '' . '</div>' . '</div>' . '</article>' . '</a>'; endwhile; endif; wp_reset_postdata(); $output .= '</div>'; return $output; } add_action('wp_head', 'change_recent_posts_to_v2'); function change_recent_posts_to_v2() { remove_shortcode( 'x_recent_posts' ); add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2code' ); }Hope it helps.
October 4, 2015 at 8:10 am #610128
Jonathan SParticipantGreat thank you for getting back to me, the code supplied didn’t appear to do anything however, i found something similar (posted from back in March below [https://community.theme.co/forums/topic/recent-posts-adding-catorgies-meta/]) – i kind of did the trick in terms of adding the category text -but it messed up my boxes (pic attached)
any ideas>//////////////////////////////////////
// Recent Posts Custom
// =============================================================================function excerpt($limit) {
$excerpt = explode(‘ ‘, get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(” “,$excerpt).’.’;
} else {
$excerpt = implode(” “,$excerpt);
}
$excerpt = preg_replace(‘@\[[^\]]*\]@’,”,$excerpt);
return $excerpt;
}function x_shortcode_recent_posts_v2( $atts ) {
extract( shortcode_atts( array(
‘id’ => ”,
‘class’ => ”,
‘style’ => ”,
‘type’ => ”,
‘count’ => ”,
‘category’ => ”,
‘offset’ => ”,
‘orientation’ => ”,
‘no_image’ => ”,
‘fade’ => ”
), $atts ) );$id = ( $id != ” ) ? ‘id=”‘ . esc_attr( $id ) . ‘”‘ : ”;
$class = ( $class != ” ) ? ‘x-recent-posts cf ‘ . esc_attr( $class ) : ‘x-recent-posts cf’;
$style = ( $style != ” ) ? ‘style=”‘ . $style . ‘”‘ : ”;
$type = ( $type == ‘portfolio’ ) ? ‘x-portfolio’ : ‘post’;
$count = ( $count != ” ) ? $count : 3;
$category = ( $category != ” ) ? $category : ”;
$category_type = ( $type == ‘post’ ) ? ‘category_name’ : ‘portfolio-category’;
$offset = ( $offset != ” ) ? $offset : 0;
$orientation = ( $orientation != ” ) ? ‘ ‘ . $orientation : ‘ horizontal’;
$no_image = ( $no_image == ‘true’ ) ? $no_image : ”;
$fade = ( $fade == ‘true’ ) ? $fade : ‘false’;$output = “<div {$id} class=\”{$class}{$orientation}\” {$style} data-fade=\”{$fade}\”>”;
$q = new WP_Query( array(
‘orderby’ => ‘date’,
‘post_type’ => “{$type}”,
‘posts_per_page’ => “{$count}”,
‘offset’ => “{$offset}”,
“{$category_type}” => “{$category}”
) );if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
if ( $no_image == ‘true’ ) {
$image_output = ”;
$image_output_class = ‘no-image’;
} else {
$image_output = ‘<div class=”x-recent-posts-img”>’ . get_the_post_thumbnail( get_the_ID(), ‘entry-cropped’, NULL ) . ‘</div>’;
$image_output_class = ‘with-image’;
}$cat_name = get_the_category();
endwhile; endif; wp_reset_postdata();
$output .= ‘</div>’;
return $output;
}add_action(‘wp_head’, ‘change_recent_posts_to_v2’);
function change_recent_posts_to_v2() {
remove_shortcode( ‘recent_posts’ );
add_shortcode( ‘recent_posts’, ‘x_shortcode_recent_posts_v2’ );
}October 4, 2015 at 8:40 am #610141
ChristopherModeratorHi there,
I just tried the code I provided in my previous replay and I can confirm that it works fine with less styling issue, see the attachment.
Please add the code and make sure you clear cache.
Thanks.
October 4, 2015 at 8:59 am #610151
Jonathan SParticipantHi still not getting result would you mnd casting an eye over the code to make sure its all in the right place? many thanks…..
<?php
// =============================================================================
// FUNCTIONS/INTEGRITY.PHP
// —————————————————————————–
// Integrity specific functions.
// =============================================================================// =============================================================================
// TABLE OF CONTENTS
// —————————————————————————–
// 01. Entry Meta
// 02. Portfolio Tags
// 03. Individual Comment
// =============================================================================// Entry Meta
// =============================================================================if ( ! function_exists( ‘x_integrity_entry_meta’ ) ) :
function x_integrity_entry_meta() {//
// Author.
//$author = sprintf( ‘<span><i class=”x-icon-pencil” data-x-icon=””></i> %s</span>’,
get_the_author()
);//
// Date.
//$date = sprintf( ‘<span><time class=”entry-date” datetime=”%1$s”><i class=”x-icon-calendar” data-x-icon=””></i> %2$s</time></span>’,
esc_attr( get_the_date( ‘c’ ) ),
esc_html( get_the_date() )
);//
// Categories.
//if ( get_post_type() == ‘x-portfolio’ ) {
if ( has_term( ”, ‘portfolio-category’, NULL ) ) {
$categories = get_the_terms( get_the_ID(), ‘portfolio-category’ );
$separator = ‘, ‘;
$categories_output = ”;
foreach ( $categories as $category ) {
$categories_output .= ‘<a href=”‘
. get_term_link( $category->slug, ‘portfolio-category’ )
. ‘” title=”‘
. esc_attr( sprintf( __( “View all posts in: “%s””, ‘__x__’ ), $category->name ) )
. ‘”><i class=”x-icon-bookmark” data-x-icon=””></i> ‘
. $category->name
. ‘‘
. $separator;
}$categories_list = sprintf( ‘<span>%s</span>’,
trim( $categories_output, $separator )
);
} else {
$categories_list = ”;
}
} else {
$categories = get_the_category();
$separator = ‘, ‘;
$categories_output = ”;
foreach ( $categories as $category ) {
$categories_output .= ‘<a href=”‘
. get_category_link( $category->term_id )
. ‘” title=”‘
. esc_attr( sprintf( __( “View all posts in: “%s””, ‘__x__’ ), $category->name ) )
. ‘”><i class=”x-icon-bookmark” data-x-icon=””></i> ‘
. $category->name
. ‘‘
. $separator;
}$categories_list = sprintf( ‘<span>%s</span>’,
trim( $categories_output, $separator )
);
}
function my_new_action() {
if ( is_singular(‘post’) ) : ?><?php echo do_shortcode(‘<h5>Also on Deeside.com</h5>[recent_posts type=”post” count=”3″ orientation=”horizontal”]’); ?>
<?php endif;
}add_action( ‘x_before_the_content_end’, ‘my_new_action’, 10 );
//
// Comments link.
//if ( comments_open() ) {
$title = apply_filters( ‘x_entry_meta_comments_title’, get_the_title() );
$link = apply_filters( ‘x_entry_meta_comments_link’, get_comments_link() );
$number = apply_filters( ‘x_entry_meta_comments_number’, get_comments_number() );if ( $number == 0 ) {
$text = __( ‘Leave a Comment’ , ‘__x__’ );
} else if ( $number == 1 ) {
$text = $number . ‘ ‘ . __( ‘Comment’ , ‘__x__’ );
} else {
$text = $number . ‘ ‘ . __( ‘Comments’ , ‘__x__’ );
}$comments = sprintf( ‘<span><i class=”x-icon-comments” data-x-icon=””></i> %3$s</span>’,
esc_url( $link ),
esc_attr( sprintf( __( ‘Leave a comment on: “%s”’, ‘__x__’ ), $title ) ),
$text
);} else {
$comments = ”;
}
//
// Output.
//if ( x_does_not_need_entry_meta() ) {
return;
} else {
printf( ‘<p class=”p-meta”>%1$s%2$s%3$s%4$s</p>’,
$author,
$date,
$categories_list,
$comments
);
}}
endif;// Portfolio Tags
// =============================================================================if ( ! function_exists( ‘x_integrity_portfolio_tags’ ) ) :
function x_integrity_portfolio_tags() {$terms = get_the_terms( get_the_ID(), ‘portfolio-tag’ );
echo ‘<ul class=”x-ul-icons”>’;
foreach( $terms as $term ) {
echo ‘<li class=”x-li-icon”>slug, ‘portfolio-tag’ ) . ‘”><i class=”x-icon-check” data-x-icon=””></i>’ . $term->name . ‘‘;
};
echo ‘‘;}
endif;// Individual Comment
// =============================================================================//
// 1. Pingbacks and trackbacks.
// 2. Normal Comments.
//if ( ! function_exists( ‘x_integrity_comment’ ) ) :
function x_integrity_comment( $comment, $args, $depth ) {$GLOBALS[‘comment’] = $comment;
switch ( $comment->comment_type ) :
case ‘pingback’ : // 1
case ‘trackback’ : // 1
?>
<li <?php comment_class(); ?> id=”comment-<?php comment_ID(); ?>”>
<p><?php _e( ‘Pingback:’, ‘__x__’ ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( ‘(Edit)’, ‘__x__’ ), ‘<span class=”edit-link”>’, ‘</span>’ ); ?></p>
<?php
break;
default : // 2
GLOBAL $post;
if ( X_WOOCOMMERCE_IS_ACTIVE ) :
$rating = esc_attr( get_comment_meta( $GLOBALS[‘comment’]->comment_ID, ‘rating’, true ) );
endif;
$avatar_variation = ( x_is_product() ) ? ‘ x-img-thumbnail’ : ”;
?>
<li id=”li-comment-<?php comment_ID(); ?>” <?php comment_class(); ?>>
<?php
printf( ‘<div class=”x-comment-img”>%1$s %2$s</div>’,
‘<span class=”avatar-wrap cf’ . $avatar_variation . ‘”>’ . get_avatar( $comment, 120 ) . ‘</span>’,
( $comment->user_id === $post->post_author ) ? ‘<span class=”bypostauthor”>’ . __( ‘Post<br>Author’, ‘__x__’ ) . ‘</span>’ : ”
);
?>
<article id=”comment-<?php comment_ID(); ?>” class=”comment”>
<header class=”x-comment-header”>
<?php
printf( ‘<cite class=”x-comment-author”>%1$s</cite>’,
get_comment_author_link()
);
printf( ‘<div><time datetime=”%2$s”>%3$s</time></div>’,
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( ‘c’ ),
sprintf( __( ‘%1$s at %2$s’, ‘__x__’ ),
get_comment_date(),
get_comment_time()
)
);
edit_comment_link( __( ‘<i class=”x-icon-edit” data-x-icon=””></i> Edit’, ‘__x__’ ) );
?>
<?php if ( x_is_product() && get_option(‘woocommerce_enable_review_rating’) == ‘yes’ ) : ?>
<div class=”star-rating-container”>
<div itemprop=”reviewRating” itemscope itemtype=”http://schema.org/Rating” class=”star-rating” title=”<?php echo sprintf( __( ‘Rated %d out of 5’, ‘__x__’ ), $rating ) ?>”>
<span style=”width:<?php echo ( intval( get_comment_meta( $GLOBALS[‘comment’]->comment_ID, ‘rating’, true ) ) / 5 ) * 100; ?>%”><strong itemprop=”ratingValue”><?php echo intval( get_comment_meta( $GLOBALS[‘comment’]->comment_ID, ‘rating’, true ) ); ?> <?php _e( ‘out of 5’, ‘__x__’ ); ?></span>
</div>
</div>
<?php endif; ?>
</header>
<?php if ( ‘0’ == $comment->comment_approved ) : ?>
<p class=”x-comment-awaiting-moderation”><?php _e( ‘Your comment is awaiting moderation.’, ‘__x__’ ); ?></p>
<?php endif; ?>
<section class=”x-comment-content”>
<?php comment_text(); ?>
</section>
<?php if ( ! x_is_product() ) : ?>
<div class=”x-reply”>
<?php comment_reply_link( array_merge( $args, array( ‘reply_text’ => __( ‘Reply <span class=”comment-reply-link-after”><i class=”x-icon-reply” data-x-icon=””></i></span>’, ‘__x__’ ), ‘depth’ => $depth, ‘max_depth’ => $args[‘max_depth’] ) ) ); ?>
</div>
<?php endif; ?>
</article>
<?php
break;
endswitch;}
endif;// Add category name to recent posts shortcode
// =============================================================================
function x_shortcode_recent_posts_v2code( $atts ) {
extract( shortcode_atts( array(
‘id’ => ”,
‘class’ => ”,
‘style’ => ”,
‘type’ => ”,
‘count’ => ”,
‘category’ => ”,
‘enable_excerpt’ => ”,
‘offset’ => ”,
‘orientation’ => ”,
‘no_image’ => ”,
‘fade’ => ”
), $atts ) );$id = ( $id != ” ) ? ‘id=”‘ . esc_attr( $id ) . ‘”‘ : ”;
$class = ( $class != ” ) ? ‘x-recent-posts cf ‘ . esc_attr( $class ) : ‘x-recent-posts cf’;
$style = ( $style != ” ) ? ‘style=”‘ . $style . ‘”‘ : ”;
$type = ( $type == ‘portfolio’ ) ? ‘x-portfolio’ : ‘post’;
$count = ( $count != ” ) ? $count : 3;
$category = ( $category != ” ) ? $category : ”;
$category_type = ( $type == ‘post’ ) ? ‘category_name’ : ‘portfolio-category’;
$offset = ( $offset != ” ) ? $offset : 0;
$orientation = ( $orientation != ” ) ? ‘ ‘ . $orientation : ‘ horizontal’;
$no_image = ( $no_image == ‘true’ ) ? $no_image : ”;
$fade = ( $fade == ‘true’ ) ? $fade : ‘false’;
$enable_excerpt = ( $enable_excerpt == ‘true’ ) ? true : false;$output = “<div {$id} class=\”{$class}{$orientation}\” {$style} data-fade=\”{$fade}\”>”;
$q = new WP_Query( array(
‘orderby’ => ‘date’,
‘post_type’ => “{$type}”,
‘posts_per_page’ => “{$count}”,
‘offset’ => “{$offset}”,
“{$category_type}” => “{$category}”
) );if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
if ( $no_image == ‘true’ ) {
$image_output = ”;
$image_output_class = ‘no-image’;
} else {
$image_output = ‘<div class=”x-recent-posts-img”>’ . get_the_post_thumbnail( get_the_ID(), ‘entry-‘ . get_theme_mod( ‘x_stack’ ) . ‘-cropped’, NULL ) . ‘</div>’;
$image_output_class = ‘with-image’;
}$cat_name = get_the_category();
endwhile; endif; wp_reset_postdata();
$output .= ‘</div>’;
return $output;
}add_action(‘wp_head’, ‘change_recent_posts_to_v2’);
function change_recent_posts_to_v2() {
remove_shortcode( ‘x_recent_posts’ );
add_shortcode( ‘x_recent_posts’, ‘x_shortcode_recent_posts_v2code’ );
}October 4, 2015 at 9:03 am #610152
ThaiModeratorHi There,
In this case, would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:
β Link to your site
β WordPress Admin username / Password
β FTP AccountDonβt forget to select Set as a private reply. This ensures your information is only visible to our staff.
Thanks.
October 4, 2015 at 11:29 am #610216
Jonathan SParticipantThis reply has been marked as private.October 4, 2015 at 6:39 pm #610472
LelyModeratorHello Jonathan,
Unfortunately, my IP address is not allowed to access your WP admin link. I did login to your FTP and check functions.php file inside /public_html/wp-content/themes/x-child. I found out that the code suggested above is not yet added or did you remove it? Please add the function from this reply:https://community.theme.co/forums/topic/adding-category-tagtext-to-recent-post-box/#post-610079 and then use the recent post shortcode to display. If it still doesn’t work, please enable our IP to access your admin and point us to the page URL where it is supposed to be working. Thank you.
October 5, 2015 at 8:28 am #611204
Jonathan SParticipantHi thanks, ive added the code to the main theme and not the child theme, will do that at some point if i can manage to make it work, the admin is locked down as the site was hit by thousands of ip’s from a spam site – i’m talking to the server guys to get it lifted however i may have top abandon the request if they are reluctant to open it up again.
Plan B i guess is to perhaps deconstruct the other code i found (posted above) which worked in so much as adding the text, it just disfigured the content boxes.
will be in touch
thanks again for all your help.
October 5, 2015 at 8:46 am #611230
ChristopherModeratorHi there,
I was able to connect to FTP but functions.php is empty (/public_html/wp-content/themes/x-child), also child theme is not activated in your site.
Thanks.
October 5, 2015 at 9:03 am #611263
Jonathan SParticipanthi i know about the child theme will start to use after this but see file attached..
October 5, 2015 at 9:04 am #611265
Jonathan SParticipantwoops sorry: you can see the code included her- its in the right place?
<?php
// =============================================================================
// FUNCTIONS/INTEGRITY.PHP
// —————————————————————————–
// Integrity specific functions.
// =============================================================================// =============================================================================
// TABLE OF CONTENTS
// —————————————————————————–
// 01. Entry Meta
// 02. Portfolio Tags
// 03. Individual Comment
// =============================================================================// Entry Meta
// =============================================================================if ( ! function_exists( ‘x_integrity_entry_meta’ ) ) :
function x_integrity_entry_meta() {//
// Author.
//$author = sprintf( ‘<span><i class=”x-icon-pencil” data-x-icon=””></i> %s</span>’,
get_the_author()
);//
// Date.
//$date = sprintf( ‘<span><time class=”entry-date” datetime=”%1$s”><i class=”x-icon-calendar” data-x-icon=””></i> %2$s</time></span>’,
esc_attr( get_the_date( ‘c’ ) ),
esc_html( get_the_date() )
);//
// Categories.
//if ( get_post_type() == ‘x-portfolio’ ) {
if ( has_term( ”, ‘portfolio-category’, NULL ) ) {
$categories = get_the_terms( get_the_ID(), ‘portfolio-category’ );
$separator = ‘, ‘;
$categories_output = ”;
foreach ( $categories as $category ) {
$categories_output .= ‘<a href=”‘
. get_term_link( $category->slug, ‘portfolio-category’ )
. ‘” title=”‘
. esc_attr( sprintf( __( “View all posts in: “%s””, ‘__x__’ ), $category->name ) )
. ‘”><i class=”x-icon-bookmark” data-x-icon=””></i> ‘
. $category->name
. ‘‘
. $separator;
}$categories_list = sprintf( ‘<span>%s</span>’,
trim( $categories_output, $separator )
);
} else {
$categories_list = ”;
}
} else {
$categories = get_the_category();
$separator = ‘, ‘;
$categories_output = ”;
foreach ( $categories as $category ) {
$categories_output .= ‘<a href=”‘
. get_category_link( $category->term_id )
. ‘” title=”‘
. esc_attr( sprintf( __( “View all posts in: “%s””, ‘__x__’ ), $category->name ) )
. ‘”><i class=”x-icon-bookmark” data-x-icon=””></i> ‘
. $category->name
. ‘‘
. $separator;
}$categories_list = sprintf( ‘<span>%s</span>’,
trim( $categories_output, $separator )
);
}
function my_new_action() {
if ( is_singular(‘post’) ) : ?><?php echo do_shortcode(‘<h5>Also on Deeside.com</h5>[recent_posts type=”post” count=”3″ orientation=”horizontal”]’); ?>
<?php endif;
}add_action( ‘x_before_the_content_end’, ‘my_new_action’, 10 );
//
// Comments link.
//if ( comments_open() ) {
$title = apply_filters( ‘x_entry_meta_comments_title’, get_the_title() );
$link = apply_filters( ‘x_entry_meta_comments_link’, get_comments_link() );
$number = apply_filters( ‘x_entry_meta_comments_number’, get_comments_number() );if ( $number == 0 ) {
$text = __( ‘Leave a Comment’ , ‘__x__’ );
} else if ( $number == 1 ) {
$text = $number . ‘ ‘ . __( ‘Comment’ , ‘__x__’ );
} else {
$text = $number . ‘ ‘ . __( ‘Comments’ , ‘__x__’ );
}$comments = sprintf( ‘<span><i class=”x-icon-comments” data-x-icon=””></i> %3$s</span>’,
esc_url( $link ),
esc_attr( sprintf( __( ‘Leave a comment on: “%s”’, ‘__x__’ ), $title ) ),
$text
);} else {
$comments = ”;
}
//
// Output.
//if ( x_does_not_need_entry_meta() ) {
return;
} else {
printf( ‘<p class=”p-meta”>%1$s%2$s%3$s%4$s</p>’,
$author,
$date,
$categories_list,
$comments
);
}}
endif;// Portfolio Tags
// =============================================================================if ( ! function_exists( ‘x_integrity_portfolio_tags’ ) ) :
function x_integrity_portfolio_tags() {$terms = get_the_terms( get_the_ID(), ‘portfolio-tag’ );
echo ‘<ul class=”x-ul-icons”>’;
foreach( $terms as $term ) {
echo ‘<li class=”x-li-icon”>slug, ‘portfolio-tag’ ) . ‘”><i class=”x-icon-check” data-x-icon=””></i>’ . $term->name . ‘‘;
};
echo ‘‘;}
endif;// Individual Comment
// =============================================================================//
// 1. Pingbacks and trackbacks.
// 2. Normal Comments.
//if ( ! function_exists( ‘x_integrity_comment’ ) ) :
function x_integrity_comment( $comment, $args, $depth ) {$GLOBALS[‘comment’] = $comment;
switch ( $comment->comment_type ) :
case ‘pingback’ : // 1
case ‘trackback’ : // 1
?>
<li <?php comment_class(); ?> id=”comment-<?php comment_ID(); ?>”>
<p><?php _e( ‘Pingback:’, ‘__x__’ ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( ‘(Edit)’, ‘__x__’ ), ‘<span class=”edit-link”>’, ‘</span>’ ); ?></p>
<?php
break;
default : // 2
GLOBAL $post;
if ( X_WOOCOMMERCE_IS_ACTIVE ) :
$rating = esc_attr( get_comment_meta( $GLOBALS[‘comment’]->comment_ID, ‘rating’, true ) );
endif;
$avatar_variation = ( x_is_product() ) ? ‘ x-img-thumbnail’ : ”;
?>
<li id=”li-comment-<?php comment_ID(); ?>” <?php comment_class(); ?>>
<?php
printf( ‘<div class=”x-comment-img”>%1$s %2$s</div>’,
‘<span class=”avatar-wrap cf’ . $avatar_variation . ‘”>’ . get_avatar( $comment, 120 ) . ‘</span>’,
( $comment->user_id === $post->post_author ) ? ‘<span class=”bypostauthor”>’ . __( ‘Post<br>Author’, ‘__x__’ ) . ‘</span>’ : ”
);
?>
<article id=”comment-<?php comment_ID(); ?>” class=”comment”>
<header class=”x-comment-header”>
<?php
printf( ‘<cite class=”x-comment-author”>%1$s</cite>’,
get_comment_author_link()
);
printf( ‘<div><time datetime=”%2$s”>%3$s</time></div>’,
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( ‘c’ ),
sprintf( __( ‘%1$s at %2$s’, ‘__x__’ ),
get_comment_date(),
get_comment_time()
)
);
edit_comment_link( __( ‘<i class=”x-icon-edit” data-x-icon=””></i> Edit’, ‘__x__’ ) );
?>
<?php if ( x_is_product() && get_option(‘woocommerce_enable_review_rating’) == ‘yes’ ) : ?>
<div class=”star-rating-container”>
<div itemprop=”reviewRating” itemscope itemtype=”http://schema.org/Rating” class=”star-rating” title=”<?php echo sprintf( __( ‘Rated %d out of 5’, ‘__x__’ ), $rating ) ?>”>
<span style=”width:<?php echo ( intval( get_comment_meta( $GLOBALS[‘comment’]->comment_ID, ‘rating’, true ) ) / 5 ) * 100; ?>%”><strong itemprop=”ratingValue”><?php echo intval( get_comment_meta( $GLOBALS[‘comment’]->comment_ID, ‘rating’, true ) ); ?> <?php _e( ‘out of 5’, ‘__x__’ ); ?></span>
</div>
</div>
<?php endif; ?>
</header>
<?php if ( ‘0’ == $comment->comment_approved ) : ?>
<p class=”x-comment-awaiting-moderation”><?php _e( ‘Your comment is awaiting moderation.’, ‘__x__’ ); ?></p>
<?php endif; ?>
<section class=”x-comment-content”>
<?php comment_text(); ?>
</section>
<?php if ( ! x_is_product() ) : ?>
<div class=”x-reply”>
<?php comment_reply_link( array_merge( $args, array( ‘reply_text’ => __( ‘Reply <span class=”comment-reply-link-after”><i class=”x-icon-reply” data-x-icon=””></i></span>’, ‘__x__’ ), ‘depth’ => $depth, ‘max_depth’ => $args[‘max_depth’] ) ) ); ?>
</div>
<?php endif; ?>
</article>
<?php
break;
endswitch;}
endif;// Add category name to recent posts shortcode
// =============================================================================
function x_shortcode_recent_posts_v2code( $atts ) {
extract( shortcode_atts( array(
‘id’ => ”,
‘class’ => ”,
‘style’ => ”,
‘type’ => ”,
‘count’ => ”,
‘category’ => ”,
‘enable_excerpt’ => ”,
‘offset’ => ”,
‘orientation’ => ”,
‘no_image’ => ”,
‘fade’ => ”
), $atts ) );$id = ( $id != ” ) ? ‘id=”‘ . esc_attr( $id ) . ‘”‘ : ”;
$class = ( $class != ” ) ? ‘x-recent-posts cf ‘ . esc_attr( $class ) : ‘x-recent-posts cf’;
$style = ( $style != ” ) ? ‘style=”‘ . $style . ‘”‘ : ”;
$type = ( $type == ‘portfolio’ ) ? ‘x-portfolio’ : ‘post’;
$count = ( $count != ” ) ? $count : 3;
$category = ( $category != ” ) ? $category : ”;
$category_type = ( $type == ‘post’ ) ? ‘category_name’ : ‘portfolio-category’;
$offset = ( $offset != ” ) ? $offset : 0;
$orientation = ( $orientation != ” ) ? ‘ ‘ . $orientation : ‘ horizontal’;
$no_image = ( $no_image == ‘true’ ) ? $no_image : ”;
$fade = ( $fade == ‘true’ ) ? $fade : ‘false’;
$enable_excerpt = ( $enable_excerpt == ‘true’ ) ? true : false;$output = “<div {$id} class=\”{$class}{$orientation}\” {$style} data-fade=\”{$fade}\”>”;
$q = new WP_Query( array(
‘orderby’ => ‘date’,
‘post_type’ => “{$type}”,
‘posts_per_page’ => “{$count}”,
‘offset’ => “{$offset}”,
“{$category_type}” => “{$category}”
) );if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
if ( $no_image == ‘true’ ) {
$image_output = ”;
$image_output_class = ‘no-image’;
} else {
$image_output = ‘<div class=”x-recent-posts-img”>’ . get_the_post_thumbnail( get_the_ID(), ‘entry-‘ . get_theme_mod( ‘x_stack’ ) . ‘-cropped’, NULL ) . ‘</div>’;
$image_output_class = ‘with-image’;
}$cat_name = get_the_category();
endwhile; endif; wp_reset_postdata();
$output .= ‘</div>’;
return $output;
}add_action(‘wp_head’, ‘change_recent_posts_to_v2’);
function change_recent_posts_to_v2() {
remove_shortcode( ‘x_recent_posts’ );
add_shortcode( ‘x_recent_posts’, ‘x_shortcode_recent_posts_v2code’ );
}October 5, 2015 at 9:30 am #611298
JackKeymasterHi there Jonathan,
Thanks for the additional information. I’ve checked your site using FTP and I see the code was placed in the parent theme within the main integrity file. This could cause issues and isn’t recommend.
I’ve moved the code into the child theme and tried it, though upon activation of that, a lot of styling is lost, for now I’ve reactivated the parent theme again because of that.
Can you let us know if you’ve placed any other custom code into the main parent theme please?
Please advise. π
Thank you!
October 5, 2015 at 11:29 am #611537
Jonathan SParticipantHi yes custom code in parent function:
function my_new_action() {
if ( is_singular(‘post’) ) : ?><?php echo do_shortcode(‘<h5>Also on Deeside.com</h5>[recent_posts type=”post” count=”3″ orientation=”horizontal”]’); ?>
<?php endif;
}add_action( ‘x_before_the_content_end’, ‘my_new_action’, 10
October 5, 2015 at 12:16 pm #611620
JadeModeratorHi Jonathan,
I have checked on your files and saw that the code for the custom recent post structure is now in the right place in the child theme. However, when I checked on the frontend of the site, it seems like you are now using a third party plugin to display the recent posts?
I was going to check further by logging in to the admin panel but I am still getting the Blocked IP message.
Could you please confirm if you have activate the child theme and if there is anything that is not working so that we could assist you further on this?
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-610057 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
