MapPress Show Date and Category on Mashup Pop Ups

Home Forums MapPress Support MapPress Show Date and Category on Mashup Pop Ups

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13775
    dleroischmidt
    Participant

    Hi,
    I’m trying to display the Date and Category of the individual Map POI while on the Mashup screen. These fields show when I’m on the individual post page with it’s map but on the Mashup map, the Category and Date are blank. What code can I add to help me get these to display there.

    Individual POI Map Example

    Mashup Map Example

    I’m using the following code in the map_poi.php template file.

    <div class='mapp-body'>
    		<!-- <//?php echo $poi->get_thumbnail(array('class' => 'mapp-thumb')); ?> -->
    		<?php echo $poi->get_body(); ?>
    		Date: &nbsp;<?php echo the_time('F j, Y'); ?><br />
    		Category:&nbsp;<?php $categories = get_the_category(); echo $categories[0]->cat_name; ?>
    	</div>
    #13777
    Chris
    Keymaster

    Hi,

    The WP functions that begin with ‘the_’ (like the_time) are really meant to work only on a global current post, in the theme’s “The Loop” section.

    The mashup has its own query so the ‘the_’ functions won’t work. But there are two workarounds:

    1) Find the corresponding WP function that uses a post or post ID instead. For example, instead of the_time(‘F’), call get_the_time(‘F’, $post_id) instead. Not all template functions have a clear analog, for example get_the_category() has to be replaced with get_the_terms().

    2) Save the current post from The Loop, set up the mashup post, and then restore the current post. Then you can use ‘the_’ functions in the mashup.

    Example code for #1:

    <?php
      $post = $poi->get_post();
      if ($post) {
    	echo get_the_time( 'F j, Y', $post) . "<br/>";
    	$terms = get_the_terms( $post->ID, 'category');
    	if (isset($terms[0]))
    		echo $terms[0]->name;
      }
    ?>

    Example for #2:

    <?php
      global $post;
    
      // Save current post from The Loop
      $current_post = ($post) ? clone($post) : null;
    
      $post = $poi->get_post();
      if ($post) {
    	setup_postdata($post);
    	echo the_time( 'F j, Y') . "<br/>";
    	$categories = get_the_category();
    	if (isset($categories[0]))
    		echo $categories[0]->cat_name;
    
    	// Restore original post so we don't interfere with The Loop
    	if ($current_post) {
    		$post = $current_post;
    		setup_postdata($current_post);
    	}
      }
    ?>
    #13898
    dleroischmidt
    Participant

    Hi Chris,
    Sorry for the delay and please bear with me. I tried option 1 in the templates/map_poi.php file. It works perfectly on the Mashup view, but now the individual Post views only show the title. Here is the code for the map_poi.php as it is now. Is there a way to have a template for the Mashup and a separate one for the single?

    Thanks for your assistance 🙂

    <div class='mapp-iw'>
    	<div class='mapp-title'>
    		<?php echo $poi->get_title_link(); ?>
    	</div>
    	<div class='mapp-body'>
    		<?php echo $poi->get_body(); ?>
    
    		<?php
    		  global $post;
    
    		  // Save current post from The Loop
    		  $current_post = ($post) ? clone($post) : null;
    
    		  $post = $poi->get_post();
    		  if ($post) {
    			setup_postdata($post);
    			echo the_time( 'F j, Y') . "<br/>";
    			$categories = get_the_category();
    			if (isset($categories[0]))
    				echo $categories[0]->cat_name;
    
    			// Restore original post so we don't interfere with The Loop
    			if ($current_post) {
    				$post = $current_post;
    				setup_postdata($current_post);
    			}
    		  }
    		?>
    		
    	</div>
    	<div class='mapp-links'>
    		<?php echo $poi->get_links(); ?>
    	</div>
    </div>
    #13899
    Chris
    Keymaster

    Hi,

    There’s only one template, but you can get different output for mashups and individual posts by including an ‘else’ after you check if there’s a post for the current POI. For example, to print the body saved with the POI on individual maps:

    
    if ($post) { 
    ... 
    } else {
      echo $poi->get_body();
    }
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.