WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] List Certain Categories only plus their sub categories (8 posts)

  1. Danny Albeck
    Member
    Posted 6 years ago #

    Hey everyone,

    I am working on a site for a client and he has a a page that is private for only users who are logged in to see, it is a list by genre of his movie collection, and when you click on the "Media Library" button he wants it to take you to a page that will only display the parent categories "English" (Subs: Action, Drama, Horror, Comedy, etc.) Parent: "Indian" (Subs: A, B, C, D, E, F, etc.) but he doesn't want all of his other categories like News, Blog, Uncategorized to display on this page. He also wants it so you can click on the category name and it will take you to whatever is entered in under that category. Could anyone be so kind to help me out with this?

  2. Michael Torbert
    WordPress Virtuoso
    Posted 6 years ago #

    http://codex.wordpress.org/Template_Tags/wp_list_pages

    This link will show you have you can have whichever pages shown you'd like... you may want to just try exclude=pageshedoesntwant.

  3. Danny Albeck
    Member
    Posted 6 years ago #

    Ok, i appreciate you pointing me int he right direction, quick question if anyone can help again. I will paste my code below, the problem is I know I put the exclude command in there wrong and the display categories even if there is nothing in them wrong. Could someone help me clean it up a little bit. Here is my code:

    <li id="categories">
    	<h2><?php _e('Posts by Category'); ?></h2>
    	<form action="<?php bloginfo('url'); ?>/" method="get">
    
    <?php
    	$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0 exclude=9,23,16,15,3,1);
    	$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    	echo $select;
         echo $hide_empty=0;
    ?>
    	<noscript><input type="submit" value="View" /></noscript>
    	</form>
    </li>

    Here is the original code:

    <li id="categories">
    	<h2><?php _e('Posts by Category'); ?></h2>
    	<form action="<?php bloginfo('url'); ?>/" method="get">
    <?php
    	$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
    	$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    	echo $select;
    ?>
    	<noscript><input type="submit" value="View" /></noscript>
    	</form>
    </li>

    Thanks guys!

  4. Michael Torbert
    WordPress Virtuoso
    Posted 6 years ago #

    &exclude=1,2,3

  5. Danny Albeck
    Member
    Posted 6 years ago #

    Halls,

    I really appreciate your help! I almost have it getting 2 problems. As soon as I added the exclude tag it made 2 drop down menus, but it is excluding the categories I don't want which is good. Then I added the command to display categories that do not have posts in them. Final addition was the hierarchy command but that made the categories with no entry disappear. I will post my code so either you or anyone may see it.

    <li id="categories">
    	<h2><?php _e('Posts by Category'); ?></h2>
    	<form action="<?php bloginfo('url'); ?>/" method="get">
    <?php
    	$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0 &exclude=9,23,16,15,3,1&hierarchical=1&hide_empty=0 ');
    	$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    	echo $select;
    ?>
    	<noscript><input type="submit" value="View" /></noscript>
    	</form>
    </li>

    Thanks again!

  6. Danny Albeck
    Member
    Posted 6 years ago #

    Update: I partially fixed the problem deleted an extra space I had in the code so now all of the categories are displaying, but I still have 2 drop down boxes.

  7. Danny Albeck
    Member
    Posted 6 years ago #

    Sorry for all the posts another update though. I got it working I had another space in the code. All is working well now! Thank you for all of your help halls!

  8. Michael Torbert
    WordPress Virtuoso
    Posted 6 years ago #

    You're welcome, I'm glad I was able to help get it working. Please mark this post as resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic