AV88 Posted October 18, 2014 Share Posted October 18, 2014 (edited) Hi all, I've got a problem with a php code on my website. I don't know why, but the hyperlink is wrong, because it's taken also the link of the current page, before the one of the page of destination. (see the attachment) Where is the mistake?Thanks all for the help $post_id = $instance['posts_name']; $title = apply_filters('widget_title', $instance['title']); if ( empty($title) ) $title = false; echo '<div class="widget top-story">'; if ( $title ) echo $before_title . $title . $after_title . "\n"; ?> <div> <?php $post = get_post( $post_id ); ?> <a href="<?php echo $post->post_name; ?>" class="image"><?php echo get_the_post_thumbnail( $post_id, 'top-story'); ?><span class="comment-icon"><?php echo $post->comment_count; ?></span></a> <span><?php the_time('d.m.Y | g:i A'); ?></span> <span class="rating"><a href="#" class="active"></a><a href="#" class="active"></a><a href="#"></a><a href="#"></a><a href="#"></a></span> <p><a href="<?php echo $post->post_name; ?>"><?php echo $post->post_title; ?></a></p> </div> <?php echo '</div>'; } /* Update widget settings */ function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['posts_name'] = $new_instance['posts_name']; return $instance; } /* Widget form */ function form( $instance ) { $defaults = array( 'title' => '', 'posts_name' => '', ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label> <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" /> </p> <p> <label for="<?php echo $this->get_field_id('posts_name'); ?>">Choose Post:</label> <select name="<?php echo $this->get_field_name('posts_name'); ?>" id="<?php echo $this->get_field_id('posts_name'); ?>" class="widefat"> <?php $posts_array = get_posts( array('numberposts' => -1) ); ?> <?php foreach( $posts_array as $post ) : setup_postdata($post); ?> <option value="<?php echo $post->ID; ?>"<?php selected( $instance['posts_name'], $post->ID ); ?>><?php echo $post->post_title; ?></option> <?php endforeach; ?> </select> </p> <?php } } Edited October 18, 2014 by AV88 Quote Link to comment https://forums.phpfreaks.com/topic/291907-help-with-php-widget-link/ Share on other sites More sharing options...
jcbones Posted October 18, 2014 Share Posted October 18, 2014 This is the reason why you should always put a fully qualified URI in an anchor tag. Putting relative links into an anchor tag, if not well thought out, will create the problem you are having. In other words: BAD <a href="/my/links">Links</a> Good <a href="http://my.site.com/my/links">Links</a> You will have less of these problems. Quote Link to comment https://forums.phpfreaks.com/topic/291907-help-with-php-widget-link/#findComment-1494086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.