• I have a Category template page that is actually a copy of the blog template, with a filter applied to only show posts of a certain category (Case Studies) slug is (case-studies).

    I want to have the template look at the page slug, and use that as the variable to filter the posts. This should allow me to create separate category menu items, and when you click one on the menu bar, it immediately presents the blog excerpt page for that category (Case Studies, Resources, or Blog, for example)

    This should be all the relevant code:

    [ Moderator note: Code fixed, please wrap code in backticks or use the code button. ]

    <?php get_header(); ?>
    
    <section id="content" role="main">
    	<div id="pageTitle" class="page">
    		<div id="title_bg">
    			<div class="title"><?php single_cat_title( '' ); ?></div>
    		</div>
    		<div id="compass" class="blog"></div>
    	</div>
    
    				<section class="entry-content">
    
    <?php // Display blog posts on any page @ http://m0n.co/l
                        $temp = $wp_query; $wp_query= null;
                        $wp_query = new WP_Query(); $wp_query->query("category_name=$slug&posts_per_page=10" . '&paged='.$paged);
                        while ($wp_query->have_posts()) : $wp_query->the_post(); if ( $post->ID == $do_not_duplicate ) continue; ?>
    
    	<div id="containerBlogEntry">
    		<div id="sidebar">
    		<div class="date">
    			<?php the_time( get_option( 'date_format' ) ); ?>
     		</div>
    		<div class="separator"></div>
    		<div class="author">
    				Posted by <?php the_author_posts_link(); ?>
     		</div>
    		</div>
    		<div id="info">
    
    			<?php /*if ( have_posts() ) : while ( have_posts() ) : the_post();*/ ?>
    			<article>
    
    					<h2 class="entry-title">
    						<a>" title="<?php the_title_attribute(); ?>" rel="bookmark">
    							<?php the_title(); ?>
    						</a>
    					</h2>
    					<div class="separator"></div>
     					<div style="height: 2px;"></div>
    					<div id="ecWrap">
    						<?php if ( ( function_exists('has_post_thumbnail') ) && ( has_post_thumbnail() ) ) {
    							$post_thumbnail_id = get_post_thumbnail_id();
    							$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
    						?>
    						<!--<a>" style="background: none;">-->
    							<img class="wp-post-image" src="<?php echo $post_thumbnail_url; ?>">
    						<!--</a>-->
    						<?php } ?>
            	            <?php the_excerpt(); ?>
    					</div>
    					<div id="rmLink">
    						<a>">Read More >></a>
     					</div>
     					<div style="height: 50px;"></div>
    
    			</article>
    		</div>
    	</div>
                        <?php endwhile; ?>
    
                        <?php if ($paged > 1) { ?>
    
                        <nav id="nav-posts">
                            <div class="prev"><?php next_posts_link('« Previous Posts'); ?></div>
                            <div class="next"><?php previous_posts_link('Newer Posts »'); ?></div>
                        </nav>
    
                        <?php } else { ?>
    
                        <nav id="nav-posts">
                            <div class="prev"><?php next_posts_link('« Previous Posts'); ?></div>
                        </nav>
    
                        <?php } ?>
    
                        <?php wp_reset_postdata(); ?>
    				</section>
    	<?php /*if ( ! post_password_required() ) comments_template( '', true ); ?>
    	<?php endwhile; endif;*/ ?>
    
    	<a href="">             </a>
    
    </section>

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get category slug as a variable’ is closed to new replies.