Link to the user profile
-
Hello
Is there a way to link the user ID to its profile page? I am not using buddypress but have a special page from my template
Thanks
-
You can link the username on Ads details page sing the code below
add_filter( "adverts_tpl_single_posted_by", "ads_by_author_tpl_single_posted_by", 10, 2 ); function ads_by_author_tpl_single_posted_by( $name, $post_id ) { $post = get_post( $post_id ); $person = get_post_meta($post_id, 'adverts_person', true); if( $post->post_author ) { include_once ADVERTS_PATH . "/includes/class-html.php"; $link = "http://example.com/custom/link/here/"; $person = new Adverts_Html( "a", array( "href" => $link . $glue . "posted_by=" . $post->post_author ), $person); } return sprintf( __("by <strong>%s</strong>", "adverts"), $person ); }Just replace http://example.com/custom/link/here/ with actual URL you want to link to.
Hello
Thanks for anwser but I’m not good in code: where (in what file) should I put it and at what place in the other code?
About the link: http://example.com/custom/link/here/
> the link is variable: it should be the one of the user who posted the advert. Ex: http://zooroom.org/owners/mathilde/ (list of users here: http://zooroom.org/hotes/)
> I’ve found this on internet: would it work?
https://wordpress.org/support/topic/link-to-authors-profile-page?replies=6
“><?php the_author(); ?>The complete code to link to author page should be
add_filter( "adverts_tpl_single_posted_by", "ads_by_author_tpl_single_posted_by", 10, 2 ); function ads_by_author_tpl_single_posted_by( $name, $post_id ) { $post = get_post( $post_id ); $person = get_post_meta($post_id, 'adverts_person', true); if( $post->post_author ) { include_once ADVERTS_PATH . "/includes/class-html.php"; $link = get_author_posts_url( $post->post_author ); $person = new Adverts_Html( "a", array( "href" => $link ), $person); } return sprintf( __("by <strong>%s</strong>", "adverts"), $person ); }The code itself you can add in your theme functions.php file.
Hello Greg
I’ve got a link to this url:
http://zooroom.org/author/elisabeth/
while it should be:
http://zooroom.org/owners/elisabeth/Can I change that?
Thank you
Try replacing
$link = get_author_posts_url( $post->post_author );with
$link = "http://zooroom.org/owners/" . get_user_by( "id", $post->post_author )->user_login;Hello Greg
Is there a way to put the code in WP Adverts files?
I cannot put it in my template or I lose supportThanks
If you put this code in WPAdverts files, the code will be overwritten on WPAdverts update.
Hello Greg
Yes I know but for me it’s easier
Are you planning to put this redirection adress as an option in furture versions?
Thanks
No, i am not planning to do this.
All the codes i am pasting are using filters or actions. This means you can put them inside your theme functions.php or create a new WordPress plugin and put all the codes there.
The same goes for ticket https://wordpress.org/support/topic/wordpress-login-and-backend?replies=7
Hello Greg
I’ve found on internet how to create a plugin: I though it was much complicated…
So I’ve put the code and it’s working perfect now: thanks a lot!
The topic ‘Link to the user profile’ is closed to new replies.