Jump to content

Help with php widget link


AV88

Recommended Posts

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)

 

Untitled-2.jpg

 

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 by AV88
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.