Forum Replies Created

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • in reply to: Image upload / preview? #5757
    pwwwpwww
    Member

    if you look at the code that constructs the file upload meta box (\parts\fields\file.php), you find this at the top of it:

    <?php
      $options = array_merge(
                  array(
                    'button' =>'Add Media'
                    ,'modal_title' =>'Add Media'
                    ,'basic' => false
                    ,'preview_size' => 'thumbnail'
                    ,'textarea_rows' => 5
                    ,'save' => 'id'
                  )
                  ,isset($options) && is_array($options) ? $options : array()
                );
    ?>

    So I’m guessing you can do this:

    `piklist(‘field’, array(
    ‘type’ => ‘file’
    ,’field’ => ‘upload_basic’
    ,’scope’ => ‘post_meta’
    ,’label’ => __(‘Add File(s)’,’piklist’)
    ,’description’ => __(‘This is the basic upload field.’,’piklist’)
    ,’options’ => array(
    ‘preview_size’ => ‘thumbnail’ //change this i.e ‘medium’, ‘large’, ‘full’ etc
    )
    ));`

    Not tested, so let me know if it works

    pwwwpwww
    Member

    I think I figured it out. It’s a bit rough, but seems to handle the above example:

    $pwww_builder = get_post_meta( get_the_ID(), 'module_group', true ); 
    
    foreach ( $pwww_builder as $pwww_build ) {
    
        // Print out the first module type
        echo '<p>' . $pwww_build['module_editor'] . '</p>';
            
            //The next module is an add-more field - lets dig a bit deeper
            $pwww_buildtitle = $pwww_build['module_title']; 
        
                foreach ( $pwww_buildtitle as $pwww_title) { 
                    
                    // Print out the second module type
                    echo '<h2>' . $pwww_title . '</h2>';
                    }                                                  
    }

    I’ll have a go at creating my own page builder in the next day or two – I can think of at least 8-10 modules that would be useful for building those one-off landing pages that are normally a time drain. If you can leave this thread open for a few days, I’m sure I’ll be back with more questions / amateur code gibberish. I suspect my copypasta will fail miserably one I try and do fancier things.

    pwwwpwww
    Member

    Cheers Steve – just nested arrays to figure out now! You can go ahead and mark this as resolved (I’m sure I’ll fire-up another thread soon enough…)

    pwwwpwww
    Member

    Well, I’ve just about managed to get it working. My code needs cleaning up, but it’s a start:

    global $post;
    $post_objects = get_post_meta($post->ID, 'attach_blocks');
    
    if( $post_objects ): ?>
        
        <?php foreach( $post_objects as $post): // variable must be called $post ?>
            <?php 
            setup_postdata($post);
            $blockstyle = get_post_meta($post, 'block_style', true);
            $blockimg = get_post_meta($post, 'content_block_img', true);
            ?>
            
            <section>
                <div class="<?php echo $blockstyle; ?>">
                <h3><?php the_title(); ?></h3>
                <div><?php echo '<img src="' . wp_get_attachment_url($blockimg) . '" alt="" />';?></div>
                <?php the_content(); ?>
                </div>
            </section>
        <?php endforeach; ?>
        
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>
    pwwwpwww
    Member
    This reply has been marked as private.
    pwwwpwww
    Member
    This reply has been marked as private.
    pwwwpwww
    Member

    Well, after almost a day googling I’m still none the wiser.

    And to add to my failure, I tried replicating the advanced add-more example in the docs without success. Considering I was just copying and pasting the example code, adjusted only for the template file paths, I have no idea why it wouldn’t work – only the days would print and not the workout schedule (reps, sets etc). I won’t even mention what happened when I tried outputting the Page Modules addmore demo in my theme 🙁

    On that note, I think I’ll have to return to ACF. I appreciate it doesn’t store data very well, but the learning curve for non-devs feels less steep. Plus there’s plenty of example code floating around the web for pretty much everything I need to do.

    Either way, thanks for trying to help. Maybe when I get my head around PHP I’ll give your plugin another go.

    pwwwpwww
    Member

    Hmm, not sure that’ll work for what I’m trying to achieve. Your code example just pulls in the first entry of my attach_blocks field. I need to somehow loop through the attach_blocks data, i.e the list of content_blocks associated with the page, and then display their contents (title, post_content, block_img). Does this make sense?

    pwwwpwww
    Member

    Thanks for the reply Steve. As it turns out, the code I used above works just fine in the sidebar – no WP_Query or other wizardry needed. Not sure why it wouldn’t work the first 6 times I tried 🙂

Viewing 9 posts - 1 through 9 (of 9 total)