Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using wp alchemy to add a custom metabox to my site with multiple image uploader option. This part is working fine, but I have no Idea how to go about outputting the image links to my template. I am hoping to output as a unordered list.

setup.php file

<?php

include_once WP_CONTENT_DIR . '/wpalchemy/MetaBox.php';
include_once WP_CONTENT_DIR . '/wpalchemy/MediaAccess.php';

// include css to help style our custom meta boxes
add_action( 'init', 'my_metabox_styles' );

function my_metabox_styles()
{
    if ( is_admin() )
    {
        wp_enqueue_style( 'wpalchemy-metabox', get_stylesheet_directory_uri() . '/metaboxes/meta.css' );
    }
}

$wpalchemy_media_access = new WPAlchemy_MediaAccess();

custom-spec.php

<?php
$custom_mb = new WPAlchemy_MetaBox(array
(
    'id' => '_custom_meta',
    'title' => 'Add images to home page slider',
    'template' => get_stylesheet_directory() . '/metaboxes/custom-meta.php',
    'include_template' => 'home.php'
));
?>

custom-meta.php

<?php global $wpalchemy_media_access; ?>
<div class="my_meta_control">

    <p><a href="#" class="dodelete-docs button">Remove All</a></p>

    <?php while($mb->have_fields_and_multi('docs')): ?>
    <?php $mb->the_group_open(); ?>

        <a href="#" class="dodelete button">Remove</a>

        <?php $mb->the_field('imgurl'); ?>
        <?php $wpalchemy_media_access->setGroupName('img-n'. $mb->get_the_index())->setInsertButtonLabel('Insert'); ?>

        <p>
            <?php echo $wpalchemy_media_access->getField(array('name' => $mb->get_the_name(), 'value' => $mb->get_the_value())); ?>
            <?php echo $wpalchemy_media_access->getButton(); ?>
        </p>

        <?php $mb->the_field('title'); ?>
        <label for="<?php $mb->the_name(); ?>">Title</label>
        <p><input type="text" id="<?php $mb->the_name(); ?>" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p>

    <?php $mb->the_group_close(); ?>
    <?php endwhile; ?>

    <p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-docs button">Add</a></p>

</div>

functions.php file

include_once 'metaboxes/setup.php';

include_once 'metaboxes/custom-spec.php';
share|improve this question
    
Did you manage to make it work ? Can you guive us the solution : ) thanks yann –  user14680 Mar 29 '12 at 11:02
add comment

1 Answer

Do you have any output code we can reference?

Put this in your Theme file:

     <img src="<?php get_the_value('imgurl'); ?>” style=”width:100px;height:100px” />

if you have multiple you'll have to go through a foreach loop:

<?php

foreach ($meta['imgurl'] as $img )
{
    echo '<a href="#" /><img src="'. $img .'" /></a>';
}
?>

Hope this helps, I don't really know this Metabox class, however I've used many and it seems like it would work this way.

Good luck!

share|improve this answer
    
This doesn't seem to work. What output code are you looking for, I'm not sure what to post. –  Anders Kitson Mar 14 '12 at 19:26
    
If you change the $meta['imgurl'] to $meta ['img-n'] do you get a different result when wrapped in your function? –  David Mar 14 '12 at 19:30
    
no luck, do you mean change the $meta['imgurl'] in the loop not the function. –  Anders Kitson Mar 14 '12 at 19:46
    
try: var_dump($custom_mb->the_value('imgurl'); & var_dump($custom_mb->the_value('img-n'); and check your Post Meta to see if it's outputting the URL inside the meta data of the post. –  David Mar 14 '12 at 20:23
    
Im sorry what you said doesn't make any sense to me, do I just place this code in my template on its own, how Do I check my Post Meta? Do you recommend a better way to create a upload button in a custom metabox –  Anders Kitson Mar 15 '12 at 18:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.