• Resolved etespey

    (@etespey)


    I’ve tried getting a metaslider to display on just my home page using custom fields called from my functions.php file and it’s just creating a big blank spot below the header (the div tags for the metaslider don’t show up in the code). This functions was actually used for a slidedeck-I just tweaked the code for metaslider(not using slidedeck for this project). The problem seems to have something to do with the variable declared in the function. When I comment out $metaslider_id the div tags show up in the code. What am I overlooking?

    Here’s the code:

    function slidedeck_insert() {
            $metaslider_id = getCustomFieldValue('metaslider_id', '');
            if( !empty($slidedeck_id) ) {
                ?>
            <div id="slidedeck_wrapper"><div id="slidedeck"> <?php echo do_shortcode( "[metaslider id=" . $metaslider_id . "]" ); ?> </div></div>
            <?php
            }
    }
    add_action('thematic_belowheader','slidedeck_insert');
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thanks for providing this code. Since it is what I based the revised code on, I wanted to post the updated working version for anyone who might be looking for something like this. Here it is:

    //Allows the meta-slider to be selected by adding the ID in a custom field<br />
    function metaslider_insert() {
            $meta_slider_select = get_post_meta(get_the_ID(), 'meta_slider_select', 'true');
            if( !empty($meta_slider_select) ) {
                ?>
            <div id="metaslider_wrapper"><div id="metaslider"> <?php echo do_shortcode( "[metaslider id=" . $meta_slider_select . "]" ); ?> </div></div>
            <?php
            } else{
              echo "<div class=\"title\">";
             echo "<h1>" . get_the_title($ID) . "</h1>";
             echo "</div>";
            }
    }
    ?>

    That function goes in the functions.php file of whatever theme you are using. Then you just place this little snippet in your theme page wherever the slider is supposed to appear:

    <?php
            metaslider_insert();
            ?>

    This is based on creating a custom field called “meta_slider_select” where you would just place the ID number of the meta slider that you are using.

    If you don’t want to have the else statement that displays the title, then just use this…

    function metaslider_insert() {
            if( !empty($meta_slider_select) ) {
                ?>
            <div id="metaslider_wrapper"><div id="metaslider"> <?php echo do_shortcode( "[metaslider id=" . $meta_slider_select . "]" ); ?> </div></div>
            <?php
            }
    ?>

    is there also a way to get a custom field to pick the gallery? like a list of all galleries which you can choose and then replys the id?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Metasliders using Custom Fields’ is closed to new replies.