Inserting custom FB share button in post (Wordpress) - php

Im trying to insert big custom FB share button.
I was able to make it appear, but the problem started to happen with jquery.
I am having 2 fb share buttons on the same post, but for only one of them share popup opens up. What must i do to make the second share popup work? You can find below the code im using:
<?php
/**
* The single post loop Default template
**/
if (have_posts()) {
the_post();
$td_mod_single = new td_module_single($post);
?>
<article id="post-<?php echo $td_mod_single->post->ID;?>" class="<?php echo join(' ', get_post_class());?>" <?php echo $td_mod_single->get_item_scope();?>>
<div class="td-post-header">
<?php echo $td_mod_single->get_category(); ?>
<header class="td-post-title">
<?php echo $td_mod_single->get_title();?>
<?php if (!empty($td_mod_single->td_post_theme_settings['td_subtitle'])) { ?>
<p class="td-post-sub-title"><?php echo $td_mod_single->td_post_theme_settings['td_subtitle'];?></p>
<?php } ?>
<div class="td-module-meta-info">
<?php echo $td_mod_single->get_author();?>
<?php echo $td_mod_single->get_date(false);?>
<?php echo $td_mod_single->get_comments();?>
<?php echo $td_mod_single->get_views();?>
</div>
</header>
</div>
<?php echo $td_mod_single->get_social_sharing_top();?>
<div class="td-post-content">
<div class="big-facebook-share" data-url="<?php echo home_url(add_query_arg(array(),$wp->request));?>" id="fb-share-button">
<span class="big-share-text"><?php _e('Share on facebook','fb');?></span>
</div>
<script>
jQuery(function(){
jQuery("#fb-share-button").on('click', function () {
fbShare(jQuery(this).attr("data-url"));
})
});
function fbShare(url) {
var width=640;
var height=320;
var leftPosition, topPosition;
leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
topPosition = (window.screen.height / 2) - ((height / 2) + 50);
var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=no,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";
var u=location.href;
var t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(t),'sharer', windowFeatures);
return false;
}
</script>
<?php
// override the default featured image by the templates (single.php and home.php/index.php - blog loop)
if (!empty(td_global::$load_featured_img_from_template)) {
echo $td_mod_single->get_image(td_global::$load_featured_img_from_template);
} else {
echo $td_mod_single->get_image('td_696x0');
}
?>
<?php echo $td_mod_single->get_content();?>
<div align="center"> <?php echo do_shortcode('[fb_button]'); ?></div>
<div class="big-facebook-share" data-url="<?php echo home_url(add_query_arg(array(),$wp->request));?>" id="fb-share-button">
<span class="big-share-text"><?php _e('dhare on facebook','fb');?></span>
</div>
<?php echo do_shortcode('[fbcomments url="https://facebook.com/Facebook/" width="700" count="off" num="3" countmsg="wonderful comments!"]'); ?>
</div>
<footer>
<?php echo $td_mod_single->get_post_pagination();?>
<?php echo $td_mod_single->get_review();?>
<div class="td-post-source-tags">
<?php echo $td_mod_single->get_source_and_via();?>
<?php echo $td_mod_single->get_the_tags();?>
</div>
<?php echo $td_mod_single->get_social_sharing_bottom();?>
<?php echo $td_mod_single->get_next_prev_posts();?>
<?php echo $td_mod_single->get_author_box();?>
<?php echo $td_mod_single->get_item_scope_meta();?>
</footer>
</article> <!-- /.post -->
<?php echo $td_mod_single->related_posts();?>
<?php
} else {
//no posts
echo td_page_generator::no_posts();
}

Your jQuery selector is targeting the id and since the buttons have the same id (they should be unique), only one is working. Consider giving each button a unique id or update your jQuery selector to use class instead.
jQuery(".big-facebook-share").on("click", function() {...});

Related

Issues with undefined function that is in fact defined

I didn't build this PHP file, but I am trying to figure out why it is giving me errors. If the "Block layout mode" ACF variable is set to "Modal" then the block works, but gives me this error. "Undefined variable $vids on line 176". If I select the "Embed & Thumbnail" mode, then none of the block is displayed and I get this error. "Call to undefined function vc_embed_layout() on line 252". I can't pin down why this is happening, and I haven't been able to find any unclosed tags or anything in my php file. This is the file in question, and I've marked the lines that trigger errors.
<?php
global $theme_text_domain;
$block_class_identifier = 'blk__vidcol';
// default variables
$block_id = $top_class = $top_style = $inner_class = $inner_style = '';
// check for custom id
$block_id .= BLOCK::set_id( get_sub_field('content_block_id') );
// set block class, $i comes from FLEX class loop and represents the block order on a page
$top_class .= BLOCK::set_standard_classes( $i );
$top_class .= BLOCK::set_custom_classes( get_sub_field('content_block_classes') );
// check for top padding adjustment
$top_class .= BLOCK::set_padding_class( get_sub_field('block_padding_adjustment') );
$top_style .= BLOCK::set_padding_style( get_sub_field('block_padding_adjustment'), get_sub_field('custom_top_padding'), get_sub_field('custom_bottom_padding'));
// check for custom color theme
$top_style .= BLOCK::set_colors( get_sub_field('color_theme'), get_sub_field('text_color'), get_sub_field('custom_background_color') );
// check for width settings
$inner_class .= BLOCK::set_width_class( get_sub_field('content_width') );
$inner_style .= BLOCK::set_width_style( get_sub_field('content_width'), get_sub_field('custom_maximum_content_width') );
$block_assets = get_stylesheet_directory_uri() . '/inc/blocks/' . basename(__FILE__, '.php') . '/assets/';
/*
CUSTOM BLOCK SPECIFIC SETUP
*/
$layout = get_sub_field('block_layout_mode');
$top_class .= ' layout-' . $layout;
// title color
$h2_style = (get_sub_field('color_theme') == 'custom') ? ' color: ' . get_sub_field('custom_title_color') . ';' : '';
/**
* outputs code for the modal version of the video collection block
* #return html output
*/
if (!function_exists('vc_modal_layout')) {
function vc_modal_layout() {
global $block_class_identifier;
$cta_label = get_sub_field('cta_label');
$counter = 0;
$cta = array(
'style' => get_sub_field('cta_style'),
'button_color' => get_sub_field('button_color'),
'button_text_color' => get_sub_field('button_color')
);
$cta_class = BLOCK::get_cta_style( $cta, '.' . $block_class_identifier . ' .button');
?>
<?php // list section ?>
<?php if( have_rows('videos') ): ?>
<div class="vid-container">
<?php while ( have_rows('videos') ) : the_row(); ?>
<?php if ($counter == 0): ?>
<div class="vid-featured">
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
<a class="vid_overlay" data-fancybox data-src="#<?php echo $block_class_identifier; ?>_vid_0" href="javascript:;"></a>
</div>
<!-- modal -->
<div id="<?php echo $block_class_identifier; ?>_vid_0" class="modal video-modal" style="display: none;">
<div class="modal-inner">
<h3><?php echo get_sub_field('video_title'); ?></h3>
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
<div class="vid-list">
<?php else: ?>
<div class="vid-item">
<div class="item-btn">
<a class="button <?php echo $cta_class; ?>" data-fancybox data-src="#<?php echo $block_class_identifier; ?>_vid_<?php echo $counter; ?>" href="javascript:;"><?php echo $cta_label; ?></a>
</div>
<div class="item-title"><?php echo get_sub_field('video_title'); ?></div>
</div>
<!-- modal -->
<div id="<?php echo $block_class_identifier; ?>_vid_<?php echo $counter; ?>" class="modal video-modal" style="display: none;">
<div class="modal-inner">
<h3><?php echo get_sub_field('video_title'); ?></h3>
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
<?php endif; ?>
<?php $counter++; ?>
<?php endwhile; ?>
</div>
</div>
<?php else: ?>
No videos defined.
<?php endif; ?>
<?
}
}
/**
* outputs code for the embed version of the video collection block
* #return html output
*/
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout($vids, $i) {
?>
<?php if ( $vids ): ?> **this is line 176**
<div class="vid-container2">
<h2 class="vid-title"><?php echo $vids[0]['video_title']; ?></h2>
<div class="vid-container2-inner">
<div class="vid-embed">
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo $vids[0]['youtube_embed_code']; ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen onload="this.style.visibility = 'visible';"></iframe>
</div>
</div>
<div class="vid-thumbnails">
<?php foreach ($vids as $key => $vid): ?>
<?php $wrap_class = ($key == 0) ? ' tn-hide' : ''; ?>
<div class="tn-wrapper <?php echo $wrap_class; ?>" data-embed="<?php echo $vid['youtube_embed_code']; ?>" data-title="<?php echo $vid['video_title']; ?>">
<img src="https://img.youtube.com/vi/<?php echo $vid['youtube_embed_code']; ?>/mqdefault.jpg" alt="">
</div>
<?php endforeach; ?>
</div>
</div>
<script>
var vid_swap = function() {
$('.block_<?php echo $i; ?> .vid-embed').css({opacity: 1});
$('.block_<?php echo $i; ?> .tn-wrapper').on('click', function(e) {
var $this = $(this);
var embed_id = $this.attr('data-embed');
var title = $this.attr('data-title');
console.log('embed = ' + embed_id);
$('.block_<?php echo $i; ?> .vid-title').animate({opacity: 0}, 100);
$('.block_<?php echo $i; ?> .vid-embed').animate({opacity: 0}, 1000, function() {
$('.block_<?php echo $i; ?> .vid-embed, .block_<?php echo $i; ?> .vid-title').css('visiblity','hidden');
$('.block_<?php echo $i; ?> .vid-title').html( title );
$('.block_<?php echo $i; ?> .vid-embed iframe').attr('src', 'https://www.youtube.com/embed/' + embed_id);
$('.block_<?php echo $i; ?> .tn-wrapper.tn-hide').removeClass('tn-hide');
$this.addClass('tn-hide');
$('.block_<?php echo $i; ?> .vid-title').css('visiblity','visible').delay(500).animate({opacity: 1}, 500);
$('.block_<?php echo $i; ?> .vid-embed').delay(500).animate({opacity: 1}, 1000);
});
});
}
jQuery(document).on('block_init', vid_swap);
</script>
</div>
<?php else: ?>
No videos defined.
<?php endif; ?>
<?php
}
}
?>
<section id="<?php echo $block_id; ?>" class="<?php echo $block_class_identifier; ?> <?php echo $top_class; ?>" style="<?php echo $top_style; ?>">
<div class="inner <?php echo $inner_class; ?>" style="<?php echo $inner_style; ?>">
<?php // title section ?>
<?php if (get_sub_field('title')): ?>
<h2 style="<?php echo $h2_style; ?>"><?php echo get_sub_field('title'); ?></h2>
<?php endif; ?>
<?php $vids = get_sub_field('videos'); ?>
<?php if ($layout == 'modal') vc_modal_layout($vids); ?>
<?php if ($layout == 'embed') vc_embed_layout($vids, $i); ?> **This is line 252**
</div>
</section>
You're not accepting any arguments in vc_modal_layout() function declaration.
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout() {
needs to have parameters in order to accept arguments.
something like this is what you're looking for:
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout($vids=[], $i=0) {
And it's the same idea with vc_modal_layout, the function needs to be able to accept the variables from outside it.
When we call a function, the function needs to be able to accept all arguments passed to it. And all variables we use need to be defined, if there's a risk of them being undefined or empty arrays, we can check them with if(!empty($var)) or if(isset($var))
An alternative to passing the variable to the function is to access it as a global. But it's generally better to pass the variable to the function because when we pass the variable to a function in PHP it works with a copy of the variable's value inside the function. When we do something like this:
$var = 10;
function doIt(){
global $var;
$var++;
}
doit();
echo $var;
we could overcomplicate things..
let's have a closer look here:
if ($layout == 'modal') vc_modal_layout($vids);
if ($layout == 'embed') vc_embed_layout($vids, $i); ?> **This is line 252**
function vc_modal_layout(){ ... }
// should be:
function vc_modal_layout($vids){ ... }
function vc_embed_layout($vids, $i)
// looks good.
Aside from that, nothing stands out as really unusual & I'd want to have a look at the actual site to tinker with this problem further.

Wordpress link and content

I'm creating a menu for wordpress, but when I click on the permalink the content stays the same. And my second dropdown does not work eather. The problem is that on my section where the content needs to be it not shows. The content just takes the last message and not the post i select on the menu.
https://i.gyazo.com/1698056c27baa40768659d2edab5e3d9.png
This is how it stays even if i click an other post.
<?php
get_header();
?>
<div class="menu">
<div>
<h1>Documentatie</h1>
</div>
<?php $cats = get_categories();
foreach ($cats as $cat) {
$cat_id= $cat->term_id;
echo "<div class='dropdown'>";
echo "<button onclick='myFunction()' class='dropbtn'>".$cat->name."</button>";
echo "<div id='myDropdown' class='dropdown-content'>";
query_posts("cat=$cat_id&post_per_page=100");
if (have_posts()) : while (have_posts()) : the_post(); ?>
<button class="dropbutton"><h2><?php the_title(); ?></h2></button>
<?php endwhile;
?>
</div>
</div>
<?php
else :
echo "<p>Geen content gevonden</p>";
endif;
wp_reset_postdata();
}
?>
</div>
<div class="content">
<h2><?php the_title(); ?></h2>
<div class="wpcontent"><?php the_content(); ?> </div>
</div>
<?php wp_footer(); ?>
<script>
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</script>
Have a look at my other 2 comments and proposed solution below, this is not a WP issue you're facing, it's JS/jQuery
echo "<div class='dropdown'>";
echo "<button onclick='myFunction(" . $cat->slug . ")' class='dropbtn btn-" . $cat->slug . "'>".$cat->name."</button>";
echo "<div id='myDropdown' class='dropdown-content'>";
And:
function myFunction(cat_slug) {
$('.btn-' + cat_slug).show();
}
Try that, should work :)

How to change previous html (a part) with that of ajax success callback data?

I have this list of poll questions (with distinct id) along with options. When I submit a poll option I get an AJAX response back.
I want to use this response to publish as result instantly without page refresh but exactly replacing the html of the same poll question with the success ajax data received.
Specifically, my question is on submitting a poll answer how to change/remove the question (html) to that of new html containing answer(different html). Only the html of the related poll should change not all the poll's html. I'm successfully getting the ajax success callback.
This is the code:
php:
<?php if(isset($GLOBALS['questions']) && is_array($questions)): ?>
<?php foreach($questions as $key => $question): ?>
<?php require 'poll.php'; ?>
<?php $user = Subscribers::getSubscriber($question->userID); ?>
<li class="comment-holder" id="_<?php echo $question->id; ?>">
<div class="user-img">
<img src="<?php echo $user->profile_img; ?>" class="user-img-pic" />
</div>
<div class="comment-body">
<h3 class="username-field"><?php echo $user->username; ?></h3>
<div class="comment-text">
<?php echo $question->question; ?>
<hr />
</div>
</div>
<!--Relevant part: display choices -->
<div class="poll-option">
<?php if($completed):?>
<div id="completed">
<p>You have completed this poll, thanks.</p>
<!--**This is where ajax response should appear**-->
</div>
<?php else: ?>
<?php if(!empty($opts)): ?>
<div class="poll-options">
<?php
$TypeOfPoll = $question->pollType;
switch($TypeOfPoll) {
case "option1":
foreach($opts as $index => $opt) {
if ($opt->id == $question->id) {
echo "<input type='radio' name='choice' value='$opt->choice_id' />";
echo $opt->name,'<br />';
}}
echo "<input type='submit' value='Submit' id='$question->id' class='submitPoll' />";
break;
case "option2":
echo 'Option 2';
break;
case "option3":
echo 'Option 3';
break;
case "option4":
echo 'Option 4';
break;
default:
foreach($opts as $index => $opt) {
if ($opt->id == $question->id) {
echo '<input type="radio" name="choice" value="<?php echo $opt->choice_id; ?>" />';
echo $opt->name,'<br /><br />';
}}
echo "<input type='submit' value='Submit' id='$question->id' class='submitPoll' />";
break;
}
?>
</div>
<?php else: ?>
<p>No choices available!</p>
<?php endif; ?>
<?php endif; ?>
</div>
<div class="comment-buttons-holder">
<ul>
<li id="<?php echo $question->id; ?>" class="delete-btn">X</li>
</ul>
</div>
</li>
<?php endforeach; ?>
<?php endif; ?>
Ajax:
$(document).ready(function() {
add_submitPoll_handlers();
});
function add_submitPoll_handlers() {
$('.submitPoll').each(function() {
// 'submitPoll' is class for submit button
var btn = this;
$(btn).click(function() {
var ChoiceAnsVal = $('input:radio[name=choice]:checked').val();
var userId = $('#userId').val();
var id = btn.id;
console.log('user:'+userId+'poll:'+btn.id+'choice:'+ChoiceAnsVal);
submit_poll(userId, id, ChoiceAnsVal);
});
});
}
function submit_poll(userId, id, ChoiceAnsVal) {
$('.submitPoll').click(function() {
$.post("ajax/submit_poll.php",
{
task:"submit_poll",
userId: userId,
poll_id: id,
choice_id:ChoiceAnsVal
}
).error(
function() {
console.log("Error in script.js")
}
).success(
function(data) {
$('#completed').html('You have completed the poll!');//not working
//console.log("ResponseText:" + data); //I'm getting the //response
}
);
});
Ajax is exactly designed for the above purpose. But for this i would suggest using jQuery+AJAX. This will be an easy method.Since you haven't provide you code I cannot provide you the exact code needed. The code will be like this
HTML
<div id="question_id">html</div>
Jquery
$(selector).something(function(){
var id=$(this).id; //assuming this will be the id of question that is selected
$.ajax({
url:url. //url to which data to be submitted
type:post,
data: //data to be submitted
success:function(data){
//data will be page/data that returned by the server page
$(selector).html(html_daya);// you can create html string that to replaced and pass it as argument to html function
}
});
});
Please refer http://api.jquery.com/jquery.ajax/ for complete documentation.

Pagination on Wp-Property not working

I have a Wordpress site that is using Wp-Property and the pagination isn't working, can anyone help fix this please. Please see below the pagination part from the function page.
<?php if($use_pagination) { ?>
if(!wpp_pagination_<?php echo $unique_hash; ?>) {
jQuery("#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider_wrapper").each(function() {
var this_parent = this;
/* Slider */
jQuery('.wpp_pagination_slider', this).slider({
value:1,
min: 1,
max: <?php echo $pages; ?>,
step: 1,
slide: function( event, ui ) {
/* Update page counter - we do it here because we want it to be instant */
jQuery("#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_current_page_count").text(ui.value);
jQuery("#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider .slider_page_info .val").text(ui.value);
},
stop: function(event, ui) {
wpp_query_<?php echo $unique_hash; ?> = changeAddressValue(ui.value, wpp_query_<?php echo $unique_hash; ?>);
}
});
/* Fix slider width based on button width */
var slider_width = (jQuery(this_parent).width() - jQuery(".wpp_pagination_back", this_parent).outerWidth() - jQuery(".wpp_pagination_forward", this_parent).outerWidth() - 30);
jQuery(".wpp_pagination_slider", this_parent).css('width', slider_width);
jQuery('.wpp_pagination_slider .ui-slider-handle', this).append('<div class="slider_page_info"><div class="val">1</div><div class="arrow"></div></div>');
});
wpp_pagination_<?php echo $unique_hash; ?> = true;
}
<?php } ?>
});
</script>
<?php
$js_result = ob_get_contents();
ob_end_clean();
ob_start(); ?>
<div class="properties_pagination <?php echo $settings['class']; ?> wpp_slider_pagination" id="properties_pagination_<?php echo $unique_hash; ?>">
<div class="wpp_pagination_slider_status">
<?php
if(function_exists('WPPFL_getNumberOfFavorites')) {
$num_of_favorites = WPPFL_getNumberOfFavorites();
} else{
$num_of_favorites = 0;
}
$currentTemplate = "";
if (isset($wpp_query['template'])) {
$currentTemplate = $wpp_query['template'];
}
?>
<?php if ($currentTemplate==TEMPLATEPATH . "/list-my-property-content.php") { ?>
<div class="wppcs-sub-menu">
<?php global $post;
$post_name = $post->post_name; ?>
<?php $class='class="active"'; ?>
<ul>
<li <?php if($post_name == 'list-my-property') { echo $class; } ?>>
<a href="<?php echo get_bloginfo('url'); ?>/list-my-property/">
View Listed Properties
</a>
</li>
<li <?php if($post_name == 'add-new-property') { echo $class; } ?>>
<a href="<?php echo get_bloginfo('url'); ?>/list-my-property/add-new-property/">
Add New Property
</a>
</li>
</ul>
</div>
<?php } else { ?>
<ul class="top_part">
<li><a>Search results</a></li>
<li class="favor">My Favourites(<span class="number_of_favorites"><?php echo $num_of_favorites; ?></span>)</li>
</ul>
<?php } ?>
<div class="clear"></div>
</div>
<?php if($use_pagination) { ?>
<div class="wpp_pagination_slider_wrapper">
<div class="wpp_page_numbers_block">
<span class="numbers-title">Pages</span>
<?php
if ($pages < 10) {
for($i=1; $i<=$pages; $i++) {
echo '<span class="page_numbers" data-value="'.$i.'">'.$i.'</span>';
}
} else {
for($i=1; $i<=$pages; $i++) {
if (($i < 4) || ($i>$pages-3)) {
echo '<span class="page_numbers" data-value="'.$i.'">'.$i.'</span>';
}
if ($i==4) {
echo '<span class="middle-pages"><span class="dotted-separator">...</span></span>';
}
}
}?>
</div>
<div class="wpp_pagination_back wpp_pagination_button"><?php _e('Prev', 'wpp'); ?></div>
<div class="wpp_pagination_forward wpp_pagination_button"><?php _e('Next', 'wpp'); ?></div>
<div class="wpp_pagination_slider"></div>
</div>
<?php } ?>
</div>
<div class="ajax_loader"></div>
<?php
$html_result = ob_get_contents();
ob_end_clean();
Thank you in anticaption.
The first thing which can cause your issue is some of third party plugins or your theme. So try firstly to deactivate third party plugins and switch theme to default one to be sure that issue doesn't relate to any of them.
Such request you can also send here
https://wordpress.org/support/plugin/wp-property
or on our site
https://usabilitydynamics.com/contact-us/
Regards.
Usability Dynamics Support

jquery delete selected comment

I have made a forum and I want the user to delete their comment if they don't want it.
Now it deletes the first post and not the post that they have clicked "delete" on.
How can I check that its the comment they click on that gets deleted?
I have made this:
$(function() {
$(".slet").click( function(event) {
event.preventDefault();
//$(this).css("background-color","#000");
var id = "<?=$deleteID?>";
//alert(id);
$("#forum_content").fadeOut();
});
});
and my php:
it is a little messy.
<?php foreach ($comments as $comment): ?>
<?php
if($comment->level == "admin")
{
echo '<div class="adminclass">';
}
?>
<div id="forum_content" class="content">
<div class="forum_comment">
<div class="forum_profil_img"><img width="90" height="90" src="<?php echo base_url();?>images/users/thumbs/<?php echo $query->profile_picture; ?>"></div><!-- forum_profil_img -->
<div class="forum_post_content">
<span class="post_navn"><?php echo anchor('profil/index/'.$comment->kommentar_brugernavn, $comment->kommentar_brugernavn); ?></span>
<span style="font-size:11px; margin-left:3px; color:#686868;"><i> Siger</i></span><br>
<div id="data"><?php echo nl2br($comment->indhold); ?></div><!-- data -->
</div><!-- forum_post_content -->
<div style="width:auto; float:right; color:#a0a0a0; clear:left; position:relative; bottom:-15px;" id="forum_dato">
<i>
<abbr class="timeago" title="<?php echo $comment->dato; ?>"><?php echo $comment->dato; ?></abbr>
<?php
if($this->session->userdata('logget_ind') == 1 &&
$this->session->userdata('username') == $comment->brugernavn &&
time() - $comment->time < 300)
{ echo "- <a href=''>Ret</a> - <a class='slet' href=''>Slet</a>";
$deleteID = $comment->commentID;
} ?>
</i>
</div><!-- forum_post_content -->
</div><!-- forum_comment -->
<?php if ($comment->level == "admin") { ?> <span class="admin-ribbon"></span></div> <?php } ?>
</div><!-- content -->
<?php endforeach ?>
On each page use a counter, on which you assign a unique id to each comment from as it's added. That way you can delete comments irrelevant of their order (original or ordered).
Change the line echo "- <a href=''>Ret</a> - <a class='slet' href=''>Slet</a>" to
echo "- <a href=''>Ret</a> - <a class='slet' id='slet-".$comment->commentID."' href=''>Slet</a>"
and the click handler to:
$(function() {
$(".slet").click( function(event) {
event.preventDefault();
//$(this).css("background-color","#000");
var id = $(this).attr("id").replace(/[^0-9]/g, "");
alert(id);
$("#forum_content").fadeOut();
});
});

Categories