Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Recommend a Friend: Want to send top most recent post not last WordPress

  • SOLVED

On my Blog: http://www.sowhatireallymeant.com/ I installed "Recommend a Friend," which works well on individual pages. But on the home page, where I show 15 most recent posts, with the most recent at the top, it will send the link for the oldest post at the bottom, not the most recent at the top.

I'm not a computer programmer, but I can get into editor and change the language that's doing that if someone would please help me.

Thank you!

Answers (3)

2011-11-10

Luis Abarca answers:

Maybe its sending the last post because its the last item to show and the plugin get the info from there.

You can also try this after the loop and before the "Recommend Plugin" is showed.

wp_reset_query()

If you can send me login details via PM i can have a look at your code.


alison7 comments:

Thank you. How do I send it to you. Also Jerson Baguio sent me info, but I'm unclear how to do that.


Luis Abarca comments:

I just sent you a Private Message

2011-11-10

Jerson Baguio answers:

Try this the idea is to get the latest post link and have the link as permanent to use in the recommed_a_friend_link function

<?php query_posts('showposts=1');
if ( have_posts() ) : while ( have_posts() ) : the_post();
$permalink = get_permalink( the_ID() );
endwhile;
endif;
?>

<?php echo recommend_a_friend_link( $permalink, $image_url, $text_link ); ?>


alison7 comments:

Thank you. I tried finding the link function unsuccessfully unfortunately. I searched around for this kind of language, but wasn't sure if I was in the right are. Sorry. Where would I put this?


Jerson Baguio comments:

are you using widgets?

if yest try to check with this code


<?php
/**
* Recommend A Friend widget class
*
*/
class RAF_Widget extends WP_Widget {

function RAF_Widget() {
$widget_ops = array( 'classname' => 'raf_widget raf_link', 'description' => __( 'Add a recommend a friend widget' , 'raf') );
$this->WP_Widget('recommend_a_friend', 'Recommend A Friend', $widget_ops);
}

function widget( $args, $instance ) {
extract( $args );
$title = apply_filters('widget_title', empty( $instance['title'] ) ? 'Recommend a friend' : $instance['title'], $instance, $this->id_base);
$display_type = empty( $instance['display_type'] ) ? 1 : $instance['display_type'];
$link_text = empty( $instance['link_text'] ) ? __( 'Share this page' , 'raf') : $instance['link_text'];
$image_url = empty( $instance['image_url'] ) ? '' : $instance['image_url'];
echo $before_widget;?>
<h3 class="widget-title">
<?php if ( $title ) echo $title; ?>
</h3>
<?php query_posts('showposts=1');
if ( have_posts() ) : while ( have_posts() ) : the_post();
$permalink = get_permalink( the_ID() );
endwhile;
endif;
?>

<?php

//custom image view
if ( $display_type == 2 ){
echo recommend_a_friend_link( $permalink, $image_url );
}
//text view
elseif ( $display_type == 3 ){
echo "<p>" . recommend_a_friend_link( $permalink, '', $link_text ) . "</p>";
}
//default view
else {
echo recommend_a_friend_link( $permalink, RAF_URL . 'images/share-widget-bg.png' );
}

echo $after_widget;
}

function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['display_type'] = strip_tags( $new_instance['display_type'] );
$instance['image_url'] = strip_tags( $new_instance['image_url'] );
$instance['link_text'] = strip_tags( $new_instance['link_text'] );

return $instance;
}

function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'display_type' => 1, 'link_text' => '', 'image_url' => '' ) );
$title = esc_attr( $instance['title'] );
$display_type = ( isset( $instance['display_type'] ) && !empty( $instance['display_type'] ) ) ? esc_attr( $instance['display_type'] ) : 1 ;
$image_url = ( isset( $instance['image_url'] ) && !empty( $instance['image_url'] ) ) ? esc_attr( $instance['image_url'] ) : '' ;
$link_text = ( isset( $instance['link_text'] ) && !empty( $instance['link_text'] ) ) ? esc_attr( $instance['link_text'] ) : '' ;
?>

<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title' , 'raf'); ?></label>

<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>

<label><?php _e( 'Display type' , 'raf'); ?></label><br />
<input type="radio" name="<?php echo $this->get_field_name('display_type'); ?>" value="1" class="display_default" <?php checked( $display_type, 1 ); ?> /> <label><?php _e( 'Default' , 'raf'); ?></label><br />
<input type="radio" name="<?php echo $this->get_field_name('display_type'); ?>" value="2" class="display_img" <?php checked( $display_type, 2 ); ?> /> <label><?php _e( 'Custom image' , 'raf'); ?></label><br />
<input type="radio" name="<?php echo $this->get_field_name('display_type'); ?>" value="3" class="display_text" <?php checked( $display_type, 3 ); ?> /> <label><?php _e( 'Custom text' , 'raf'); ?></label><br />
</p>

<p class="img_input">
<input type="text" name="<?php echo $this->get_field_name('image_url'); ?>" value="<?php echo $image_url; ?>" /> <label><?php _e( 'Image URL' , 'raf'); ?></label>
</p>

<p class="txt_input">
<input type="text" name="<?php echo $this->get_field_name('link_text'); ?>" value="<?php echo $link_text; ?>" /> <label><?php _e( 'Link text' , 'raf'); ?></label>
</p>

<?php
}
}

add_action( 'widgets_init', create_function('', 'return register_widget("RAF_Widget");') );
?>

2011-11-10

Duncan O'Neill answers:

Hi Alison,

your problem stems from the fact that get_permalink() will return the last permalink on the page if it's used outside the Loop;

[[LINK href="http://codex.wordpress.org/Function_Reference/get_permalink"]]get_permalink ref[[/LINK]]


To fix this, edit the file inc/functions.tpl.php within your plugin folder.

You need to edit it at line 13 ( most recent version of the plugin ), and replace this;


$permalink = get_permalink();


with this;


//$permalink = get_permalink();
$permalink = esc_url( $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] );


I'm effectively just commenting out the existing line, and adding a new line to replace it.

This will return the current page as the page being recommended.

best,