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've got a issue when trying to setup our app portfolio. (have a look at our portfolio page)

Whats going on: I created a custom post type with 'apps'. Every post I'm going to create is a project we worked on. In this post there might be 3 properties:

1) App store link 2) Google Play store link ---- optional: ---- 3) Intern app (no link)

Meanwhile, in our template this will be displayed:

Is there a store link?

If yes, make this image (http://www.dreamix-studio.com/images/ios_button.png) a link:

Else: Create this image (http://www.dreamix-studio.com/images/ios_inactive_button.png).

This also goes for the Google Store link.

How do I create this? And how do I create this in our template?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Ok, with the use of this 'plugin' (JareDatch). It works like a charm.

add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' ); /** * Define the metabox and field configurations. ** @param  array $meta_boxes * @return array */ function cmb_sample_metaboxes( array $meta_boxes ) {

// Start with an underscore to hide fields from custom fields list
$prefix = '_cmb_';

$meta_boxes[] = array(
    'id'         => 'appstore_link',
    'title'      => 'App Store',
    'pages'      => array( 'apps', ), // Post type
    'context'    => 'normal',
    'priority'   => 'high',
    'show_names' => true, // Show field names on the left
    'fields'     => array(
        array(
            'name' => 'App Store',
            'desc' => 'field description (optional)',
            'id'   => $prefix . 'app_store_link',
            'type' => 'text',
        ),
    )
);

// Add other metaboxes as needed

return $meta_boxes;}

add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 ); function cmb_initialize_cmb_meta_boxes() { 
if ( ! class_exists( 'cmb_Meta_Box' ) )
    require_once 'init.php';}

And use the following in your theme:

<?php if ( get_post_meta($post->ID, '_cmb_app_store_link', true) ) : ?>
                <a href="<?php echo get_post_meta($post->ID, '_cmb_app_store_link', true) ?>">
                    <img src="source.png" src="<?php echo get_post_meta($post->ID, '_cmb_app_store_link', true) ?>" alt="<?php the_title(); ?>" />
                </a>
share|improve this answer
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.