I've inherited a legacy CMS.
The articles at the top are parsing the correct url
https://www.tptg.co.uk/news
But when you click more articles at the bottom of the page ajax is pulling through the incorrect href ( /blog/id/post-name instead of the correct and working /
<div class="col-lg-12 col-xs-12">
<button id="load-more" class="btn btn-primary center-block more-news-btn">
more articles
</button>
</div>
</div>
<script>
$(document).ready(function() {
$("#load-more").click(function() {
var ids = new Array();
$("article").each(function(i, o) {
var id = $(o).data("blog-id");
ids.push(id);
});
ids = JSON.stringify(ids);
var searchTerm = $("input[name='searchTerm']").val();
$.ajax({
url: '<?="https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"?>',
context: document.body,
crossDomain: true,
data: {
excludeIDs: ids,
blockID: "blog_listing",
searchTerm: searchTerm
}
}).done(function(data) {
// if the response ends in last tag then remove the load more button
if (data.substr(data.length - 8) == '<last />')
target.hide();
$('#article-col').append(data);
});
})
})
</script>
Earlier in the template file (for the blog listing page) there is the array of the working posts which looks like this
<div id="blog-article-wrapper">
<?php if( count( $articles ) > 0 ): ?>
<div class="col-xs-12 col-lg-12 blog-columns" id="article-col">
<?php foreach( $articles as $i => $article ): ?>
<?php require( dirname(__FILE__)."/puredata_article.php"); //this is the actual article template thats shared between normal page loads and ajax requests ?>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="text-xs-center p-x-2 p-y-2">
No news to display
</p>
<?php endif; ?>
<div class="col-lg-12 col-xs-12">
<button id="load-more" class="btn btn-primary center-block more-news-btn">
more articles
</button>
</div>
</div>
Then the file mentioned there is
<?php
use Fluid\Ignite4\Config;
use \IgniteApp\viewHelpers\PageViewHelper;
?>
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-xs-12">
<article class="m-b-1 blog-post" data-blog-id="<?= $article->getPrimaryKeyValue() ?>">
<?php if( $article->hasImage() ): ?>
<a href="<?= PageViewHelper::url($blogPage , $article , false ) ?>">
<?= $article->getImage()->setClasses("img-fluid blog-image") ?>
</a>
<?php endif; ?>
<h1 class="p-x-3 p-t-2 p-b-1" style="line-height: 0.8em !important;">
<a href="<?= PageViewHelper::url($blogPage , $article , false ) ?>">
<?= $article->title ?>
</a>
</h1>
<p class="teaser p-x-3 p-b-1">
<?= $article->teasercontent ?>
</p>
<hr>
<div class="wide-article-footer clearfix p-x-3 p-b-1">
<?php if( $article->getPublisher()->hasImage() ):?>
<div class="publisher-image pull-left">
<a href="<?= PageViewHelper::url( $blogListingPage , false , false , array( " author " => $article->getPublisher()->getPrimaryKeyValue() )) ?>">
<?= $article->getPublisher()->getImage()->setClasses("img-fluid") ?>
</a>
</div>
<?php endif; ?>
<div class="pull-left p-l-2 p-t-2 p-b-2">
<p>
<a style="color: #1A1A1A; font-weight: 500;" href="<?= PageViewHelper::url( $blogListingPage , false , false , array( " author " => $article->getPublisher()->getPrimaryKeyValue() )) ?>">Posted by
<?= $article->getPublisher()->user ?>
</a></br>
<?= $article->getCreated()->format("F j, Y") ?>
</p>
</div>
<div class="pull-right share-wrapper clearfix">
<?php /*
<div class="share-text visible">
<p>
<a class="share-text-link">
<i class="fa fa-share-alt" aria-hidden="true"></i> SHARE
</a>
</p>
</div> */ ?>
</div>
</div>
<!-- end wide article footer -->
</article>
</div>
Please help I'm really stuck with this one I've project searched for the /blog/ and /view-article/ permalink and in the database only the id and post names are specified.
Related
I want to use pjax with pagination in yii2.
When user clicks on next page, i want to reload only one div with dynamic contents.
I have put pjax::begin() and pjax::end() before and end of my div.
This is my controller code :
public function actionRestaurantDetails(){
$this->layout = "detail";
if(isset($_REQUEST['rid']) && !empty($_REQUEST['rid'])){
$rid = $_REQUEST['rid'];
$snRestaurantsDetail = Restaurants::find()->where(['id'=>$_REQUEST['rid']])->one();
$snRestaurantMenuCategoryArr = MenuCategories::find()->where(["status"=>"1"])->all();
$snRestaurantMenusArr = RestaurantMenu::find()->where(['restaurant_id'=>$_REQUEST['rid'],'status'=>"1"])->all();
$query = RestaurantsGallery::find()->where(['restaurant_id'=>$_REQUEST['rid'],'status'=>"1"]);
$snRestaurantgallerysArr = RestaurantsGallery::find()->where(['restaurant_id'=>$_REQUEST['rid'],'status'=>"1"])->all();
$pagination = new Pagination(['totalCount' => $query->count(), 'pageSize'=>3]);
$models = $query->offset($pagination->offset)
->limit($pagination->limit)
->all();
$snRestaurantLayoutsArr = $snRestaurantsDetail->getRestaurantLayouts();
$snRestaurantTablesArr = $snRestaurantsDetail->getRestaurantTables();
$snRestaurantWorkingHoursArr = $snRestaurantsDetail->getRestaurantWorkingHours();
$snRestaurantMealTimesArr = $snRestaurantsDetail->getRestaurentMealTimes();
//p($snRestaurantsDetail);
}
return $this->render('restaurant_detail', [
'snRestaurantsDetail' => $snRestaurantsDetail,
'snRestaurantMenuCategoryArr' => $snRestaurantMenuCategoryArr,
'snRestaurantMenusArr' => $snRestaurantMenusArr,
'snRestaurantMealTimesArr' => $snRestaurantMealTimesArr,
'snRestaurantWorkingHoursArr' => $snRestaurantWorkingHoursArr,
'snRestaurantgallerysArr' => $snRestaurantgallerysArr,
'models' => $models,
'pagination' => $pagination,
]);
}
And this is my view :
<?php
use common\models\RestaurantMenu;
use yii\widgets\Pjax;
?>
<div class="container">
<div class="row align-items-center site-vh-100">
<div class="col-md-12">
<?php
$url = Yii::getAlias('#web')."/img/chiefs-rs-text.png";
?>
<!-- <a class="brand" href="#"><img src="<?php echo $url; ?>" width="35%" height="35%"></a> -->
<h1 class="site-heading site-animate mb-3"><?= !empty($snRestaurantsDetail) ? $snRestaurantsDetail->name : "-" ?></h1>
<h2 class="h5 site-subheading mb-5 site-animate">Please book our restaurant now</h2>
<?php if(Yii::$app->user->isGuest){ ?>
<p>For Booking Restaurant :Register Now</p>
<?php }else{ ?>
<p>Book Now</p>
<?php } ?>
</div>
</div>
</section>
<section class="site-section section_details" id="section-about">
<div class="container">
<div class="row">
<div class="col-md-5 site-animate mb-5">
<h4 class="site-sub-title">Our Story</h4>
<h2 class="site-primary-title display-4">Welcome</h2>
<p><?= !empty($snRestaurantsDetail->description) ? $snRestaurantsDetail->description : "No contents found." ?></p>
<!-- <p class="mb-4">A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.</p> -->
</div>
<div class="col-md-1"></div>
<div class="col-md-6 site-animate img" data-animate-effect="fadeInRight">
<img src="<?= ($snRestaurantsDetail->photo) ? Yii::getAlias('#web')."../../../uploads/".$snRestaurantsDetail->photo : "No image uploaded"?>" alt="chiefsRS" class="img-fluid" style="width:100%;height: 60vh">
</div>
</div>
</div>
</section>
<section class="site-section section_details" id="section-menu">
<div class="container">
<div class="row">
<div class="col-md-12 text-center mb-5 site-animate">
<h2 class="display-4">Delicious Menu</h2>
<div class="row justify-content-center">
<div class="col-md-7">
<p class="lead">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
</div>
</div>
</div>
<div class="col-md-12 text-center">
<ul class="nav site-tab-nav nav-pills mb-5" id="pills-tab" role="tablist">
<?php
if(!empty($snRestaurantMenuCategoryArr)){
foreach ($snRestaurantMenuCategoryArr as $key => $category) { ?>
<li class="nav-item site-animate">
<a class="nav-link <?= (strtolower($category->name) == "breakfast") ? 'active' : '' ?>" id="pills-<?= strtolower($category->name)?>-tab" data-toggle="pill" href="#pills-<?= strtolower($category->name)?>" role="tab" aria-controls="pills-<?= strtolower($category->name);?>" aria-selected="true"><?= $category->name;?></a>
</li>
<?php }
}
?>
</ul>
<div class="tab-content text-left">
<?php
if(!empty($snRestaurantMenuCategoryArr)){
foreach ($snRestaurantMenuCategoryArr as $key => $category) { ?>
<div class="tab-pane fade <?= (strtolower($category->name) == "breakfast") ? 'show active' : '' ?>" id="pills-<?= strtolower($category->name)?>" role="tabpanel" aria-labelledby="pills-<?= strtolower($category->name)?>-tab">
<div class="row">
<?php
$breakfastMenu = RestaurantMenu::find()->where(['restaurant_id'=>$_REQUEST['rid'],'menu_category_id'=>$category->id,'status'=>"1"])->all();
// p($breakfastMenu);
if(!empty($breakfastMenu)){
foreach ($breakfastMenu as $key_menu => $menu) { ?>
<div class="col-md-6 site-animate">
<div class="media menu-item">
<img class="mr-3" src="<?php echo Yii::getAlias('#web')."/../../uploads/".$menu->photo; ?>" class="img-fluid" alt="chiefsRS">
<div class="media-body">
<h5 class="mt-0"><?= !empty($menu->name) ? $menu->name : ""?></h5>
<p><?= !empty($menu->description) ? $menu->description : ""?></p>
<h6 class="text-primary menu-price"><?= !empty($menu->price) ? "$".$menu->price : ""?></h6>
</div>
</div>
</div>
<?php
}
}
?>
</div>
</div>
<?php }
}
?>
</div>
</div>
</div>
</div>
</section>
<!-- END section -->
<?php
Pjax::begin(['id' => 'gallery_r','timeout'=>100000]); ?>
<section class="site-section section_details" id="section-gallery">
<div class="container">
<div class="row site-custom-gutters">
<div class="col-md-12 text-center mb-5 site-animate">
<h2 class="display-4">Gallery</h2>
<div class="row justify-content-center">
<div class="col-md-7">
<p class="lead">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
</div>
</div>
</div>
<div id="categories"></div>
<?php if (!empty($models)) {
foreach ($models as $key => $image) {
?>
<div class="col-md-4 site-animate">
<a href="<?php echo Yii::getAlias('#web') . "../../../uploads/" . $image->image_name; ?>" class="site-thumbnail image-popup">
<img src="<?php echo Yii::getAlias('#web') . "../../../uploads/" . $image->image_name; ?>" alt="chiefsRS" class="img-fluid" style="width:80%;height:50vh;" title="<?= $image->image_title; ?>">
</a>
</div>
<?php
}
}
?>
</div>
</div>
</section>
<?php echo \yii\widgets\LinkPager::widget([
'pagination' => $pagination,
]);
Pjax::end();?>
<!-- END section -->
<section class="site-section section_details bg-light" id="section-contact">
<div class="container">
<div class="row">
<div class="col-md-12 text-center mb-5 site-animate">
<h2 class="display-4">Get In Touch</h2>
<div class="row justify-content-center">
<div class="col-md-7">
<p class="lead">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
<p class="text-black">
<?php
if(!empty($snRestaurantsDetail)){ ?>
Address: <br><?= $snRestaurantsDetail->address; ?><br>
Phone: <br><?= $snRestaurantsDetail->contact_no; ?><br> <br>
Email: <br> <?= $snRestaurantsDetail->email; ?>
<?php } ?>
</p>
</div>
</div>
</div>
</div>
</div>
</section>
<div id="map"></div>
<?php// p($snRestaurantsDetail); ?>
<input type="hidden" name="lat" id="lat" value="<?= $snRestaurantsDetail->lattitude; ?>">
<input type="hidden" name="long" id="long" value="<?= $snRestaurantsDetail->longitude; ?>">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBvpANF446OIBFdLaqozAf-lheEZ__oVVg&libraries=geometry"></script>
<script type="text/javascript">
$.pjax.reload({container: '#gallery_r'});
</script>
<?php Pjax::begin(['id'=>'gallery_r']);
if(!empty($models)){
foreach ($models as $key => $image) { ?>
<div class="col-md-4 site-animate">
<a href="<?php echo Yii::getAlias('#web')."../../../uploads/".$image->image_name;?>" class="site-thumbnail image-popup">
<img src="<?php echo Yii::getAlias('#web')."../../../uploads/".$image->image_name;?>" alt="chiefsRS" class="img-fluid" style="width:80%;height:50vh;" title="<?= $image->image_title;?>">
</a>
</div>
<?php }
Pjax::end();
echo \yii\widgets\LinkPager::widget([
'pagination' => $pagination,
]);
}?>
And this is my js code :
$.pjax.reload({container: '#gallery_r'});
And I call this jquery to add class after pjax load to display contents :
jQuery(document).on("pjax:success", "#gallery_r", function(event){
contentWayPoint();
}
);
var contentWayPoint = function() {
var i = 0;
$('.site-animate').waypoint( function( direction ) {
if( direction === 'down' && !$(this.element).hasClass('site-animated') ) {
i++;
$(this.element).addClass('item-animate');
setTimeout(function(){
$('body .site-animate.item-animate').each(function(k){
var el = $(this);
setTimeout( function () {
var effect = el.data('animate-effect');
if ( effect === 'fadeIn') {
el.addClass('fadeIn site-animated');
} else if ( effect === 'fadeInLeft') {
el.addClass('fadeInLeft site-animated');
} else if ( effect === 'fadeInRight') {
el.addClass('fadeInRight site-animated');
} else {
el.addClass('fadeInUp site-animated');
}
el.removeClass('item-animate');
}, k * 50, 'easeInOutExpo' );
});
}, 100);
}
} , { offset: '95%' } );
};
And on one button click I am calling this URL like this :
<p class="mb-0">Read More</p>
This URL calls as ajax call and loads only pjax container div, When i reload this page manually then it will display the whole page.I don't know why this happened ?
You should move the LinkPager inside the Pjax scope.
<?php
Pjax::begin(['id' => 'gallery_r']);
if (!empty($models)) {
foreach ($models as $key => $image) {
?>
<div class="col-md-4 site-animate">
<a href="<?php echo Yii::getAlias('#web') . "../../../uploads/" . $image->image_name; ?>" class="site-thumbnail image-popup">
<img src="<?php echo Yii::getAlias('#web') . "../../../uploads/" . $image->image_name; ?>" alt="chiefsRS" class="img-fluid" style="width:80%;height:50vh;" title="<?= $image->image_title; ?>">
</a>
</div>
<?php
}
echo \yii\widgets\LinkPager::widget([
'pagination' => $pagination,
]);
Pjax::end();
}
?>
I am trying to create a Slick JS with ACF repeater, but it doesn't work.
The following code just shows image after image.
Is there something I have forgotten?
By the way, I have already registered the CSS and JavaSscript's on functions.php.
<section>
<div id="slick-hero">
<a id="slick-hero-left" class="slick-hero__arrow-container slick-hero__arrow-container--prev">
<div class="slick-hero__icon-container">
<div class="slick-hero__icon">
<i class="fas fa-angle-left"></i>
</div>
</div>
</a>
<a id="slick-hero-right" class="slick-hero__arrow-container slick-hero__arrow-container--next">
<div class="slick-hero__icon-container">
<div class="slick-hero__icon">
<i class="fas fa-angle-right"></i>
</div>
</div>
</a>
<div class="slick-hero__slider">
<?php if ( have_rows( 'slider_2019_home' ) ) : ?>
<?php while ( have_rows( 'slider_2019_home' ) ) : the_row(); ?>
<div class="slick-hero__slide" style="background-image:url(<?php the_sub_field('slider_home_2019_image'); ?>)">
<div class="container slick-hero__slide__container">
<div class="row">
<div class="col-12">
<div class="slick-hero__slide__content">
<a class="slick-hero__slide__link" href="<?php the_sub_field('slider_home_2019_link'); ?>">
<h4 class="slick-hero__slide__heading">
<?php the_sub_field('slider_home_2019_heading'); ?>
</h4>
<h2 class="slick-hero__slide__title">
<?php the_sub_field('slider_home_2019_sub_title'); ?>
</h2>
<hr class="hero-slider__divider">
<p class="slick-hero__slide__body">
<?php the_sub_field('slider_home_2019_body'); ?>
</p>
<p class="slick-hero__slide__cta-text">
<?php the_sub_field('slider_home_2019_cta_text'); ?>
</p>
</a>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<?php endif; ?>
</div> <?php // end slick-hero__slider ?>
</div> <?php // end slick-hero ?>
</section>
Are you running
$(document).ready(function(){
$(".slick-hero__slider").slick()
})
anywhere?
I am trying to get an effect like on this site so that when I click a div, jquery takes the id of the current clicked div and stores it in a variable.
$(function (){
$('.project-wrapper').click(function() {
var id = $(this).attr('id');
jQuery.ajax({
type: 'post',
url:'wp-content/themes/MartinFjeldUpdated/header.php',
dataType : 'HTML',
data:{"id" : id},
success: function(rs)
{
$(".display-video-image-graphic-fade").fadeIn(500);
}
});
});
});
Then I would like to get that variable to a php variable so that is automatically change the content I want to fade in simply by clicking the thumbnail of a post.
<?php
$paged = $_post['id'];
$args= array(
'id' => $paged,
);
query_posts($args);; if (have_posts()) : while (have_posts()) : the_post(); ?>
<div data-id="<?php echo get_the_ID();?>" class="display-video-image-graphic-fade">
<div class="display-outer-frame">
<div class="display-middle-frame">
<div class="video-frame">
<div id="slider">
<ul class="slides">
<?php the_content(); ?>
</ul>
</div>
</div>
<div class="title">
<h3 class="title-head"> <?php echo the_title(); ?></h3>
</div>
<div class="options">
<div class="inliner back-forth">
<div id="left" class="arrows">
<img src="wp-content/themes/MartinFjeldUpdated/images/left.pdf">
</div>
<div id="right" class="arrows">
<img src="wp-content/themes/MartinFjeldUpdated/images/right.pdf">
</div>
</div>
<div class="inliner out-cross">
<div class="cross">
<img src="wp-content/themes/MartinFjeldUpdated/images/cross.pdf">
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; else : endif; ?>
Somehow it does not work.. I am a real amateur in this, so if you need more explaining, please let me know and I'll try my best.
Thanks.
I have a chunk of content in a textarea that I can call dynamically to the front by using <php the_content ?> See full code below.
The problem is, I dont have an assigned area for the image. (I'm open to options to create one but I think it will be too much effort), anyway, is there anything I can do (JQuery / JS is fine) that I can call the image to fill the: <?php echo $the_content['image'] ?> that you see in my code, which obviously does not work? Meanwhile leaving the actual text part or rest of the content separate.
I am attaching an illustration for a more visual idea of what I am looking for
Here is the entire code for that section
<section class="box classes-box" id="classes_box"><!-- Section Events -->
<div class="container light-grey-background">
<div class="row">
<div class="col-md-6 no-padding">
<div class="boxing-classes" style="background-image: url('<?php echo $the_content['image'] ?>')">
<div class="classes">
<nav class="classes-nav">
<ul class="clean-list toggle-list clearfix">
<?php foreach($slides as $i => $slide): ?>
<li class="classes-menu-item ">
<input type="radio" id="toggle-<?php echo $slide['post']->ID; ?>" name="toggle-helper" autocomplete="off">
<label for="toggle-<?php echo $slide['post']->ID; ?>"><?php echo get_the_title( $slide['post']->ID ) ?></label>
</li>
<?php endforeach; ?>
</ul>
</nav>
</div>
</div>
</div>
<div class="col-md-6 no-padding ">
<?php foreach($slides as $i => $slide): ?>
<div class="classes-content-block" id="classes_content_<?php echo $slide['post']->ID ?>" style="display:none;">
<header class="padding white-background">
<h2 class="entry-header black-background"><?php echo get_the_title( $slide['post']->ID ) ?></h2>
</header>
<div class="entry-content padding">
<?php echo apply_filters('the_content', $slide['post']->post_content); ?>
<?php if ( !empty( $slide['options']['button'] )): ?>
<div class="white-background">
<a class="read-more text-center red-black-hover" href="<?php echo $slide['options']['button']['link'] ? $slide['options']['button']['link'] : '#'; ?>"><?php echo $slide['options']['button']['link_text'] ? $slide['options']['button']['link_text'] : 'View Timeline' ; ?></a>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
Normally, what people do is to create a Shortcode that will produce the desired HTML, something like:
[image-block src="apple-touch-icon.png" class="all-imgs" id="my-img"]The content[/image-block]
This would be the shortcode:
add_shortcode( 'image-block', function( $atts, $content) {
return sprintf(
'<div class="left"><img src="%1$s" class="%2$s" id="%3$s"></div><div class="right">%4$s</div>',
$atts['src'],
$atts['class'],
$atts['id'],
$content
);
});
And this the output:
See CSS property FLOAT : left|right
<div id=container class="clearfix">
<div class="image-wrapper" style="float:left;max-width:50%;padding:0;margin:0">
<img src="images/mypicture.jpg" alt="" class="rwd-image" id="mymage">
</div>
<div class="content-wrapper" style="float:left;max-width:50%;padding:0;margin:0">
<p>Lorem Ipsum</p>
</div>
</div>
I want to be able to conditionally load a class containing the word 'AUTHOR' in the comments section, next to the name of the person who was the author of the post. I know it has something to do with class bypostauthor, what I've got so far is:
<?php if $class == 'bypostauthor' ?>
<div class="author">AUTHOR</div>
<? endif; ?>
More info:
In comment section of my wordpress post page, the class .bypostauthor exists whenever a the author of post page comments on there post page, giving this for one of the comments in the comment section ->
<li class="comment byuser comment-author-admin bypostauthor odd alt thread-odd thread-alt depth-1 clearfix" id="li-comment-28">
<div class="comment-block" id="comment-28">
<div class="comment-inside-block">
<div class="comment-info">
<div class="comment-author vcard clearfix">
<img alt="" src="http://0.gravatar.com/avatar/6dbfd7e6bd95881c5736647c8736dd89?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G" class="avatar avatar-32 photo" height="32" width="32">
<div class="comment-meta commentmetadata">
<cite class="fn">Trent Aughey</cite>
<div style="clear:both;"></div>
<a class="comment-time" href="http://trentaughey.com/test/#comment-28"> 1 day ago </a> </div>
</div>
<div class="clearfix"></div>
</div>
<div class="comment-text">
<p>comment – 2</p>
<p class="reply">
<a class="comment-reply-link" href="/test/?replytocom=28#respond" onclick="return addComment.moveForm("comment-28", "28", "respond", "570")">Reply</a> </p>
</div>
</div>
</div>
<ul class="children">
<li class="comment byuser comment-author-admin bypostauthor even depth-2 clearfix" id="li-comment-29">
<div class="comment-block" id="comment-29">
<div class="comment-inside-block">
<div class="comment-info">
<div class="comment-author vcard clearfix">
<img alt="" src="http://0.gravatar.com/avatar/6dbfd7e6bd95881c5736647c8736dd89?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G" class="avatar avatar-32 photo" height="32" width="32">
<div class="comment-meta commentmetadata">
<cite class="fn">Trent Aughey</cite>
<div style="clear:both;"></div>
<a class="comment-time" href="http://trentaughey.com/test/#comment-29"> 1 day ago </a> </div>
</div>
<div class="clearfix"></div>
</div>
<div class="comment-text">
<p>HELLO</p>
<p class="reply">
</p>
</div>
</div>
</div>
When a non-author of the post page leaves a comment on the post the following code is used
<li class="comment even thread-even depth-1 clearfix" id="li-comment-20">
<div class="comment-block" id="comment-20">
<div class="comment-inside-block">
<div class="comment-info">
<div class="comment-author vcard clearfix">
<img alt="" src="http://0.gravatar.com/avatar/6dbfd7e6bd95881c5736647c8736dd89?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G" class="avatar avatar-32 photo" height="32" width="32">
<div class="comment-meta commentmetadata">
<cite class="fn">Trent Aughey</cite>
<div style="clear:both;"></div>
<a class="comment-time" href="http://trentaughey.com/test/#comment-20"> 1 month ago </a> </div>
</div>
<div class="clearfix"></div>
</div>
<div class="comment-text">
<p>Test, Test</p>
<p class="reply">
<a class="comment-reply-link" href="/test/?replytocom=20#respond" onclick="return addComment.moveForm("comment-20", "20", "respond", "570")">Reply</a> </p>
</div>
</div>
</div>
I'm trying to accomplish having the word 'AUTHOR' next to the author of post name whenever they comment on there page. Considering bypostauthor class appears whenever page author post a comment on his page I tried to use the following code to make a div class conditionally appear whenever the post author comments ->
<li <?php comment_class('clearfix'); ?> id="li-comment-<?php comment_ID() ?>">
<div class="comment-block" id="comment-<?php comment_ID(); ?>">
<div class="comment-inside-block">
<div class="comment-info">
<div class="comment-author vcard clearfix">
<?php echo get_avatar( $comment->comment_author_email, 32 ); ?>
<div class="comment-meta commentmetadata">
<?php printf(__('<cite class="fn">%s</cite>', 'playne'), get_comment_author_link()) ?><?php if $class == 'bypostauthor' ?>
<div class="author">AUTHOR</div>
<? endif; ?>
<div style="clear:both;"></div>
<a class="comment-time" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>"> <?php echo themeblvd_time_ago_1(); ?> </a><?php edit_comment_link(__('(Edit)', 'playne'),' ','') ?>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="comment-text">
<?php comment_text() ?>
<p class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</p>
</div>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.', 'playne') ?></em>
<?php endif; ?>
</div>
My code fix does nothing, can anyone tell me what I'm doing wrong please.
You can filter the comment author name instead of adding something to core files. Your change will be overwritten on a WordPress update.
add_filter( 'get_comment_author', 'your_prefix_filter_the_post_author_name' );
function your_prefix_filter_the_post_author_name( $author ) {
$classes = get_comment_class();
if (in_array( 'bypostauthor',$classes) ) {
$output = '<div class="author-tag"><p>AUTHOR - ' . $author . '</p></div>';
return $output;
}
return $author;
}
I was able to fix this problem using the following code:
function author_tag() {
$classes = get_comment_class();
if(in_array('bypostauthor',$classes)) {
$output = '<div class="author-tag"><p>AUTHOR</p></div>';
} /*else {
$output = '<div class="author-tag"><p>NOT AUTHOR</p></div>';
}*/
return $output;}
Placed the function as follows:
<li <?php comment_class('clearfix'); ?> id="li-comment-<?php comment_ID() ?>">
<div class="comment-block" id="comment-<?php comment_ID(); ?>">
<div class="comment-inside-block">
<div class="comment-info">
<div class="comment-author vcard clearfix">
<?php echo get_avatar( $comment->comment_author_email, 32 ); ?>
<div class="comment-meta commentmetadata">
<?php printf(__('<cite class="fn">%s</cite>', 'playne'), get_comment_author_link()) ?>
<?php echo author_tag(); ?>
<div style="clear:both;"></div>
<a class="comment-time" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>"> <?php echo themeblvd_time_ago_1(); ?> </a><?php edit_comment_link(__('(Edit)', 'playne'),' ','') ?>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="comment-text">
<?php comment_text() ?>
<p class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</p>
</div>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.', 'playne') ?></em>
<?php endif; ?>
</div>
Hope this helps anyone who had similar issues.