PDA

View Full Version : New titlebar button?


ronincyberpunk
February 20th, 2006, 06:50
I'd really like to add a button next to the "Site Admin" button on the top tab which checked to see if I was logged in and let me go directly to the post creation page in Wordpress. Is this possible? I see that the Site Admin link is done via the built in wp_register tag so I'd have to probably write my own extension or find some way to test if the person is logged in and has permission to write, then show the link...

ShahabJafri
February 21st, 2006, 04:59
For that, You'll need to edit header.php of K2.
Open header.php and find

<ul class="menu">
...
</ul>
This the top navigation bar. If you would like to have a Register link adjacent to Login / Site Admin link, (Like what I've done (www.shahabjafri.com) ), You can put this code :


<li class="page_item"><?php wp_register('', ''); ?></li>
<li class="page_item"><?php wp_loginout(); ?></li>

JohnW.
February 21st, 2006, 05:42
It's possible but it isn't pretty. First you'll need to open k2/functions.php and add this function.

function wp_postlinkheader( $before = '<li>', $after = '</li>' ) {
global $user_ID;

get_currentuserinfo();

if ( '' == $user_ID && get_settings('users_can_register') )
$link = '';
elseif ( '' == $user_ID && !get_settings('users_can_register') )
$link = '';
else
$link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/post.php">' . __('Post') . '</a>' . $after;

echo apply_filters('register', $link);
}

Then you'll need to open header.php and add this code.
<?php wp_postlinkheader('<li class="newpost">','</li>'); ?>
right above this
<?php wp_register('<li class="admintab">','</li>'); ?>

And to move it over near the admin tab you can add this to your css.
.newpost {
position: relative;
left: 200px;
}

I tested it and it works great, hopefully it does for you too.

ronincyberpunk
February 21st, 2006, 02:42
Thanks JohnW! That works brilliantly! :)

ronincyberpunk
February 21st, 2006, 02:55
3 things to note:

Since this is an actual hack, I put the new function in its own php block at the end of the functions.php and marked it out so I could easily spot it for any future upgrades. I also gave attribution to John so in the future when I go "Damn that's a cool toy" I can be reminded that John's the man.

Also, in my version I changed the function from just having the button say "Post" to having it say "New Post."

I also made a change to the CSS. I use the fixed width layout and so the "left: 200px" wasn't far enough over for me, I wanted it closer to the right. So I twiddled it some and found that I was happiest when I changed the css to be:
.newpost {
position: relative;
left: 225px;
}