• Resolved martinfamily2005

    (@martinfamily2005)


    OK, I have implemented a dropdown category list on a page, and it works fine, but I want to change some things….but I am not sure how to go about doing that. Here is the page where the dropdown is located (at the bottom): http://billboardfamily.com/blogs/

    Here is what I want to do.

    1) I want to EXCLUDE category ID 7 from the dropdown list.
    2) I want the target page (when a category is selected) to show a list of the blog titles (as links) instead of the complete posts. I want it to work just like it does on this site: http://iwearyourshirt.com/blogs

    Here is the code I am using on the dropdown as of now. Thanks!

    <?php wp_dropdown_categories('show_option_none=Select category'); ?>
    
    <script type="text/javascript"><!--
        var dropdown = document.getElementById("cat");
        function onCatChange() {
            if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
                location.href = "<?php echo get_option('home');
    ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
            }
        }
        dropdown.onchange = onCatChange;
    --></script>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Dan Bissonnet

    (@asinglehumanbeing)

    1) To remove category 7, you should just be able to do:
    <?php wp_dropdown_categories('exclude=7&show_option_none=Select category'); ?>

    2) It depends a bit on the theme you are using. You may have to edit the ‘archive.php’ file in your theme (or child theme). There will probably a call to the_excerpt() which you can either remove entirely (which will also change your tag, monthly, author archive pages) or filter it like so:

    <?php
        if(!is_category()) {the_excerpt();}
    ?>

    You may need to edit some of the other markup around it as well depending on how you want it to display.

    Thread Starter martinfamily2005

    (@martinfamily2005)

    That worked well for #1.

    I tried what you have for #2, and it is not exactly what I was looking for. Basically, if you choose a category in the dropdown on http://www.iwearyourshirt.com/blogs , “Day Journal” for example, you get a list of all the posts in that category in a paginated list (see here: http://iwearyourshirt.com/category/categories/day-journal ) This is exactly what I want on my site.

    Also, here is the code for my archives.php , if that helps:

    And the archive page (when you choose Daily T-Shirt Blog from the dropdown: http://billboardfamily.com/daily-t-shirt-blogs/

    <?php include("header.php"); ?>
    
    <!-- BEGIN content -->
    <div id="content">
    
    	<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    	<?php /* If this is a category archive */ if (is_category()) { ?>
    	<h2 class="title">Archive for the <strong><?php single_cat_title(); ?></strong> Category</h2>
    	<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
    	<h2 class="title">Posts Tagged <strong><?php single_tag_title(); ?></strong></h2>
    	<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    	<h2 class="title">Archive for <?php the_time('F jS, Y'); ?></h2>
    	<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    	<h2 class="title">Archive for <?php the_time('F, Y'); ?></h2>
    	<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    	<h2 class="title">Archive for <?php the_time('Y'); ?></h2>
    	<?php /* If this is an author archive */ } elseif (is_author()) { ?>
    	<h2 class="title">Author Archive</h2>
    	<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    	<h2 class="title">Blog Archives</h2>
    	<?php } ?>
    
    	<?php
    	if (have_posts()) :
    	while (have_posts()) : the_post();
    	?>
    
    	<!-- BEGIN post -->
    	<div class="post">
    		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    		<a href="<?php the_permalink(); ?>"><?php dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '"'); 
    
    ?></a>
    <?php the_excerpt(); ?>
    
    		<p class="date"><?php the_time('F j, Y') ?> <span class="category"><?php the_category(', ') ?></span> <span 
    
    class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></a></p>
    	</div>
    	<!-- END post -->
    
    	<?php endwhile; ?>
    	<p class="postnav">
    		<?php next_posts_link('&laquo; Older Entries'); ?> &nbsp;
    		<?php previous_posts_link('Newer Entries &raquo;'); ?>
    	</p>
    	<?php else : ?>
    	<div class="notfound">
    		<h2>Not Found</h2>
    		<p>Sorry, but you are looking for something that is not here.</p>
    	</div>
    	<?php endif; ?>
    
    </div>
    <!-- END content -->
    
    <?php get_sidebar(); get_footer(); ?>
    Dan Bissonnet

    (@asinglehumanbeing)

    Ok, If you want an unordered list of the post titles, that’s a bit more complex.

    You might be best creating a separate category.php template in your theme directory where you can customise the layout in more detail.

    Here’s a basic category.php file http://wordpress.pastebin.ca/1940373. I haven’t tested it and you will need to do some styling to get it to look exactly like the example you linked to.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Category List Dropdown help needed’ is closed to new replies.