Error in wordpress function.php file - php

I am trying to add a particular shortcode to my theme, but i get an error when i paste the below code in my themes function.php. I already tried including once in the function.php but that did not work.
I think the problem is because of the <?php prefix and ?> suffix it has which is prohibited in wordpress fucntion.php. I had removed all <?php and ?> but it still generates an error.
// Add Shortcode
function acardio_big_grid_1() {
<div class="col-md-12 featt big-grid">
<div class="container-fluid no-padding">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'post', 'posts_per_page' => 5, 'paged' => $paged);
$query = new WP_Query($args);
if( $query->have_posts() ) :
while( $query->have_posts() ) : $query->the_post(); ?>
<?php $count++; ?>
<?php if ($count == 1) : ?>
<div class="big-pane col-xs-6">
<div class="the-big-pane image">
<div class="img-responsive"> <?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail('big-grid-one-image'); ?>
<?php else : ?>
<img src="
<?php if (function_exists('get_option_tree') ) : if (get_option_tree('defualt_fatured_uploader')) : ?>
<?php get_option_tree( 'defualt_fatured_uploader', '', 'true' ); ?>
<?php else : ?>
<?php echo get_template_directory_uri (); ?>/img/nothumb-featured.png
<?php endif; endif; ?>
" />
<?php endif; ?></div>
</div>
<div class="big-pane overlay">
<div class="the-big-pane-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1><?php echo wp_trim_words( get_the_title(), 15 ); ?></h1>
<span class="the-content-post-data"><span class="the-auth-post-image-content" style="padding-top: 0px !important;"> <?php echo get_avatar( get_the_author_meta( 'user_email' ), 100 ); ?> </span> By <?php the_author_posts_link(); ?> <span class="the-content-post-date"> <i class="fa fa-clock-o the-content "></i><?php the_time('jS M, Y') ?></span> </span>
</div>
</div>
</div>
<?php elseif ($count == 2) : ?>
<div class="small-pane-holder1 col-xs-6">
<div class="small-pane col-xs-6 one">
<div class="the-small-pane-image">
<?php the_post_thumbnail();?>
</div>
<div class="small-pane-overlay">
<div class="small-pan-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1 class="small-pane-title"><?php echo wp_trim_words( get_the_title(), 10 ); ?></h1>
</div>
</div>
</div>
<?php elseif ($count == 3) : ?>
<div class="small-pane col-xs-6 two">
<div class="the-small-pane-image">
<?php the_post_thumbnail();?>
</div>
<div class="small-pane-overlay">
<div class="small-pan-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1 class="small-pane-title"><?php echo wp_trim_words( get_the_title(), 10 ); ?></h1>
</div>
</div>
</div>
<?php elseif ($count == 4) : ?>
<div class="small-pane col-xs-6 three">
<div class="the-small-pane-image">
<?php the_post_thumbnail();?>
</div>
<div class="small-pane-overlay">
<div class="small-pan-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1 class="small-pane-title"><?php echo wp_trim_words( get_the_title(), 10 ); ?></h1>
</div>
</div>
</div>
<?php elseif ($count == 5) : ?>
<div class="small-pane col-xs-6 four">
<div class="the-small-pane-image">
<?php the_post_thumbnail();?>
</div>
<div class="small-pane-overlay">
<div class="small-pan-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1 class="small-pane-title"><?php echo wp_trim_words( get_the_title(), 10 ); ?></h1>
</div>
</div>
</div>
</div>
<?php else : ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
}
add_shortcode( 'acardio-big-grid-1', 'acardio_big_grid_1' );

Right near the top you have a syntax error - an issue with your PHP tags. You need a closing php tag before the HTML, and an opening PHP tag after. The top of the code should read like so:
function acardio_big_grid_1() {
?>
<div class="col-md-12 featt big-grid">
<div class="container-fluid no-padding">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'post', 'posts_per_page' => 5, 'paged' => $paged);
You have a similar problem near the end of the code sample, but this time missing a opening php tag:
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php
}
add_shortcode( 'acardio-big-grid-1', 'acardio_big_grid_1' );
No guarantees that that is all your issues, but that would be one key issue in the code sample you provided.

Related

WordPress- Calling a function - not working when using custom tag

The following function works by adding it to >the_content() , however, I want to display it at a custom location in my html markup via a custom tag, when I tried this I got a PHP error, I'm sure this is something very simple but I for the life of me cannot see the issue.
// code from crunchify
function supersun_social_sharing_buttons($content) {
global $post;
if(is_singular() || is_home()){
// Get current page URL
$supersunURL = urlencode(get_permalink());
// Get current page title
$supersunTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$supersunThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$supersunTitle.'&url='.$supersunURL.'&via=Crunchify';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$supersunURL;
$googleURL = 'https://plus.google.com/share?url='.$supersunURL;
$whatsappURL = 'whatsapp://send?text='.$supersunTitle . ' ' . $supersunURL;
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$supersunURL.'&media='.$supersunThumbnail[0].'&description='.$supersunTitle;
// Add sharing button at the end of page/page content
$variable .= '<div class="supersun-social">';
$variable .= '<a class="supersun-social-link supersun-twitter" href="'. $twitterURL .'" target="_blank" title="Share on Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a>';
$variable .= '<a class="supersun-social-link supersun-facebook" href="'.$facebookURL.'" target="_blank" title="Share on Facebook"><i class="fa fa-facebook" aria-hidden="true"></i></a>';
$variable .= '<a class="supersun-social-link supersun-whatsapp" href="'.$whatsappURL.'" target="_blank" title="Share on Whatsapp"><i class="fa fa-whatsapp" aria-hidden="true"></i></a>';
$variable .= '<a class="supersun-social-link supersun-googleplus" href="'.$googleURL.'" target="_blank" title="Share on Google+"><i class="fa fa-google-plus" aria-hidden="true"></i></a>';
$variable .= '<a class="supersun-social-link supersun-pinterest" href="'.$pinterestURL.'" target="_blank" title="Share on Pinterest"><i class="fa fa-pinterest" aria-hidden="true"></i></a>';
$variable .= '</div>';
return $variable.$content;
}else{
// if not a post/page then don't include sharing button
return $variable.$content;
}
};
add_filter( 'the_content', 'supersun_social_sharing_buttons');
THIS ERROR MESSAGE APPEARS WHEN I ADD
<?php supersun_social_sharing_buttons(); ?>
TO MY THEME.
Thank you so much for your time. Sorry the site is not currently live, I think this should be an easy fix for someone with an experienced eye.
<?php
/**
* The template for displaying all single posts and attachments
*
* #package FoundationPress
* #since FoundationPress 1.0.0
*/
get_header(); ?>
<div class="post-container">
<div class="blog-single-header-background" id="blog-single-header-background">
</div>
<?php supersun_social_sharing_buttons($content); ?>
<div class="container post-content-container">
<div class="columns medium-10 medium-centered">
<div itemscope itemtype="http://schema.org/Article" class="single-blog-post" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article <?php post_class('main-content') ?> id="post-<?php the_ID(); ?>">
<header class="post-header">
<h1 itemprop="name" class="entry-title"><?php the_title(); ?></h1>
<div class="post-author-details">
<a href="<?php get_the_author_link(); ?>" class="post-author-avatar image-circle float-left">
<?php echo get_avatar( get_the_author_meta( 'ID' ), 64 ); ?>
</a>
<div class="post-author-meta media-body margin-left">
<h4 class="author-post-byline">
<span> By </span>
<span itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name" class="author-post-link"><?php the_author_posts_link(); ?></span>
</span>
<span class="post-date">
on <?php echo the_time("M j, Y");?>
</span>
</h4>
<span class="post-meta-wrap">
<span class="post-category">
<span class="pre-cat"> In
</span>
<?php $categories = get_the_category();
if ( ! empty( $categories ) ) {
echo '' . esc_html( $categories[0]->name ) . '';
}?>
</span>
</span>
</div>
</div>
<div class="clear"></div>
</header>
<div class="post-content">
<span itemprop="articleBody">
<div class="post-image">
<?php echo the_post_thumbnail( 'large' ); ?>
</div>
<?php the_content(); ?>
</span>
</div>
<footer>
<div class="post-author-about-section">
<?php
global $post;
// Detect if it is a single post with a post author
if ( is_single() && isset( $post->post_author ) ) {
// Get author's display name
$display_name = get_the_author_meta( 'display_name', $post->post_author );
// If display name is not available then use nickname as display name
if ( empty( $display_name ) )
$display_name = get_the_author_meta( 'nickname', $post->post_author );
// Get author's biographical information or description
$user_description = get_the_author_meta( 'user_description', $post->post_author );
// Get author's website URL
$user_website = get_the_author_meta('url', $post->post_author);
// Get link to the author archive page
$user_posts = get_author_posts_url( get_the_author_meta( 'ID' , $post->post_author));
if ( ! empty( $user_description ) )
// Author avatar and bio
$author_details = '' . get_avatar( get_the_author_meta('user_email') , 90 ) . '';
$author_details .= '<div class="media-body margin-left">';
if ( ! empty( $display_name ) )
// $author_details = '<p class="author-about-name">About ' . $display_name . '</p>';
$author_details .= '<h4 class="author-post-byline author-about-name">';
$author_details .= '<span class="pre-author-header"> About </span>';
$author_details .= '<span itemprop="author" itemscope itemtype="http://schema.org/Person">';
$author_details .= '<span itemprop="name" class="author-post-link">' . $display_name . '</span>';
$author_details .= '</span>';
$author_details .= '</h4>';
$author_details .= '<p class="author-about-details">' . nl2br( $user_description ). '</p>';
// $author_details .= '<p class="author-about-links">View all posts by ' . $display_name . '';
// Check if author has a website in their profile
if ( ! empty( $user_website ) ) {
// Display author website link
$author_details .= ' | Website</p>';
} else {
// if there is no author website then just close the paragraph
$author_details .= '</p>';
}
$author_details .= '</div">';
// Pass all this info to post content
$content = $content . $author_details;
}
echo $content;
?>
</div>
</footer>
</article>
</div>
<?php endwhile;?>
<div class="related-posts">
<?php $orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>2, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo '<div id="relatedposts"><h3>Related Posts</h3>';
while( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<div class="columns medium-6 large-6 collapse margin-bottom">
<a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>">
<div class="related-post-item content-card">
<div class="related-thumb">
<?php the_post_thumbnail(); ?>
</div>
<div class="related-content">
<div class="related-category-title">
<?php $categories = get_the_category();
if ( ! empty( $categories ) ) {
echo esc_html( $categories[0]->name );
}?>
</div>
<h2>
<?php the_title(); ?>
</h2>
</div>
</div>
</a>
</div>
<?php }
echo '</div>';
}
}
$post = $orig_post;
wp_reset_query(); ?>
</div>
<div class="clear"> </div>
<!-- <h3> Comments </h3> -->
<div class="comments">
<?php do_action( 'foundationpress_post_before_comments' ); ?>
<?php comments_template(); ?>
<?php do_action( 'foundationpress_post_after_comments' ); ?>
</div>
</div>
</div>
</div>
<?php get_footer();
You need pass a parameter when you call your function directly, not in add_filter. Like this <?php supersun_social_sharing_buttons($parameter); ?>

Show only one Category in wordpress

I have a post which is assigned to different categories.
I created a loop
<div class="col-sm-12 ">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="row marginbottomclass">
<div class="col-sm-4 thumbnailimage">
<?php the_post_thumbnail(); ?>
</div>
<div class="col-sm-8">
<h1><?php the_title( ); ?></h1>
<small><?php the_category("," );?></small>
<p><?php the_excerpt(); ?></p>
</div>
</section>
<div class="clearfix"></div>
<?php endwhile; else : ?>
<?php endif; ?>
</div>
But this loop getting all the category of post. While i only want to show one category. I don't want to show all the category that this post assigned to.
I tried different
<?php $parentscategory ="";
foreach((get_the_category()) as $category) {
if ($category->category_parent == 0) {
$parentscategory .= ' <a href="' . get_category_link($category->cat_ID) .
'" title="' . $category->name . '">' . $category->name . '</a>, ';
}
}
echo substr($parentscategory,0,-2); ?>
I think you might want to to use wp_get_post_terms, this will grab all the categories attached to the post and put them in an array.
<?php
$term_list = wp_get_post_terms($post->ID, 'my_taxonomy', array("fields" => "all"));
echo $term_list[0]->description ;
?>

Editing Wordpress code to bring post type

Is there a way to edit the following so that rather than bringing in the most recent posts, it bring in posts from a specific category?
if( !function_exists('zolo_recent_posts') ) { function zolo_recent_posts($atts, $content = null) { ob_start(); extract(shortcode_atts(array( "num" => '4', 'columnsizepost' => '', 'data_animation'=>'fadeInDown', 'data_delay'=>'0' ), $atts)); global $post;
query_posts( 'post_type=post&posts_per_page='.$num.'&paged='. #$paged ); ?>
<div class="zolo-recent-post <?php echo $columnsizepost;?>">
<?php $i=1 ; while (have_posts()) : the_post(); if (has_post_thumbnail( $post->ID ) ): ?>
<?php //$image=w p_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'recent_posts_thumb' ); ?>
<?php endif; if( $i % 4==0 ) $class='last' ; else $class='' ; ?>
<div class="blog-box <?php echo $class;?> animated hiding" data-animation="<?php echo $data_animation;?>" data-delay="<?php echo $data_delay; ?>">
<div class="blog-img"><a href="<?php the_permalink(); ?>">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('recent_posts_thumb');
}
else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumb-img.jpg" />';
}
?>
</a>
</div>
<div class="blog-text-area">
<h3><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h3>
<div class="alltag-row"> <span class="date"><i class="fa fa-calendar"></i>
<?php the_time('F jS, Y') ?>
</span> <span class="add-comment"><a href="<?php the_permalink(); ?>#hello">
<?php comments_number( '0 <i class="fa fa-comment-o"></i>', '1 <i class="fa fa-comment"></i>', '% <i class="fa fa-comments"></i>' ); ?>
</a></span>
</div>
<?php the_excerpt() ;?>
</div>
</div>
</span>
<?php $i++; endwhile; ?>
</div>
<?php wp_reset_query(); $demolp_output=o b_get_clean(); return $demolp_output; } add_shortcode( "zolo_recent_post", "zolo_recent_posts"); }
<?php query_posts('category_name=CATEGORYNAME&showposts=5');
while (have_posts()) : the_post();
// do whatever you want
?>
<b><?php the_title(); ?>
<?php
endwhile;
?>
Using this way you can fetch posts of a specific category in WordPress.

Comment form won't show on my wp blog posts

I have a wordpress site with a customized theme, and I have included comments into my single.php file, which looks like this:
<?php get_header();?>
<div id="content">
<div class="right">
<div class="article">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<small><?php the_time('F jS, Y'); ?></small>
<?php the_content();?>
<br /><br />
<hr />
<br /><br />
<?php comments_template(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div></div>
<?php get_sidebar(); ?>
</div>
<?php get_footer();?>
Still, the comment form won't show up underneath my blog posts. I have enabled comments in the back end.
I don't Know your template code it is correct or no but your code contain error because you used error position to put comment template code
put the comment template code outside the loop and within the container class
like this
<?php get_header();?>
<div id="content">
<div class="right">
<div class="article">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<small><?php the_time('F jS, Y'); ?></small>
<?php the_content();?>
<br /><br />
<hr />
<br /><br />
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
<?php comments_template(); ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer();?>
My code
this code within comments.php file
<?php
/* Prevent the direct loading of comments.php */
if (!empty($_SERVER['SCRIPT-FILENAME']) && basename($_SERVER['SCRIPT- FILENAME']) == 'comments.php') {
die(__('You can not access this file directly.', 'Yallanpe-Theme'));
}
/* If the post is password protected then display text and return */
if(post_password_required()) : ?>
<h5>
<?php
_e('This Post is password protected, Enter the password to view the comments', 'Yallanpe-Theme');
return;
?>
</h5>
<?php endif;
/* If we have comments to display, we display them */
if(have_comments()) : ?>
<div id="comments-container">
<?php wp_list_comments( array('walker' => new YPE_walker_comment)); ?>
<script>
$(document).ready(function() {
$("#comments-container ul#comment-list li.depth-1 .comment-avatar img").addClass("img-thumbnail");
$("#comments-container ul#comment-list li.depth-1 ul.children .comment-avatar img").addClass("img-circle");
});
</script>
</div><!-- /#comments-container -->
<?php if (get_comment_pages_count() > 1 && get_option('page_comments')) : ?>
<div class="comments-nav-section">
<h5 class="text-left"><?php previous_comments_link(__('← Older Comments', 'Yallanpe-Theme')); ?></h5>
<h5 class="text-right"><?php next_comments_link(__('Newer Comments →', 'Yallanpe-Theme')); ?></h5>
</div><!-- end comment-nav-section -->
<?php endif; ?>
<?php
/* If we don't have comments and the comments are closed, display a text */
elseif (!comments_open() && !is_page() && post_type_supports(get_post_type(), 'comments')) : ?>
<h5> <?php _e('Comments are Closed.', 'Yallanpe-Theme'); ?> </h5>
<?php endif;
/* Display the comment form */
comment_form();
?>
and this code below within functions.php (I used Bootstarp framework for comment form)
<?php
class YPE_walker_comment extends Walker_Comment {
var $tree_type = 'comment';
var $db_fields = array( 'parent' => 'comment_parent', 'id' => 'comment_ID' );
function __construct() { ?>
<h4>Comments</h4>
<ul id="comment-list">
<?php }
function start_lvl( &$output, $depth = 0, $args = array() ) {
$GLOBALS['comment_depth'] = $depth + 1; ?>
<ul class="children">
<?php }
function end_lvl( &$output, $depth = 0, $args = array()) {
$GLOBALS['comment_depth'] = $depth + 1; ?>
</ul>
<?php }
function start_el( &$output, $comment, $depth, $args, $id = 0 ) {
$depth++;
$GLOBALS['comment_depth'] = $depth;
$GLOBALS['comment'] = $comment;
$parent_class = (empty($args['has_children']) ? '' : 'parent'); ?>
<li <?php comment_class($parent_class); ?> id="comment-<?php comment_ID() ?>">
<div class="row">
<div class="col-sm-2">
<div class="comment-avatar">
<?php
$avatar_size = 80;
if ($comment->comment_parent != 0) { $avatar_size = 80; }
echo get_avatar($comment, $avatar_size);
?>
</div>
</div>
<div class="col-sm-10">
<div class="comment-header">
<?php
$reply_args = array(
'add_below' => $add_below,
'depth' => $depth,
'max_depth' => $args['max_depth']
);
?>
<ul id='author-time' class="list-inline">
<li><?php echo get_comment_author_link(); ?> </li>
<li class="pull-right text-muted"><?php comment_date(); ?> at <?php comment_time(); ?></li>
</ul>
<em>
<ul id="reply-delete" class="list-inline">
<li><?php comment_reply_link(array_merge($args, $reply_args)); ?></li>
<?php if (current_user_can('edit_post')) { $id = get_comment_ID(); ?>
<li><?php echo ' Edit'; ?></li>
<li><?php echo ' Delete'; ?></li>
<li><?php echo ' Spam'; ?></li>
<?php } ?>
</ul>
</em>
</div>
<div class="comment-content">
<?php
if( !$comment->comment_approved ) : ?>
<em class="text-muted">
<?php _e('Your comment is awaiting moderation.', 'Yallanpe Theme'); ?>
</em>
<?php else: comment_text(); ?>
<?php endif; ?>
</div>
</div>
</div>
<?php }
function end_el( &$output, $comment, $depth = 0, $args = array() ) { ?>
</li>
<?php }
function __destruct() { ?>
</ul>
<?php }
}
function YPE_custom_comment_form($defaults) {
$comment_notes_after = '';
$defaults ['comment_notice_before'] = '';
$defaults ['comment_notes_after'] = $comment_notes_after;
$defaults ['id_form'] = 'commentform';
$defaults ['comment_field'] = '<p class="form-group">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"> <span class="glyphicon glyphicon-comment"></span></span>
<textarea class="form- control" name="comment" id="comment" cols="30" rows="10">
</textarea>
</div>
</div>
</p>';
$defaults ['label_submit'] = 'Submit Comment';
$defaults ['title_reply'] = '<section id="comment-form"><h4>Add Comment</h4></section>';
return $defaults;
}
add_filter ('comment_form_defaults', 'YPE_custom_comment_form');
function YPE_custom_comment_fields() {
$commenter = wp_get_current_commenter();
$req = get_option('require_name_email');
$aria_req = ($req ? " aria-required='true'" : '');
$fields = array(
'author' => '<div class="form-group">' .
'<p>'.
'<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>' .
'<input type="text" class="form-control" id="author" name="author" value="'. esc_attr($commenter['comment_author']) .'" '. $aria_req .' placeholder="Enter Your Name" />'.
'</div>'.
'</div>'.
'</p>'.
'</div>',
'email' => '<div class="form-group">' .
'<p>'.
'<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>' .
'<input type="text" class="form-control" id="email" name="email" value="'. esc_attr($commenter['comment_author_email']) .'" '. $aria_req .' placeholder="Enter Your Email" />'.
'</div>'.
'</div>'.
'</p>'.
'</div>',
'url' => '<div class="form-group">' .
'<p>'.
'<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-globe"></span></span>' .
'<input type="text" class="form-control" id="url" name="url" value="'.esc_attr($commenter['comment_author_url']) .'" placeholder="Enter Your Website URL" />'.
'</div>'.
'</div>'.
'</p>'.
'</div>',
);
return $fields;
}
add_filter ('comment_form_default_fields', 'YPE_custom_comment_fields');
?>

Pull all posts with certain tag WordPress

I have this code:
<div class="col-md-4 col-sm-4 col-xs-12 mob">
<?php
$args = array('tag_slug__and' => array('testtag'));
$loop = new WP_Query( $args );
while ($loop->have_posts() ) : $loop->the_post();
?>
<a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
<?php
if(has_post_thumbnail()) {
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
echo '<img src="' . $image_src[0] . '" width="100%" />';
}
?>
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</a>
Which gets a post which has the tag 'testtag'.
Instead of copying this code, and using 'testtag1', 'testtag2'
How can I just grab ALL the posts which have the tag 'testtag' and just keep adding them into 4 columns?
Any links/help
Nevermind, simple fix!!
<div class="row" style="margin-top:20px;">
<?php
$args = array('tag_slug__and' => array('testtag'));
$loop = new WP_Query( $args );
while ($loop->have_posts() ) : $loop->the_post();
?>
<div class="col-md-4 col-sm-4 col-xs-12 mob">
<a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
<?php
if(has_post_thumbnail()) {
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
echo '<img src="' . $image_src[0] . '" width="100%" />';
}
?>
<h4><?php the_title(); ?></h4>
<?php $trimexcerpt = get_the_excerpt();
$shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 10, $more = '… <br/> Read More ...' );
echo '<a style="color:#333; text-decoration:none;" href="' . get_permalink() . '"><p>' . $shortexcerpt . '</p></a>';
?>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</a>
</div>

Categories