Jeremy Dennis Jeremy Dennis - 6 months ago 18
PHP Question

How to pull link and put into an href?

I have a website that I'm trying to populate with links. Right now, if you look at the website from the computer, you'll see that there's a floating box with text, then dots all over the map. If you hover over one of the dots, it will have the name of the site, along with the time period associated.

http://jeremynative.com/onthissite/

<?php
$i = 0;
while ( have_posts() ) : the_post();
$et_location_lat = get_post_meta( get_the_ID(), '_et_listing_lat', true );
$et_location_lng = get_post_meta( get_the_ID(), '_et_listing_lng', true );

$et_location_rating = '<div class="location-rating"></div>';
if ( ( $et_rating = et_get_rating() ) && 0 != $et_rating )
$et_location_rating = '<div class="location-rating"><span class="et-rating"><span style="' . sprintf( 'width: %dpx;', esc_attr( $et_rating * 17 ) ) . '"></span></span></div>';

if ( '' != $et_location_lat && '' != $et_location_lng ) {
?>




et_add_marker( <?php printf( '%1$d, %2$s, %3$s, \'<div id="et_marker_%1$d" class="et_marker_info"><div class="location-description"> <div class="location-title"> <h2>%4$s </h2> <div class="listing-info"><p>%5$s</p></div> </div> ' . $et_location_rating . ' </div> <!-- .location-description --> </div> <!-- .et_marker_info -->\'',
$i,
esc_html( $et_location_lat ),
esc_html( $et_location_lng ),
get_the_title(),
wp_strip_all_tags( addslashes( get_the_term_list( get_the_ID(), 'listing_type', '', ', ' ) ) )
); ?> );
<?php
}

$i++;
endwhile;

rewind_posts();
?>

Answer

Try with

<?php
$i = 0;
while ( have_posts() ) : the_post();
    $et_location_lat = get_post_meta( get_the_ID(), '_et_listing_lat', true );
    $et_location_lng = get_post_meta( get_the_ID(), '_et_listing_lng', true );

    $et_location_rating = '<div class="location-rating"></div>';
    if ( ( $et_rating = et_get_rating() ) && 0 != $et_rating )
        $et_location_rating = '<div class="location-rating"><span class="et-rating"><span style="' . sprintf( 'width: %dpx;', esc_attr( $et_rating * 17 ) ) . '"></span></span></div>';

    if ( '' != $et_location_lat && '' != $et_location_lng ) {
?>
        et_add_marker( <?php printf( '%1$d, %2$s, %3$s, \'<div id="et_marker_%1$d" class="et_marker_info"><div class="location-description"> <div class="location-title"><h2><a href="%6$s">%4$s</a></h2><div class="listing-info"><p>%5$s</p></div> </div> ' . $et_location_rating . ' </div> <!-- .location-description --> </div> <!-- .et_marker_info -->\'',
                $i,
                esc_html( $et_location_lat ),
                esc_html( $et_location_lng ),
                get_the_title(),
                wp_strip_all_tags( addslashes( get_the_term_list( get_the_ID(), 'listing_type', '', ', ' ) ) ),
                get_the_permalink()
            ); ?> );
<?php
    }

    $i++;
endwhile;

rewind_posts();
?>

I added the link inside the title and then used get_the_permalink() function to pull the permalink in.