👍 Научим бесплатно правильно создавать сайты на WordPress. Подробнее →
Как сделать автоматическое добавление ника в ссылку?
Я использую плагин «Theme My Login» надо чтобы в сайдбаре была ссылка «Ваш профиль». Когда на нее нажмет пользователь, требуеться чтобы он попал «www.адрес.ру/author/ник-автора» как сделать чтобы «ник-автора» добавлялся автоматически.

Не понятно, куда вы хотите попасть при нажатии ссылки, в профиль или на страницу с постами, опубликованными автором. адрес.ру/author/ник-автора ведет на страницу с постами, в профиль ведет ссылка адрес.р/wp-admin/profile.php
На страницу с постами, ну это не суть)
<?php global $user_ID, $user_identity;get_currentuserinfo();$ruri = $_SERVER[‘REQUEST_URI’];if (!$user_ID): ?>
<?php global $current_user; get_currentuserinfo(); echo ‘
<div style="display:inline-block;border:#aaa 1px solid;box-shadow: 0 0 5px #ccc;">’ . get_avatar( $current_user->user_email, 24 ) . ‘</div>
‘;?>
<div style="display:inline-block;line-height:1em;color:#ccc;font-size:12px">
<a class="autor" href="<?php echo get_settings(‘siteurl’) . ‘/wp-login.php?redirect_to=’ . $ruri; ? rel="nofollow">" title="Залогиниться" style="font-style:normal;margin-left:5px;font-size:12px">войти</a>
</div>
<?php else:?>
<?php global $current_user; get_currentuserinfo(); echo ‘
<div style="display:inline-block;border:#aaa 1px solid;box-shadow: 0 0 5px #ccc;">’ . get_avatar( $current_user->user_email, 24 ) . ‘</div>
‘;?>
<div style="display:inline-block;margin:0 5px 0 5px;font-size:12px">
<a style="font-style:normal;font-weight:bold;" href="/wp-admin/profile.php" title="ваш аккаунт" rel="nofollow"><?php echo $user_identity; ?></a>
<span style="color:#ccc"><?php global $current_user; get_currentuserinfo(); echo ‘<a title="ваши записи" href="/author/’ . $current_user- rel="nofollow">user_login . ‘">ваше</a>’;?>
</span>
</div>
<?php endif;?>
Так можно получить username
<?php global $current_user;
get_currentuserinfo();
echo ‘Username: ‘ . $current_user->user_login . "\n";
echo ‘User email: ‘ . $current_user->user_email . "\n";
echo ‘User first name: ‘ . $current_user->user_firstname . "\n";
echo ‘User last name: ‘ . $current_user->user_lastname . "\n";
echo ‘User display name: ‘ . $current_user->display_name . "\n";
echo ‘User ID: ‘ . $current_user->ID . "\n";
?>
http://codex.wordpress.org/Function_Reference/get_currentuserinfo
В этом блоге ссылки на профиль и страницу с постами автора сделаны так:
[img]https://n-wp.ru/wp-content/uploads/2011/06/tiaurus-2011-06-24_110032.png[/img]
код:
<?php global $user_ID, $user_identity;get_currentuserinfo();$ruri = $_SERVER[‘REQUEST_URI’];if (!$user_ID): ?>
<?php global $current_user; get_currentuserinfo(); echo ‘<div style="display:inline-block;border:#aaa 1px solid;box-shadow: 0 0 5px #ccc;">’ . get_avatar( $current_user->user_email, 24 ) . ‘</div>’;?>
<div style="display:inline-block;line-height:1em;color:#ccc;font-size:12px">
<a class="autor" href="<?php echo get_settings(‘siteurl’) . ‘/wp-login.php?redirect_to=’ . $ruri; ? rel="nofollow">" title="Залогиниться" style="font-style:normal;margin-left:5px;font-size:12px">войти</a> | <a rel="nofollow" href="/rules#rules02" rel="nofollow">зачем?</a>
</div>
<?php else:?>
<?php global $current_user; get_currentuserinfo(); echo ‘<div style="display:inline-block;border:#aaa 1px solid;box-shadow: 0 0 5px #ccc;">’ . get_avatar( $current_user->user_email, 24 ) . ‘</div>’;?>
<div style="display:inline-block;margin:0 5px 0 5px;font-size:12px">
<a style="font-style:normal;font-weight:bold;" href="/wp-admin/profile.php" title="ваш аккаунт" rel="nofollow"><?php echo $user_identity; ?></a></br>
<span style="color:#ccc"><?php global $current_user; get_currentuserinfo(); echo ‘<a title="ваши записи" href="/author/’ . $current_user- rel="nofollow">user_login . ‘">ваше</a>’;?> | <a title="выбранные записи" href="/favorite/" rel="nofollow">выбранное</a>
</span>
</div>
<?php endif;?>
tiaurus, попробуйте потестировать вставку кода, от пользователя без административных прав. Вроде всё делаю правильно, но не хочет вставлять ни в какую.
Да, действительно некоторый код вставляется обрезанным. Спасибо, буду разбираться.
Кажется я устранил эту проблему.
Спасибо вам, буду побывать.
Не получается.
Если вставить так:
то:
А вот это:
хорошо работает, спасибо.
Странно, вроде в коммент вставил полностью…
Получилось?
Если вы про вставку ссылки, то нет(
Ага, понятно — rel=»nofollow» в код вставляется. Попробуйте удалить rel=»nofollow» из кода.
Не выходит, тупо вот это штука вылезает:
Выложите полный работающий код прифиля пожалуйста а то
Замучало уже
если парсер съест код:
http://onedayfiles.com/mTN7XC/
ахах) появился откуда-то rel=»nofollow» не любит меня парер…
Спасибо!))
<a href="/author/<?php global $current_user; get_currentuserinfo(); echo $current_user->user_login; ?>">your </a>
А если более полно, то вот так:
<?php global $user_ID, $user_identity;get_currentuserinfo();$ruri = $_SERVER[‘REQUEST_URI’];if (!$user_ID): ?>
<?php global $current_user; get_currentuserinfo(); echo ‘<div>’ . get_avatar( $current_user->user_email, 24 ) . ‘</div>’;?>
<div><a href="<?php echo get_settings(‘siteurl’) . ‘/wp-login.php?redirect_to=’ . $ruri; ? >">login</a></div>
<?php else:?>
<?php global $current_user; get_currentuserinfo(); echo ‘<div>’ . get_avatar( $current_user->user_email, 24 ) . ‘</div>’;?>
<div>
<a href="/wp-admin/profile.php"><?php echo $user_identity; ?></a>
<?php global $current_user; get_currentuserinfo(); echo ‘<a href="/author/’ . $current_user->user_login . ‘">your</a>’;?>
</div>
<?php endif;?>
Охохо)) работает спасибо!