Jump to content

Recommended Posts

 

Hello,

 

I need a little help, I would greatly appreciate if someone helped me with this.

 

I have 3 functions, and I want to make them work the following way:

 

 

Function 1:

This function gives me a list of users who liked a blog post. It gives me an HTML list. I want a formula which filters the output giving me ONLY the first value of the list. Or only the second value. Or only the third value.

 

the_users_who_favorited_post($post_id = null, $site_id = null, $separator = 'list', $include_anonymous = true, $anonymous_label = 'Anonymous Users', $anonymous_label_single = 'Anonymous User');

 

Example of output:

John

Albert

Mary

 

I want to filter the list and obtain only the first value:

John.

 

Or obtain only the second:

Albert

 

 

 

Function 2:

This function gives me the ID of the user. And I need to bring the value from the Function 1 and insert in this functon 2:

 

<?php

$user = get_userdatabylogin('value from function 1 here');

if($user){

echo $user->ID;

}

?>

 

 

The output from function 1 goes "value from function 1 here". And it will give me the ID.

 

 

Function 3:

 

This code will give me the user avatar, from the ID i obtain from function 2.

 

<?php echo get_avatar( ID goes here , '100' ); ?>

 

 

 

The output from function 2 goes "ID goes here". And it will give me the profile avatar picture.

 

 

 

I need to join these formulas together, and make them work.

 

Does anyone know how to do this?

 

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/301491-php-coding-help/
Share on other sites

I agree with ginerjm, you should edit your post to include some punctuation, grammar and put your code in the proper code tags and explaining a little more on the issue..

 

 

From what i've been able to understand from your question, you are after the following

  • A formula/way to list users who have liked a blog post.

Doing this depends on how the data is stored, you would need to have an database query to get users who haved like a post (refer below)

 "SELECT * FROM blog_likes WHERE blog_id = 1"

Replacing the blog_id with the specific blog_id, your function you supplied dictates that you can specify a post id, site id, seperator and anonymous.. To get those, you would need to add more to your select statement. I suggest you have a quick readover the mySQL documentation http://dev.mysql.com/doc/refman/5.7/en/select.html

 

 

With your second function, it seems you are asking for the id of each user who has liked the blog post, to get that, you could do the following:

foreach($the_users_who_favorited_post as $key=>$value){
    $user = get_userdatabylogin($value->fk_user_id);
    if($user) 
        echo $user->ID;
}

The above snippet would loop through your users list and get the user object and print the user id.

 

Your last function, which seems to be asking on how to get the avatar, you would use the same thing as above but adding in the get_avatar function...

foreach($the_users_who_favorited_post as $key=>$value){
    $user = get_userdatabylogin($value->fk_user_id);
    if($user){
       $user->user_avatar = get_avatar($user->ID,'100');
    }
}

The above will set an index in the user object called "user_avatar" to contain the data returned from "get_avatar" using the users id you got from the user object...

 

 

 

I hope this has helped.

 

:)

Link to comment
https://forums.phpfreaks.com/topic/301491-php-coding-help/#findComment-1534585
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.