【问题标题】:to to set the_permalink to a specific post, not the "active" post将 the_permalink 设置为特定帖子,而不是“活动”帖子
【发布时间】:2013-08-29 23:39:43
【问题描述】:

这里主要是对this问题的继续,代码也是一样的。我现在有可点击的标记叠加层,但它们都链接到与当前活动标记相关联的帖子,而不是与点击标记对应的帖子。 (我相信link to the site 会很有用 - 抱歉全是俄语)。

我不知道是 PHP/WordPress 问题(应该是什么而不是 'the_permalink'?)还是 jQuery/Gmap3 问题,所以我列出了所有标签。

我把它放了一大段代码,因为我的猜测是 et_add_marker 函数的定义可能很重要。我正在处理的部分标记为“以下是添加的代码”。

function et_add_marker( marker_order, marker_lat, marker_lng, marker_description ){
        var marker_id = 'et_marker_' + marker_order;

        $et_main_map.gmap3({
            marker : {
                id : marker_id,
                latLng : [marker_lat, marker_lng],
                options: {
                icon : "<?php echo get_template_directory_uri(); ?>/images/blue-marker.png"
                },
                events : {
                    click: function( marker ){
                        if ( et_active_marker ){
                            et_active_marker.setAnimation( null );
                            et_active_marker.setIcon( '<?php echo get_template_directory_uri(); ?>/images/blue-marker.png' );                                                                                                                               
                        }
                        et_active_marker = marker;

                        <!--marker.setAnimation( google.maps.Animation.BOUNCE);-->
                        marker.setIcon( '<?php echo get_template_directory_uri(); ?>/images/red-marker.png' );

                        $(this).gmap3("get").panTo( marker.position );

                        $.fn.et_simple_slider.external_move_to( marker_order );                                                       
                    },
                    mouseover: function( marker ){
                        $( '#' + marker_id ).css( { 'display' : 'block', 'opacity' : 0 } ).stop(true,true).animate( { bottom : '15px', opacity : 1 }, 500 );
                    },
                    mouseout: function( marker ){
                        $( '#' + marker_id ).stop(true,true).animate( { bottom : '50px', opacity : 0 }, 500, function() {
                            $(this).css( { 'display' : 'none' } );
                        } );
                    }
                }
            },
            overlay : {
                latLng : [marker_lat, marker_lng],
                options : {
                    content : marker_description,                                            
                    offset : {
                        y:-42,
                        x:-122
                    }
                },
                    /*Below is the added code, that should make overlay link to a corresponding WP post. This way it links to the post, associated with the active marker, not the clicked marker. */
                events : { 
                    click: function (marker) { 
                        location.href = "<?php the_permalink(); ?>"; 
                    }
                    /*End of the added code*/
                }                    
            }
        });
    }
<?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 jquery wordpress google-maps-api-3 jquery-gmap3


    【解决方案1】:

    我不熟悉 wordpress,所以我不能告诉你如何准确地做到这一点,但你必须将永久链接作为参数传递给函数并在内部使用这个参数,而不是在函数内部使用 &lt;?php the_permalink(); ?&gt;函数。

    【讨论】:

    • 您的意思是函数 'et_add_marker( marker_order, marker_lat, marker_lng, marker_description )' - 在括号中添加类似 'marker_url' 的内容?我是这么想的,但是我完全对调用函数时获取这些参数的方式感到困惑(见代码底部)。
    • 好的,经过两天的思考,我明白了。谢谢@Dr.Molle,这真的是一个提示。该解决方案由三部分组成:1)向函数添加一个参数“marker_url”,如前一条评论中所述; 2)将数据传递给函数——这是最棘手的部分! 3) 设置 location.href = marker_url
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    相关资源
    最近更新 更多