WordPress.org

Forums

[resolved] User Submitted Posts Plugin (41 posts)

  1. breakuppedia
    Member
    Posted 2 years ago #

    Hello Im using the User Submitted Posts plugin to all users to post to the front page.

    I use the code below in my content.php to get the pictures to appear too. Its all find when the users submit a photo.

    Problem is when the users don't add a photo, there is a dead link that appears.(you can see this happening here: http://www.breakuppedia.com) Do help me if you can.

    Thank you so much!

    <?php global $wpdb;
    $query = "SELECT ID, guid FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '{$post->ID}'";
    $adimages = $wpdb->get_results($wpdb->prepare($query), OBJECT);
    // To display the first image.. ?>

    <img style="float: left; height: 380px;border: 2px solid #464646;" src="<?php if(is_public_submission()){echo $adimages[0]->guid;} ?>" />

  2. deepbevel
    Member
    Posted 2 years ago #

    I think it may just be getting the border,

    border: 2px solid #464646

    if you can do without it try removing it.

    if you need it, you may try adding it in your style.css with the appropriate body class, that way it doesn't get called untill there's an image.

  3. breakuppedia
    Member
    Posted 2 years ago #

    thanks for your help deepbevel.

    I removed border: 2px solid #464646

    but the dead link is still there. Just without a border. :(

  4. deepbevel
    Member
    Posted 2 years ago #

    you probably need to mod your code with a condition added to "if is public submisission-echo addimages", it may need to be followed by an "else return" or something. I'm not sure how to write it though, I'd have to mess with it.

  5. deepbevel
    Member
    Posted 2 years ago #

    It looks different in firefox, not sure but I think it looks how it should.

  6. breakuppedia
    Member
    Posted 2 years ago #

    yeah man!!
    damn. There's no deadlink in firefox!

  7. breakuppedia
    Member
    Posted 2 years ago #

    haha, Any solutions to make the site load like it does on firefox?

  8. deepbevel
    Member
    Posted 2 years ago #

    that I have no experience with, and no clue. You'd probably have to know what it is that ie is not doing right.. might be easier to mod the condition so nothing renders if no image.

    if_is_public_submission (and if an image exitsts!) bla bla bla

  9. deepbevel
    Member
    Posted 2 years ago #

    this might provide a clue, they are talking about if-no-image conditionals.

    http://wordpress.org/support/topic/displaying-standard-imagecustom-field-image-if-no-image-excists?replies=7

  10. deepbevel
    Member
    Posted 2 years ago #

    I'd try something like this, but of course it's not tested and I'd be shocked if it worked as is.

    <?php global $wpdb;
     $query = "SELECT ID, guid FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '{$post->ID}'";
    
    if ($attachments) {
    
     $adimages = $wpdb->get_results($wpdb->prepare($query), OBJECT);
     // To display the first image.. ?>
    
    <img style="float: left; height: 380px;border: 2px solid #464646;" src="<?php if(is_public_submission()){echo $adimages[0]->guid;} ?>" />
    <?php }
    ?>
  11. breakuppedia
    Member
    Posted 2 years ago #

    Unfortunately, the images don't appear at all.
    hmmm

  12. deepbevel
    Member
    Posted 2 years ago #

    do my eyes deceive me..? is it fixed? no way my code worked, no way.

  13. deepbevel
    Member
    Posted 2 years ago #

    hmmmm, maybe need to get the post id in the condtional?

    if ($attachments) {
    
    if (post_parent = '{$post->ID}'){
    
    bla bla bla
    
    <?php } }?>

    but again, I realy doubt i'm writing it correctly. It would be great if coder would jump in here right about now.

  14. breakuppedia
    Member
    Posted 2 years ago #

    ha no. I don't think its working.
    It just stopped displaying all images.

    even the posts that have images aren't displaying.

  15. deepbevel
    Member
    Posted 2 years ago #

    I'm just happy it didn't brake your page, at least my syntax must be right. maybe try it with the id. Could be it's needed to get the images that do exist.

  16. breakuppedia
    Member
    Posted 2 years ago #

    haha now the whole site's not loading.
    only the header's left.
    This is the current code i have on

    <?php global $wpdb;
         $query = "SELECT 'ID', 'guid' FROM '$wpdb->posts' WHERE 'post_type' = 'attachment' AND post_parent = '{$post->ID}'";
    
    if ($attachments) {
    if (post_parent = '{$post->ID}'){
     $adimages = $wpdb->get_results($wpdb->prepare($query), OBJECT);
     // To display the first image.. ?>
    
    <img style="float: left; height: 380px;border: 2px solid #464646;" src="<?php if(is_public_submission()){echo $adimages[0]->guid;} ?>" />
    <?php }
    ?>
  17. deepbevel
    Member
    Posted 2 years ago #

    If all else fails, consider using default code in your template content area that aligns the images how you want. Seems a [gallery] could do it.

    But, the template you use for that would render all post images as galleries automatically, so you would only use that template for user submitted posts.

  18. breakuppedia
    Member
    Posted 2 years ago #

    Is it possible to use the default code.

    And then add an additional code that will null the default code if there are no attachments?

    Sorry if this is a dumb statement. Im really new at this :)

  19. deepbevel
    Member
    Posted 2 years ago #

    that's what I've been playing with, but with no luck. i just don't know how to tell wp to show an image, only if one exists. I've done it before but the context was different. I'm not great with this either. I help out partly to learn.

    <?php echo do_shortcode('[gallery]'); ?>

    you could try that in your content area, instead of the code you are using

  20. breakuppedia
    Member
    Posted 2 years ago #

    Damn!
    It's working!
    I think.
    but its kinda turned all the images into thumbnails.

    Should I just add:

    <img style="float: left; height: 380px;border: 2px solid #464646;" />
  21. deepbevel
    Member
    Posted 2 years ago #

    hey wait, in the last code you posted you don't have

    <?php } }?>

    instead you have

    <?php } ?>

    fix it and try again.

    or keep working with the gallery code. the choice is yours

  22. breakuppedia
    Member
    Posted 2 years ago #

    Thanks for helping anyways deepbevel!

  23. deepbevel
    Member
    Posted 2 years ago #

    If you stay with the gallery method you can change the thumbnail size in image settings.

  24. deepbevel
    Member
    Posted 2 years ago #

  25. breakuppedia
    Member
    Posted 2 years ago #

    You mean like this?

    <?php echo do_shortcode('[gallery]'); }}?>

    The site went blank again, with only the header left

  26. deepbevel
    Member
    Posted 2 years ago #

    no, I was talkiing about the original code,

    <?php global $wpdb;
         $query = "SELECT 'ID', 'guid' FROM '$wpdb->posts' WHERE 'post_type' = 'attachment' AND post_parent = '{$post->ID}'";
    
    if ($attachments) {
    if (post_parent = '{$post->ID}'){
     $adimages = $wpdb->get_results($wpdb->prepare($query), OBJECT);
     // To display the first image.. ?>
    
    <img style="float: left; height: 380px;border: 2px solid #464646;" src="<?php if(is_public_submission()){echo $adimages[0]->guid;} ?>" />
    <?php }
    ?>

    if you still want to go that route.

  27. breakuppedia
    Member
    Posted 2 years ago #

    Damn!
    u're good!!

  28. deepbevel
    Member
    Posted 2 years ago #

    change
    <?php }?>
    to
    <?php }}?>

  29. breakuppedia
    Member
    Posted 2 years ago #

    This is currently working for me

    <?php echo do_shortcode('[gallery size= large]'); ?>

    but just for us to learn. I'll try the old one with your fixes.

  30. deepbevel
    Member
    Posted 2 years ago #

    I'm lucky, sometimes.

Topic Closed

This topic has been closed to new replies.

About this Topic