WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] link to a file a root of wordpress installation and custom fields (9 posts)

  1. deadmeat30
    Member
    Posted 2 years ago #

    Hey everyone,

    Just wondering if someone could help me out with some code.

    Im looking to retrieve a file from a folder dynamically

    what ild like to do, is to find *wordpress root*/wp-content/gallery/

    then in my link, use

    <img src="*wordpress root*/wp-content/gallery/*custom field to find this folder named the same as custom field*/1.JPG" />
    <img src="*wordpress root*/wp-content/gallery/*custom field to find this folder named the same as custom field*/2.JPG" />
    <img src="*wordpress root*/wp-content/gallery/*custom field to find this folder named the same as custom field*/3.JPG" />

    So on the post in wordpress, ill add the custom field, say 'summer' and the it'll gather those images from the file 'summer' and display them on that post, then if the next post, i have 'winter', it'll goto winter, and so on and so on.

    Im not fussy about uploading the files through wordpress, as there will be mutiiple ones.

    all the images in the folder will be called 1,2,3,4,5 and so on.

    thanks,

    Alan

  2. deadmeat30
    Member
    Posted 2 years ago #

    ok i gave

    <img src="<?php echo site_url(); ?>/wp-content/gallery/<?php echo get_post_meta($post->ID, 'file', true); ?>/01.JPG" />

    a go, but it wont display my picture. Ive right clicked on the broken link, and it takes me to the right folder, it works fine locally on my computer, but not on the server. Any ideas why the images wont show up?

  3. keesiemeijer
    moderator
    Posted 2 years ago #

    Try echo home_url(); instead of echo site_url();

  4. deepbevel
    Member
    Posted 2 years ago #

    I don't remmeber why I used this directory (wp-includes) but it worked like this for me in my category.php to get an image dynamically based on a condtional:

    if (is_category('news')) { ?>
    	<h2 class="cat-title">
    <img 
    
    src="http://foursticks.net/harborsmu
    
    sic/wp-includes/images/news.jpg">
    </h2>

    Might be worth a try..

  5. deadmeat30
    Member
    Posted 2 years ago #

    no luck,

    heres the link

    just click the post, and it'll come up, the img is showing the correct path when i view its URL. what else is wrong?

  6. Jose Castaneda
    Member
    Posted 2 years ago #

    Let me get this straight: You are trying to create a post with images? If that's the case then why not use a simple plugin? Or better yet create individual posts for each. If not, can you elaborate as to what you are trying to achieve? Apologies if it may come of wrong sounding.

  7. deepbevel
    Member
    Posted 2 years ago #

    unfortunately I'm not at all experienced with custom fields, hope I'm not wasting your time with this but I thought I'd take a stab at it using another method:

    So on the post in wordpress, ill add the custom field, say 'summer' and the it'll gather those images from the file 'summer' and display them on that post, then if the next post, i have 'winter', it'll goto winter, and so on and so on.

    <?php
    $field = get_post_meta($post->ID, 'summer', true);
    if($field) { ?>
    <img src="some/path/to/summer-images/<?php echo $field; ?>1.jpg" border="0" alt="" />
    <?php }
    ?>

    although I may be missing part of the goal, since you have your filtering happening in the link code, possibly for a good reason.

  8. deadmeat30
    Member
    Posted 2 years ago #

    resolved now....

    shown working

    simple thing... the jpg tags were in uppercase.

  9. deepbevel
    Member
    Posted 2 years ago #

    yaaaaa

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.