• Resolved rajaito

    (@rajaito)


    Word Press Version 3.0
    Cimy Extra Fields Version 2.0.4
    Executable PHP widget Version 2.1

    Hello, this is my first time building a php script and I am stoked I have figured it out this far. However, I am trying to go a little further with it. I am sure this is easy for some of you php gurus out there.

    Below you will see the code I am displaying in an Executable PHP widget. While I am not sure it is precise as it could be, it does seem work. The only problem is I would have to make a separate widget for each author on my site.

    GOAL: To display this widget on specific posts/pages but have it only call the author of the page it is shown on.

    QUESTION: Instead of specifying the user id, How can I better write this script so that it uses the post/pages author of the page it is shown on?

    <?php
    	$user_ID = 2;
    	$ws = get_cimyFieldValue( $user_ID , WEBSITE1);
    	$fb = get_cimyFieldValue( $user_ID , FACEBOOK);
    	$ms = get_cimyFieldValue( $user_ID , MYSPACE);
    	$tt = get_cimyFieldValue( $user_ID , TWITTER);
    	$sc = get_cimyFieldValue( $user_ID , SOUNDCLOUD);
    	?>
    
    <h3><a href="<?php echo $ws; ?>" target="_blank"><?php the_author() ?>'s Website</a></h3>
    <h3><a href="<?php echo $fb; ?>" target="_blank"><?php the_author() ?>'s Facebook</a></h3>
    <h3><a href="<?php echo $ms; ?>" target="_blank"><?php the_author() ?>'s Myspace</a></h3>
    <h3><a href="<?php echo $tt; ?>" target="_blank"><?php the_author() ?>'s Twitter</a></h3>
    <h3><a href="<?php echo $sc; ?>" target="_blank"><?php the_author() ?>'s Soundcloud</a></h3>
Viewing 6 replies - 1 through 6 (of 6 total)
  • add these lines at the top.

    global $post;
    $user_ID = $post->post_author;

    Hope this helps.

    Thread Starter rajaito

    (@rajaito)

    Thanks for the response. I replaced

    $user_ID = 2;

    with:

    global $post;
    $user_ID = $post->post_author;

    and got this error:
    Parse error: syntax error, unexpected '&'

    use print_r($post); to check if $post is in the scope.

    Thread Starter rajaito

    (@rajaito)

    Thanks, I am not exactly sure how to do that or what this means.

    I tried adding this to the widget and nothing was displayed:
    <?php print_r($post); ?>

    Did I do that correctly?

    Thread Starter rajaito

    (@rajaito)

    .

    Thread Starter rajaito

    (@rajaito)

    I actually gave up on tying to use cimy fields for this purpose because I found it much easier and actually successful using custom fields on the write edit page (which I made with the more fields plugin). I was then able to call the fields from a Executable PHP sidebar widget using this code:

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $aw = get_post_meta($postid, 'artist_website', true);
    wp_reset_query();
    ?>
    
    <h3><a href="<?php echo $aw; ?>" target="_blank">* Website</a></h3>
    
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $fb = get_post_meta($postid, 'artist_facebook', true);
    wp_reset_query();
    ?>
    
    <h3><a href="<?php echo $fb; ?>" target="_blank">* Facebook</a></h3>
    
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $ms = get_post_meta($postid, 'artist_myspace', true);
    wp_reset_query();
    ?>
    
    <h3><a href="<?php echo $ms; ?>" target="_blank">* Myspace</a></h3>
    
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $tt = get_post_meta($postid, 'artist_twitter', true);
    wp_reset_query();
    ?>
    
    <h3><a href="<?php echo $tt; ?>" target="_blank">* Twitter</a></h3>
    
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $sc = get_post_meta($postid, 'artist_myspace', true);
    wp_reset_query();
    ?>
    
    <h3><a href="<?php echo $sc; ?>" target="_blank">* Soundcloud</a></h3>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘calling cimy extra fields in php widget – post author instead of user ID?’ is closed to new replies.