WordPress.org

Ready to get started?Download WordPress

Forums

AJAX: close post when another one opens (2 posts)

  1. beernews
    Member
    Posted 4 years ago #

    I want it so that when you click to open an excerpt post or the main post, any other post on the page closes (so that a user cant have many posts open at the same time). That or have AJAX load all posts in the top left corner. How would I modify my AJAX code for http://farmball.com/boston?

    <?php
    
    function cfct_ajax_post_content($post_id) {
    	global $post, $posts, $wp_query, $wp;
    	$posts = get_posts('include='.$post_id);
    	$post = $posts[0];
    	if (is_null($post)) {
    		$posts = get_pages('include='.$post_id);
    		$post = $posts[0];
    	}
    	if (is_null($post)) {
    		$posts = get_posts('post_status=private&include='.$post_id);
    		$post = $posts[0];
    		if ($post) {
    			$user = wp_get_current_user();
    			if (!$user->ID || $user->ID != $post->post_author) {
    				$post = null;
    			}
    		}
    	}
    	if (!$post) {
    		die('');
    	}
    	$wp_query->in_the_loop = true;
    	setup_postdata($post);
    	remove_filter('the_content', 'st_add_widget');
    	$wp->send_headers();
    	cfct_content();
    	echo '<div class="close" id="post_close_'.$post_id.'"><a href="#">'.__('Close', 'carrington').'</a></div>';
    }
    
    function cfct_ajax_load() {
    	if (isset($_GET['cfct_action'])) {
    		switch ($_GET['cfct_action']) {
    			case 'post_content':
    			case 'post_comments':
    				if (isset($_GET['id'])) {
    					$post_id = intval($_GET['id']);
    				}
    				else if (isset($_GET['url'])) {
    					$post_id = url_to_post_id($_GET['url']);
    				}
    				if ($post_id) {
    					call_user_func('cfct_ajax_'.$_GET['cfct_action'], $post_id);
    					die();
    				}
    		}
    	}
    }
    ?>
  2. dikkevandale
    Member
    Posted 4 years ago #

    It seems that it's working already?

Topic Closed

This topic has been closed to new replies.

About this Topic