WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to change category for slider? (21 posts)

  1. gpsy1
    Member
    Posted 1 year ago #

    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!

  2. Aaron
    Member
    Posted 1 year ago #

    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.

  3. gpsy1
    Member
    Posted 1 year ago #

    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 );
    }
  4. Aaron
    Member
    Posted 1 year ago #

    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.

  5. gpsy1
    Member
    Posted 1 year ago #

    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....

  6. gpsy1
    Member
    Posted 1 year ago #

    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

  7. Aaron
    Member
    Posted 1 year ago #

    **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.

  8. gpsy1
    Member
    Posted 1 year ago #

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

  9. gpsy1
    Member
    Posted 1 year ago #

    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.

  10. gpsy1
    Member
    Posted 1 year ago #

    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...?

  11. Aaron
    Member
    Posted 1 year ago #

    Got a link to your site? Would be easier.

  12. gpsy1
    Member
    Posted 1 year ago #

    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.

  13. gpsy1
    Member
    Posted 1 year ago #

    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

  14. Aaron
    Member
    Posted 1 year ago #

    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.

  15. gpsy1
    Member
    Posted 1 year ago #

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

  16. Aaron
    Member
    Posted 1 year ago #

    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.

  17. gpsy1
    Member
    Posted 1 year ago #

    Oh my god....sorry im working on this all day so tired now....thanx for the help... will corect that and let you know

  18. gpsy1
    Member
    Posted 1 year ago #

    Corected , its almost there but still don't look good...its adding more posts than what it should.

  19. Aaron
    Member
    Posted 1 year ago #

    Looks like you pasted something wrong on archives.php because it is cut off.

    But the amount of the query is set on

    &posts_per_page=4

    Did you change that?

    I would think

    $post_query = 'cat='.$slider_cat_id.'&posts_per_page=4&ignore_sticky_posts=1';

    would only show 4 posts.

  20. gpsy1
    Member
    Posted 1 year ago #

    Still it doesn't change posts per category!

    This is just beyond my knowledge, it looks like this will take a long time to fix ...i want to say that i appreciate all your work and time ...

  21. gpsy1
    Member
    Posted 1 year ago #

    <?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 ); ?>

    i belive i did

Topic Closed

This topic has been closed to new replies.

About this Topic