Forum Replies Created

Viewing 4 replies - 31 through 34 (of 34 total)
  • Thread Starter the1path

    (@the1path)

    Hi Andrea, thanks for the reply.

    Yeh I tried if (current_user_can('level_10')) first of all and that got the same unwanted result. But if you look at the codex here you see that they use if (current_user_can('administrator')) in the examples section, which is why I tried it: http://codex.ww.wp.xz.cn/Function_Reference/current_user_can

    Anyway nothing works so I delved into the codex and the WP DB to see if I could come up with an answer. I saw that if a user had a blog or site they had extra fields in the wp_usermeta table, one of which is the met_key: primary_blog. So I thought if I could test a user against one of these fields I can see if they are an admin to a blog?

    I went round the houses a bit but eventually got my head together (after some sleep) and looked at: Get User Meta Function

    Here is the solution that seems to be working, can you see any problems with it Andrea or perhaps a better way of performing the test?:

    <?php if ( is_user_logged_in() ){ ?>
    	<?php
    	$current_user = wp_get_current_user();
    	$user_id = $current_user->ID;
    	$key = 'primary_blog';
    	$single = true;
    	$primary_blog = get_user_meta( $user_id, $key, $single);
    	if ($primary_blog == "") {
    	?>
                        <p>Display banner</p>
              <?php } else { ?>
                    	<p>Do nothing</p>
              <?php } ?>
             <?php } ?>

    Well it seems to work as I have two blogs under super admin with different logins and test user account with no blog. The banner is only displayed for the non blogging user.

    Hope this helps somebody and Im open to better suggestions (Im no coder)

    Cheers

    Hi all this was almost what I needed but because I was working with a custom theme the “Featured Image” was not attached to a post but to a custom built “Link Widget”. Basically I lacked the ability to create a custom field for the url. So I found another solution which others might adapt, learn from or indeed find easier!

    What I did was put the url I wanted in the description area when you add a Featured Image. Just pasted it straight in there! Then I …

    Setup the arguments to use with the current post using the current post id (i used a custom variable $number) and put in an array
    $at_args = array( 'post_type' => 'attachment', 'post_parent' => $number );
    /* please not Ive used $number but you may want to use $post->ID as this was a custom function I was using */

    Use the array of arguments use the get_posts() function to get attachment ID data
    $attachment_data = get_posts( $at_args );

    You cant use the ID by default with get_posts() so we must call setup_postdata() and loop through each array item

    foreach( $attachment_data as $post ) : setup_postdata($post);
    endforeach;

    Stick the attachment ID in a variable
    $attachment_id = $attachment_data->ID;

    Use the get_post function to call in an array of post data with the corresponding ID (attachment)
    $link = get_post( $attachment_id );

    Then finally to display the damn url
    <a href="<?php echo $link->post_content; ?>">whatever</a>

    Hmmm once I right it down it doesnt look easier but may help someone!

    Thread Starter the1path

    (@the1path)

    I take it you have not found a solution to this yourself? I just dont get it!

    Ah well maybe have to do it strictly PHP and cut out the js!

    Doh yes sorry I should have said I am having the same problem here instead of starting a new topic.

    Can anyone help, other than not working in IE this plugin is very useful and time saving. If I dont find out why its bugging IE I will have to write my own solution…yawn.

    Any help much appreciato!

Viewing 4 replies - 31 through 34 (of 34 total)