SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Perth W.A.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Conditional include

    Hi,
    I wish to conditionally include some html in a template file which runs a slider.
    The html in question displays 3 linked image boxes and I want to have these boxes display only on one or more selected pages.

    PS I understand the rule about editing only in a child theme, however I couldn't get this method to work.

    html code I wish to include:
    HTML Code:
        <div id="feature_pics_section">
                                       <div id="image_box1"><a href="http://vnrstone.webdesignperth.com.au/?p=1" title="Ledgestone Collection"></a></div>
                                       <div id="image_box2"><a href="http://vnrstone.webdesignperth.com.au/?page_id=1149" title="Arctic Stone Collection"></a></div>
                                       <div id="image_box3"><a href="http://vnrstone.webdesignperth.com.au/?p=1" title="Dressed Edge Collection"></a></div>
                              </div>
    slider-lite.php:

    PHP Code:
    <?php
    /**
     * Title: Slider Lite Element
     *
     * Description: Slides three images having optional custom links
     *
     * Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
     * should be made in a child theme.
     *
     * @category Cyber Chimps Framework
     * @package  Framework
     * @since    1.0
     * @author   CyberChimps
     * @license  http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
     * @link     http://www.cyberchimps.com/
     */

    // Don't load directly
    if ( !defined('ABSPATH') ) { die('-1'); }

    // Action for Slider Lite
    add_action ('slider_lite''cyberchimps_slider_lite_content' );

    function 
    cyberchimps_slider_lite_content() {
        global 
    $wp_query$post;
        
        
    // Set directory uri
        
    $directory_uri get_template_directory_uri();
        
    $slide = array();
        
    $link = array();
            
        if (
    is_page()) {
            
    $slides[0]['img'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_one_image' true);
            
    $slides[1]['img'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_two_image' true);
            
    $slides[2]['img'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_three_image' true);
            
    $slides[3]['img'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_four_image' true);
            
    $slides[4]['img'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_five_image' true);


        
            
    $slides[0]['link'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_one_url' true);
            
    $slides[1]['link'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_two_url' true);
            
    $slides[2]['link'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_three_url' true);
            
    $slides[3]['link'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_four_url' true);
            
    $slides[4]['link'] = get_post_meta($post->ID'cyberchimps_slider_lite_slide_five_url' true);


        }
        
        else {
            
            
    $slides[0]['img'] = cyberchimps_get_option'image_one_slide'$directory_uri apply_filters'cyberchimps_slider_lite_img1' ,'/images/branding/slide1.jpg' ) );
            
    $slides[1]['img'] = cyberchimps_get_option'image_two_slide'$directory_uri .  apply_filters'cyberchimps_slider_lite_img2' ,'/elements/lib/images/slider/slide1.jpg' ) );
            
    $slides[2]['img'] = cyberchimps_get_option'image_three_slide'$directory_uri .  apply_filters'cyberchimps_slider_lite_img3' ,'/elements/lib/images/slider/slide1.jpg' ) );
            
    $slides[3]['img'] = cyberchimps_get_option'image_four_slide'$directory_uri .  apply_filters'cyberchimps_slider_lite_img4' ,'/elements/lib/images/slider/slide1.jpg' ) );
            
    $slides[4]['img'] = cyberchimps_get_option'image_five_slide'$directory_uri .  apply_filters'cyberchimps_slider_lite_img5' ,'/elements/lib/images/slider/slide1.jpg' ) );
        
            
    $slides[0]['link'] = cyberchimps_get_option'image_one_slide_url'apply_filters'cyberchimps_slider_lite_url1''http://cyberchimps.com' ) );
            
    $slides[1]['link'] = cyberchimps_get_option'image_two_slide_url'apply_filters'cyberchimps_slider_lite_url2''http://cyberchimps.com' ) );
            
    $slides[2]['link'] = cyberchimps_get_option'image_three_slide_url'apply_filters'cyberchimps_slider_lite_url3''http://cyberchimps.com' ) );
            
    $slides[3]['link'] = cyberchimps_get_option'image_four_slide_url'apply_filters'cyberchimps_slider_lite_url4''http://cyberchimps.com' ) );
            
    $slides[4]['link'] = cyberchimps_get_option'image_five_slide_url'apply_filters'cyberchimps_slider_lite_url5''http://cyberchimps.com' ) );

        }
        
    $i 0;
    ?>
    <div class="row-fluid">
        <div id="slider-lite" class="carousel slide">
            <div class="carousel-inner">
          <?php foreach( $slides as $slide ): ?>
          <?php if( $slide['img'] != '' ): ?>
          <?php if( $i == ): ?>
                <div class="active item">
          <?php else: ?>
          <div class="item">
          <?php endif; ?>
                    <a href="<?php echo esc_url$slide['link'] ); ?>">
                        <img src="<?php echo esc_url$slide['img'] ); ?>" alt="Slider" />
                    </a>
                </div>
                <?php endif; ?>
          <?php $i++;
                endforeach; 
    ?>
            </div>
            
            <!-- Slider nav -->
            <a class="carousel-control left slider-lite-left" href="#slider-lite" data-slide="prev">&lsaquo;</a>
            <a class="carousel-control right slider-lite-right" href="#slider-lite" data-slide="next">&rsaquo;</a>
                    
        </div>
    <!-- My feature pics code -->
        <div id="feature_pics_section">
                                       <div id="image_box1"><a href="http://vnrstone.webdesignperth.com.au/?p=1" title="Ledgestone Collection"></a></div>
                                       <div id="image_box2"><a href="http://vnrstone.webdesignperth.com.au/?page_id=1149" title="Arctic Stone Collection"></a></div>
                                       <div id="image_box3"><a href="http://vnrstone.webdesignperth.com.au/?p=1" title="Dressed Edge Collection"></a></div>
                              </div>

    </div><!-- row-fluid -->
    <?php
    }
    ?>
    Site URL: http://vnrstone.webdesignperth.com.au/

    Any help appreciated.

  2. #2
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    338
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Well conditional include is usually not a good practice, but if you have to use this Id say delegate the inclusion of your file to a loader class.

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Perth W.A.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but that went straight over my head :-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •