• Hi! The homepage of my website has a slideshow and right below the slideshow is the content div. When visited using the primary url, the slideshow tends to remain even when different posts and categories are loaded. Basically everything is loaded underneath the slideshow. On the other hand, when visited using an alternative url, and by “alternative” I mean a category or post/page url, the slideshow does not exist, since this function is only limited to the homepage.

    What I am trying to do, is to automatically remove the slideshow from homepage every time the visitor clicks on a link of a category, post, page or anything except homepage. And have the slideshow show up again every time the banner logo or “Home” link is visited even when the visitor has entered the website from an “alternative” url.

    This is a link to my website: http://bit.ly/RJBEZf (Sorry if I shortened it, I don’t want it to be indexed)
    This is a link the theme I’m using: http://wpshower.com/themes/sight/

    Slideshow.php:

    <?php
        $args = array(
            'meta_key' => 'sgt_slide',
            'meta_value' => 'on',
            'numberposts' => -1,
            );
        $slides = get_posts($args);
    
        if ( !empty($slides) ) : $exl_posts = Array(); ?>
    
            <div class="slideshow"><div id="slideshow">
    
            <?php foreach( $slides as $post ) :
                setup_postdata($post);
                global $exl_posts;
                $exl_posts[] = $post->ID;
            ?>
            <div class="slide clear">
                <div class="post">
                    <?php if ( has_post_thumbnail() ) echo '<a href="'.get_permalink().'">'.get_the_post_thumbnail($post->ID, 'slide',
                        array(
                            'alt'	=> trim(strip_tags( $post->post_title )),
                            'title'	=> trim(strip_tags( $post->post_title )),
                        )).'</a>'; ?>
                    <div class="post-category"><?php the_category(' / '); ?></div>
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
                    <div class="post-meta">by <span class="post-author"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" title="Posts by <?php the_author(); ?>"><?php the_author(); ?></a></span> on <span
                            class="post-date"><?php the_time(__('M j, Y')) ?></span> &bull; <?php comments_popup_link(__('No Comments'), __('1 Comment'), __('% Comments'), '', __('Comments Closed') ); ?> <?php edit_post_link( __( 'Edit entry'), '&bull; '); ?></div>
                    <div class="post-content"><?php if ( has_post_thumbnail() && function_exists('smart_excerpt') ) smart_excerpt(get_the_excerpt(), 50); else smart_excerpt(get_the_excerpt(), 150); ?></div>
                </div>
            </div>
            <?php endforeach; ?>
    
            </div>
    
                <a href="javascript: void(0);" id="larr"></a>
                <a href="javascript: void(0);" id="rarr"></a>
            </div>
        <?php endif; ?>

    Header.php (Part 1):

    <?php wp_head(); ?>
            <?php if ( is_home() && !get_option('ss_disable') ) : ?>
            <script type="text/javascript">
                (function($) {
                    $(function() {
                        $('#slideshow').cycle({
                            fx:     'scrollHorz',
                            timeout: <?php echo (get_option('ss_timeout')) ? get_option('ss_timeout') : '7000' ?>,
                            next:   '#rarr',
                            prev:   '#larr'
                        });
                    })
                })(jQuery)
            </script>
            <?php endif; ?>

    Header.php (Part 2):

    <?php if ( is_home() && !get_option('ss_disable') ) get_template_part('slideshow'); ?>
                <!-- Container -->
                	<div id="container" class="clear">
                    	<!-- Content -->
                    <div id="content">
    <!-- End of Header -->

    Functions.php (SlideshowPart):

    /*** Slideshow ***/
    
    $prefix = 'sgt_';
    
    $meta_box = array(
        'id' => 'slide',
        'title' => 'Slideshow Options',
        'page' => 'post',
        'context' => 'side',
        'priority' => 'low',
        'fields' => array(
            array(
                'name' => 'Show in slideshow',
                'id' => $prefix . 'slide',
                'type' => 'checkbox'
            )
        )
    );
    add_action('admin_menu', 'sight_add_box');
    
    // Add meta box
    function sight_add_box() {
        global $meta_box;
    
        add_meta_box($meta_box['id'], $meta_box['title'], 'sight_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']);
    }
    
    // Callback function to show fields in meta box
    function sight_show_box() {
        global $meta_box, $post;
    
        // Use nonce for verification
        echo '<input type="hidden" name="sight_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
    
        echo '<table class="form-table">';
    
        foreach ($meta_box['fields'] as $field) {
            // get current post meta data
            $meta = get_post_meta($post->ID, $field['id'], true);
    
            echo '<tr>',
                    '<th style="width:50%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
                    '<td>';
                    echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
            echo     '<td>',
                '</tr>';
        }
    
        echo '</table>';
    }
    
    add_action('save_post', 'sight_save_data');
    
    // Save data from meta box
    function sight_save_data($post_id) {
        global $meta_box;
    
        // verify nonce
        if (!wp_verify_nonce($_POST['sight_meta_box_nonce'], basename(__FILE__))) {
            return $post_id;
        }
    
        // check autosave
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return $post_id;
        }
    
        // check permissions
        if ('page' == $_POST['post_type']) {
            if (!current_user_can('edit_page', $post_id)) {
                return $post_id;
            }
        } elseif (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }
    
        foreach ($meta_box['fields'] as $field) {
            $old = get_post_meta($post_id, $field['id'], true);
            $new = $_POST[$field['id']];
    
            if ($new && $new != $old) {
                update_post_meta($post_id, $field['id'], $new);
            } elseif ('' == $new && $old) {
                delete_post_meta($post_id, $field['id'], $old);
            }
        }
    }

    Words cannot describe how much I appreciate your help.
    Also the plugin is one of the most fluid and flexible ajax add-ons I’ve seen so far, thank you very much for sharing it.

    Joe

    http://wordpress.org/extend/plugins/advanced-ajax-page-loader/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Hide & Show Slideshow’ is closed to new replies.