WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] link to a file a root of wordpress installation and custom fields

[Resolved] link to a file a root of wordpress installation and custom fields

  • 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

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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?

    Moderator keesiemeijer

    @keesiemeijer

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

    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..

    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?

    Moderator Jose Castaneda

    @jcastaneda

    THEME COFFEE MONKEY

    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.

    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.

    resolved now….

    shown working

    simple thing… the jpg tags were in uppercase.

    yaaaaa

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] link to a file a root of wordpress installation and custom fields’ is closed to new replies.
Skip to toolbar