SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclude Category fomr Blog Page (WP How-to)

    Simply for you guys.. Pain in the **** for me!

    All I need to do is exclude category&tag_ID=3&post_type=post from:

    PHP Code:
    <?php
    /*
    Template Name: Blog
    */
    ?>
    <?php get_header
    (); ?>
    <?php 
    if (have_posts()) : ?>

    <div id="content">
        <!--page.php-->
    <div id="post" class="post clearfix">

                <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

        <!--post title-->
        <h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>

        <!--post text with the read more link-->
    <?php the_excerpt(); ?>

        <!--for paginate posts-->
        <?php link_pages('<p><strong>Pages:</strong> ''</p>''number'); ?>

        <?php //comments_template(); // uncomment this if you want to include comments template ?>


        <?php endwhile; // end of one post ?>
    <div class="page-nav">
    <?php      wp_pagenavi(); ?>    </div>
        <?php else : // do not delete ?>
        <h3>Page Not Found</h3>
        <p>We're sorry, but the page you are looking for isn't here.</p>
        <p>Try searching for the page you are looking for or using the navigation in the header or sidebar</p>

        <?php
    endif; // do not delete ?>

    <!--page.php end-->
    </div>
    </div>
    <?php endif; ?>
    <?php get_sidebar
    (' '); ?>
    <?php get_footer
    (' '); ?>
    I know it's somewhere in the "php query there at the top.. But I can't figure out how to incorporate it so that it doesn't show.. Any help would be greatly appreciated.

    THANKS!

    --Scott G.

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Can you provide a better explanation of what it is doing now, that you don't want it to do? I'm not sure I follow what you are trying to achieve.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    stlheroinhelp.org/blog/

    ^^^ see the post "test" it's categorized under "Memorial" and I don't want those posts to show up on the blog page with other posts. I want to exclude all posts tagged with "Memorial" from the blog page. I have another section where all those appear "/category/memorial/"

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    On this page, someone recommends the following plugin, Ultimate Category Excluder

    Then on this page, it seems you just need to add before your if (have_posts()) statement
    PHP Code:
    query_posts'cat=-X' ); // replace X with the category ID, leave the minus sign 
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been trying different variations of:
    PHP Code:
    <?php query_posts'cat=-3' ); ?>
                <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    PHP Code:
    <?php query_posts('cat=-3'); ?>
    <?php 
    if (have_posts()) : ?>

    <div id="content">
        <!--page.php-->
    <div id="post" class="post clearfix">

                <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    I don't really want to have to use another plugin for this and don't want to have to edit much except for the blog.php template which is used to display blog posts.. I just want to EXCLUDE "Memorials" which is Category ID 3... Can't seem to figure this one out...

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Try just updated the following line
    PHP Code:
    <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
    To
    PHP Code:
    <?php query_posts(array('category__not_in' => -3,'paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  7. #7
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...Wow... Ok solved it...

    NOT THIS:
    PHP Code:
    <?php query_posts'cat=-3' ); ?>
                <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    BUT THIS:
    PHP Code:
                <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
    <?php query_posts
    'cat=-3' ); ?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    ah, okay. Do you still only get 10 posts per page? And does the paging actually still work? Or do you have to do a combine effort like so (although I am unsure if it works)
    PHP Code:
    <?php query_posts(array('category__not_in' => -3,'paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  9. #9
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Found this too http://wordpress.org/support/topic/q...ng-with-paging

    It says, using the cat=-3 may break your paging and they all suggest doing the following:
    PHP Code:
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $posts_per_page = (get_query_var('posts_per_page')) ? get_query_var('posts_per_page') : 10;
    query_posts('cat=-3&paged='.$paged.'&posts_per_page='.$posts_per_page); 
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  10. #10
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @cpradio

    You're right, the script did break the paging..

    How do I implement your above code? I tried turning this:
    PHP Code:
                <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
                <?php query_posts('cat=-3'); ?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    Into this (as recommended above ^^^):

    PHP Code:
                <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1?>
                <?php $posts_per_page = (get_query_var('posts_per_page')) ? get_query_var('posts_per_page') : 10?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    Left me with a blank page though..

  11. #11
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Because you forgot the all important query_posts line
    PHP Code:
                <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                
    $posts_per_page = (get_query_var('posts_per_page')) ? get_query_var('posts_per_page') : 10;
                
    query_posts('cat=-3&paged='.$paged.'&posts_per_page='.$posts_per_page); ?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  12. #12
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the quick response cpradio. I changed the code and it's not doing anything for me unfortunately. There are 12 posts on the page: http://stlheroinhelp.org/blog/

    I concede Lol

  13. #13
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, here is another attempt

    Remove this
    PHP Code:
                <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                
    $posts_per_page = (get_query_var('posts_per_page')) ? get_query_var('posts_per_page') : 10;
                
    query_posts('cat=-3&paged='.$paged.'&posts_per_page='.$posts_per_page); ?>
    Replace it with
    PHP Code:
                <?php query_posts($query_string '&cat=-3'); ?>
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  14. #14
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got only 10 posts being displayed but I for the life of me cannot figure out how to add page navigation/pagination whatever it's called.. The navigation that populates at the bottom of the page to go to the next page with 10 posts..

    PHP Code:
    <?php
    /*
    Template Name: Blog
    */
    ?>
    <?php get_header
    (); ?>
    <?php 
    if (have_posts()) : ?>

    <div id="content">
        <!--page.php-->
    <div id="post" class="post clearfix">
    <div id="blog-heading"><h1>Blog &amp; News Articles</h1></div>

    <?php
        $recentPosts 
    = new WP_Query();
        
    $recentPosts->query('posts_per_page=10&cat=-3');
    ?>
    <?php 
    while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
        <!--post title-->
        <div id="h2-memorial"><h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2></div>

        <!--post text with the read more link-->
    <?php the_excerpt(); ?>

        <!--for paginate posts-->
        <?php link_pages('<p><strong>Pages:</strong> ''</p>''number'); ?>

        <?php //comments_template(); // uncomment this if you want to include comments template ?>


        <?php endwhile; // end of one post ?>
    <div class="page-nav">
    <?php      wp_pagenavi(); ?>    </div>
        <?php else : // do not delete ?>
        <h3>Page Not Found</h3>
        <p>We're sorry, but the page you are looking for isn't here.</p>
        <p>Try searching for the page you are looking for or using the navigation in the header or sidebar</p>

        <?php
    endif; // do not delete ?>


    <!--page.php end-->
    </div>
    </div>
    <?php get_sidebar(' '); ?>
    <?php get_footer
    (' '); ?>
    CPRADIO if you help me solve this I want your Paypal email address..

  15. #15
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    I believe the solution will be similar to http://www.sitepoint.com/forums/show...late-I-m-stuck, so once we get that solved, it should be copy and paste
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  16. #16
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, I have it solved

    Replace
    PHP Code:
        $recentPosts = new WP_Query(); 
        
    $recentPosts->query('posts_per_page=10&cat=-3'); 
    With
    PHP Code:
        $recentPosts = new WP_Query( array( 'cat' => -3'posts_per_page' => 10'paged' => get_query_var('paged') ) ); 
    Then replace
    PHP Code:
    <?php      wp_pagenavi(); ?>
    With
    PHP Code:
    <?php      wp_pagenavi( array( 'query' => $recentPosts ) ); ?>
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  17. #17
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CPRADIO!

    You are the friggin MAN! I really can't thank you enough! Thank you thank you thank you! You solved what's been eating at me for 2-entire days.. And you were just helping. Thank you so much!

    -Scott G.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •