Support » Fixing WordPress » How to change category for slider?

  • Resolved gpsy1

    (@gpsy1)


    I want slider to show specific category howi do that….here is slider code

    $gazpo_settings = get_option( 'gazpo_options');
    	$slider_cat_id = $gazpo_settings['gazpo_slider_category'];
    	//if no category is selected for slider, show latest posts
    	if ( $slider_cat_id == 0 ) {
    		$post_query = 'posts_per_page=4&ignore_sticky_posts=1';
    	} else {
    		$post_query = 'cat='.$slider_cat_id.'&posts_per_page=4&ignore_sticky_posts=1';
    	}
    ?>
    
    <div id="gazpo-slider" >
    		<ul class="ui-tabs-nav ui-tabs-selected">
    			<?php query_posts( $post_query ); ?>
    			<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
    			<li class="ui-tabs-nav-item" id="nav-fragment-<?php echo $post->ID; ?>">
    			<a href="#fragment-<?php echo $post->ID; ?>">
    				<?php the_post_thumbnail( 'thumbnail', array('class' => 'slider_thumb') ); ?>
    				<span class="title">
    						<?php $short_title = mb_substr(the_title('','',FALSE),0,40);
    						echo $short_title; if (strlen($short_title) >39){ echo '...'; } ?>
    				</span>
    				<br />
    				<span class="date"><?php the_time('F j'); ?></span>
    			</a>
    			</li>
    			<?php endwhile; endif;?>
    			<?php wp_reset_query();?>
    	    </ul>
    
    		<?php query_posts( $post_query ); ?>
    		<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
    		<div id="fragment-<?php echo $post->ID; ?>" class="ui-tabs-panel ui-tabs-hide" style="">
    			<?php the_post_thumbnail( 'large', array('class' => 'slider_image') ); ?>
    			 <div class="info" >
    				<h2>
    					<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    					<?php $short_title = mb_substr(the_title('','',FALSE),0,35);
    					echo $short_title; if (strlen($short_title) >34){ echo '...'; } ?>
    					</a>
    				</h2>
    				<p>
    				<?php
    					$content = get_the_content();
    					$content = strip_tags($content);
    					echo mb_substr($content, 0, 150). '...';
    				?>
    				</p>
    			 </div>
    	    </div>
    
    			<?php endwhile; endif;?>
    			<?php wp_reset_query();?>
    </div>

    how i make this point to specific category….please!

Viewing 15 replies - 1 through 15 (of 20 total)
  • I didn’t install it but looked the source code real quick and assuming “gazpoMag: Magazine Style WordPress Theme” is the theme you are talking about there is a theme option for this.

    array(	"name" => "Slider Category",
    			"desc" => "Remember to add Featured image to the category posts. You can see the option in the right column in the New Post page.",
    			 "id" => $shortname."_slider_category",
    			"options" => gazpo_cat_list(),
    			"std" => "0",
    			"type" => "select-cat"),

    So I would go explore the theme options.

    Thanx for answering and yes you are right Aaron it’s Gazpo theme but its silverOrchid.

    Unfortunatly i dont see anything like the code you posted. This is what i have in gazpo-settings for the slider:

    $gazpo_options = array(
    	'gazpo_show_slider' => true,
    );
    function gazpo_validate_options( $input ) {
    	global $gazpo_options;
    
            	if ( ! isset( $input['gazpo_show_slider'] ) )
    	$input['gazpo_show_slider'] = null;
    	$input['gazpo_show_slider'] = ( $input['gazpo_show_slider'] == 1 ? 1 : 0 );
    }

    Can you link to the theme? I downloaded it and looked and saw in includes/slider.php

    * Theme:  	  silverOrchid
     * Theme URL: http://gazpo.com/2012/04/silverorchid
     * Created:   April 2012
     * Author:    Sami Ch.
     * URL: 	  http://gazpo.com
     *
     **/
    	$gazpo_settings = get_option( 'gazpo_options');
    	$slider_cat_id = $gazpo_settings['gazpo_slider_category'];
    	//if no category is selected for slider, show latest posts
    	if ( $slider_cat_id == 0 ) {
    		$post_query = 'posts_per_page=4&ignore_sticky_posts=1';
    	} else {
    		$post_query = 'cat='.$slider_cat_id.'&posts_per_page=4&ignore_sticky_posts=1';
    	}

    This one again says there is an option.

    Yes im looking at that for the past few hours….it has the settings at the admin area for slider just for home page.

    What im trying to do is to add slider to category pages also but to show post from that category and basically repeat that for each category and subcategory page i have. Any idea….

    Sorry….yes it has slider.php which im trying to edit but no luck…. don’t know much about php so i was trying to solve the problem with forum threads and wordpress codex but still didint get it…..

    here is theme

    http://wordpress.org/extend/themes/silverorchid

    **Backup your files before making changes just in case**

    Not tested but open slider.php and copy all the code from <div id="gazpo-slider" > and down. This is the code that makes the slider.

    Then open archive.php which is your category template and paste it all right below <div id="content" >.

    This will add the slider on top above the posts on your category pages. Now we need to set the category to the current category.

    Above the query posts line add the three lines below. This is getting the current category > getting the ID number of it > setting the query to get that category only > only 4 of them > and ignore sticky posts.

    <?php $category = get_the_category(); ?>
    <?php $category_id = $category->cat_ID; ?>
    <?php $post_query = 'cat='.$slider_cat_id.'&posts_per_page=4&ignore_sticky_posts=1'; ?>
    <?php query_posts( $post_query ); ?>

    Like I said. Untested. Just let me know if it works. I am leaving for a few hours so I won’t respond for a bit.

    Thanx Aaron…this looks like it should work…..i will give it a try and let you know …..thanx

    Not sure what do you meen by

    Above the query posts line add the three lines below.

    Where exactly those 3 lines need to be added? Can you explain a bit more, please.

    Ok i think i get it… i add 3 line of code you suggested in arive.php in top of slider code which say
    <?php query_posts( $post_query ); ?>

    but whith this is see slider but is without any css style…do i need to create a new style for this or…?

    Got a link to your site? Would be easier.

    I maybe have a workaround for this problem. It mite be stupid solution but that’s all i have.

    Duplicate slider.php and rename it to slider2.php. Also duplicate all the slider code in gazpo-settings and adjust the name to slider2. After that rename get slider in category.php to slider2 …

    Basically i just add #2 so this gives me complete new slider sand settings for it in admin area. Now it should be just a matter of creating each slider and category page and also add get_slider with different slider number to it. I should be able to change posts category in slider for each category page i created right in the admin area.

    Is this a good idea or im being ridiculous and to complicating…. hope someone can comment on this.

    Aaron I tried you suggestion …but this gives me page without any style…not sure why….maybe im missing something….would love simmple fix instead creating lot of caategory pages and sliders

    This is a simple way since your theme doesn’t support it. But I would need to link to your site to see why this is happening.

    Yes sorry … here is link http://test.zemlja.rs

    Your home page code for the slider starts with.

    <div id="gazpo-slider" class="ui-tabs ui-widget ui-widget-content ui-corner-all">

    The archive output is below.

    <ul class="ui-tabs-nav ui-tabs-selected">

    So when copying the slider.php code did you forget to include the div? You should copy the line starting with <div id="gazpo-slider" > all the way down.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘How to change category for slider?’ is closed to new replies.