• Resolved giuseppe23

    (@giuseppe23)


    I have a code like this in my index ,archives etc..

    <?php
    $page_num = $paged;
    if ($pagenum='') $pagenum =1;
    query_posts('showposts=16&paged='.$page_num); ?>
    <?php if ( have_posts() ) : ?>

    But I have a custom blog template and I want to display blog posts only on blog template how can I exlude category using this option? get_cat_id(get_option(‘mtn_blogcategory’)

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter giuseppe23

    (@giuseppe23)

    I also tried this one but not worked

    <?php
    $bcat = get_option('mtn_blogcat');
    $page_num = $paged;
    if ($pagenum='') $pagenum =1;
    query_posts('showposts=16&paged='.$page_num.'&cat=-'.$bcat); ?>
    <?php if ( have_posts() ) : ?>

    Lee

    (@romanempiredesign)

    I’m not sure if I totally understand what you are trying to do, but it seems like you could use a standard get_posts call in your template like this:

    <?php 
    
    $args = array(
    'category' 			=> 1,
    'posts_per_page'	=> 5,
    'orderby'			=>'title',
    'order'				=>'asc',
    'category__not_in' => array(2) );
    
    $posts = get_posts( $args );
    
    ?>

    That will return all posts in category 1 but not posts in category 2. Assuming you have posts that belong to both categories 1 and 2. Is that what you are looking for?

    Side Note: You are using a variable in your code called $page_num but you are referring to it in your loop as $pagenum.

    Thread Starter giuseppe23

    (@giuseppe23)

    Thanks but is there any way to exlude using $variable instead the category id?
    I want to hide this $bcat = get_option(‘mtn_blogcat’);
    from home,feeds and search not from archives …

    So on the code wich you gave above can I use $bcat instead 1?

    Lee

    (@romanempiredesign)

    <?php 
    
    if (!(is_page('home'))) {
       $bcat = 'mtn_blogcat';
    } else {
        //Do Nothing
    }
    
    $args = array(
    'category' 			=> 1,
    'posts_per_page'	=> 5,
    'orderby'			=>'title',
    'order'				=>'asc',
    'category__not_in' => array($bcat) );
    
    $posts = get_posts( $args );
    
    ?>

    I think that’s what you’re trying to do? To exclude the $bcat variable for pages that aren’t the home page? And I’m assuming your posts have multiple categories?

    Thread Starter giuseppe23

    (@giuseppe23)

    I’m tryiing thankyou verymuch but a quote is missing and I dont know how to add
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ‘)’

    Line 13 is ‘posts_per_page’ => 5,

    Thread Starter giuseppe23

    (@giuseppe23)

    I added a comma to number 1

    <?php 
    
    if (!(is_page('home'))) {
       $bcat = 'mtn_blogcat';
    } else {
        //Do Nothing
    }
    
    $args = array(
    'category' 			=> 1,
    'posts_per_page'	=> 5,
    'orderby'			=>'title',
    'order'				=>'asc',
    'category__not_in' => array($bcat) );
    
    $posts = get_posts( $args );
    
    ?>

    But I see the posts of category again

    Lee

    (@romanempiredesign)

    try this line

    'category__not_in' => array($bcat) );

    and take it out of the array

    'category__not_in' => $bcat );

    Does that work for you?

    And yes, I forgot a comma after the 1…it’s fixed in the above code.

    Lee

    (@romanempiredesign)

    try this line

    'category__not_in' => array($bcat) );

    and take it out of the array

    'category__not_in' => $bcat );

    Does that work for you?

    And yes, I forgot a comma after the 1…it’s fixed in the above code.

    You can also try adding this instead of //Do Nothing

    $bcat = '';

    Thread Starter giuseppe23

    (@giuseppe23)

    yes worked now you are great ?? thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Exlude category using get_option’ is closed to new replies.