Forums

[resolved] Excluding categories in a template (14 posts)

  1. kaspar wimberley
    Member
    Posted 5 months ago #

    I guess for many of you this is fairly simple, but I've tried and read everything now without luck. Any help greatly appreciated.

    I want to remove a post category from my blog and magazine templates (template-blog.php & template-magazine.php).

    I guess I change this bit in some way:

    <?php
    $paged = ( !empty($paged) ) ? $paged : $page;
    query_posts(array(
    'posts_per_page' => get_option('posts_per_page'),
    'paged' => $paged
    ));
    ?>

    But maybe I'm off the mark. Let me know if you need any code.

    I'm using wpshower's unspoken theme (http://www.treacletheatre.co.uk/portfolio).

    These are the files I could edit:

    Templates

    404 Template
    (404.php)
    Archives
    (archive.php)
    AutoEmbed.php
    (AutoEmbed.php)
    Blog Page Template
    (template-blog.php)
    Comments
    (comments.php)
    Contact Form Page Template
    (template-contactform.php)
    FixImageMargins.php
    (FixImageMargins.php)
    Footer
    (footer.php)
    Header
    (header.php)
    Image Gallery Page Template
    (template-gallery.php)
    Magazine Page Template
    (template-magazine.php)
    Main Index Template
    (index.php)
    Page Template
    (page.php)
    Search Results
    (search.php)
    Sidebar
    (sidebar.php)
    Single Post
    (single.php)
    Sitemap Page Template
    (template-sitemap.php)
    Tags Page Template
    (template-tags.php)
    Theme Functions
    (functions.php)
    Wide Page Template
    (template-wide.php)
    advanced_post_options.php
    (advanced_post_options.php)
    commentform.php
    (commentform.php)
    home.php
    (home.php)
    loop-page.php
    (loop-page.php)
    loop-single.php
    (loop-single.php)
    loop.php
    (loop.php)
    pagination.php
    (pagination.php)
    shortcodes.php
    (shortcodes.php)
    theme_options.php
    (theme_options.php)
    twitter.class.php
    (twitter.class.php)
    widgets.php
    (widgets.php)
    yarpp-template-recommended.php
    (yarpp-template-recommended.php)
    yarpp-template-similar.php
    (yarpp-template-similar.php)

    Styles

    Stylesheet
    (style.css)
    ie.css
    (ie.css)

  2. criador.in
    Member
    Posted 5 months ago #

    Hi,

    basically all the categories on the menu can be found at the header.php file in your theme folder.

    Find this:

    <?php wp_list_categories('title_li=') ?>

    Replace with:
    <?php wp_list_categories('exclude=6,43&title_li=') ?>

    This will exclude category 6 and 4 from the list. But you can change the category ID according to your requirement.

    Thanks,

  3. kaspar wimberley
    Member
    Posted 5 months ago #

    Thanks Criador! I'll give it a go.
    And that will not remove these categories from the site? They will still appear in category listings, etc?
    K

  4. kaspar wimberley
    Member
    Posted 5 months ago #

    No

    php wp_list_categories
    to be found! Only stuff relating to the menus etc appearing above the main content.
    Any other ideas?
    K

  5. kaspar wimberley
    Member
    Posted 5 months ago #

    Maybe I wasn't clear earlier. I want to stop the category appearing in the loop/content of my blog template and/or magazine template (currently set as home page). I don't want to remove it from the menus.
    k

  6. kaspar wimberley
    Member
    Posted 5 months ago #

    Here's my loop if that helps:

    [code moderated - please use the pastebin]

  7. kaspar wimberley
    Member
    Posted 5 months ago #

    And here's the full magazine template code:

    [code moderated - please use the pastebin]

  8. kaspar wimberley
    Member
    Posted 5 months ago #

    I believe it should be in the loop (see above). But where and how?

  9. Chip Bennett
    Member
    Posted 5 months ago #

    You need to modify the query_posts() argument string, using the appropriate category query arguments.

    Let's say the ID for the category you want to exclude is "5" (you'll need to figure out the actual category ID).

    See this?

    <?php
    $paged = ( !empty($paged) ) ? $paged : $page;
    query_posts(array(
    'posts_per_page' => get_option('posts_per_page'),
    'paged' => $paged
    ));
    ?>

    Add the cat parameter. e.g.:

    <?php
    $paged = ( !empty($paged) ) ? $paged : $page;
    query_posts(array(
    'posts_per_page' => get_option('posts_per_page'),
    'paged' => $paged,
    'cat' => '-5'
    ));
    ?>
  10. kaspar wimberley
    Member
    Posted 5 months ago #

    Thanks Chip, I'll try it!
    K

  11. kaspar wimberley
    Member
    Posted 5 months ago #

    Works! Thanks Chip,
    k

  12. mingookoh
    Member
    Posted 2 weeks ago #

    Wimberley,
    Now, I also use unspoken theme and I'm in same situation.
    I don't know how to edit this source.

    <?php
    		$paged = ( !empty($paged) ) ? $paged : $page;
    		query_posts(array(
                    'posts_per_page' => get_option('posts_per_page'),
                    'paged' => $paged
    				'cat' => '-5'
                ));
            ?>

    This part I understood. but "You need to modify the query_posts() argument string, using the appropriate category query arguments." It's difficult.

    <?php
    
    	// The Query
    	$the_query = new WP_Query( $args );
    	$query = new WP_Query( 'cat=-5' );
    
    	// The Loop
    	while ( $the_query->have_posts() ) : $the_query->the_post();
    		echo '<li>';
    		the_title();
    		echo '</li>';
    	endwhile;
    
    	// Reset Post Data
    	wp_reset_postdata();
    
    	?>
    
            <?php
    		$paged = ( !empty($paged) ) ? $paged : $page;
    		query_posts(array(
                    'posts_per_page' => get_option('posts_per_page'),
                    'paged' => $paged
    				'cat' => '-5'
                ));
            ?>

    This is right? Please, tell me how to use! T_T
    Thanks!

  13. kaspar wimberley
    Member
    Posted 2 weeks ago #

    Hi mingookoh,
    I think you might be over complicating things.
    My code in the magazine template is now like this:

    `<div class="title"><?php _e('Latest entries', 'unspoken'); ?><a href="javascript: void(0);" id="mode" class="<?php if ($_COOKIE['mode'] == 'grid') echo 'flip'; ?>"></a></div>

    <?php
    $paged = ( !empty($paged) ) ? $paged : $page;
    query_posts(array(
    'posts_per_page' => get_option('posts_per_page'),
    'paged' => $paged,
    'cat' => '-491'
    ));
    ?>

    <?php get_template_part('loop'); ?>`

    Change the ID to whatever categories you want to exclude.
    That's all I needed to do.
    K (http://treacletheatre.co.uk/portfolio)

  14. mingookoh
    Member
    Posted 2 weeks ago #

    Works! Thanks Wimberley, :)

Reply

You must log in to post.

About this Topic