• Resolved vervangenenzo

    (@vervangenenzo)


    Hi,

    I found out that I can exclude a category, but a post is still displayed when a post has more than one categories.

    I have two main categories: Category A and B (B has some subcategories). For the list, I want to exclude categorie B, the subcategories don’t matter at that moment, I want only posts of category A to be shown.

    Is that possible?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi @vervangenenzo,
    For this you will need to use the alm_query_args filter and use a category__not_in query.

    <?php
    function my_excluded_cat($args, $id){
     
      $args['category__not_in'] = array('10'); // 10 is the excluded cat id
      return $args;
     
    }
    add_filter( 'alm_query_args_{my_alm_id}', 'my_excluded_cat', 10, 2);

    Hope this helps.

    Thread Starter vervangenenzo

    (@vervangenenzo)

    Hi @dcooney!

    Thanks for your reply that fast. I think I understand what you’re saying. It is in fact the same as in the plugin settings where I have to include and exclude categories, isn’t it? (But why is a category that is not included, automatically excluded?)

    I’ve now put the code into a new page, but I saw at the “help-section” of the plugin that I can also create my own archive page with the code, am I right?

    Thanks again!

    Erick

    Plugin Author Darren Cooney

    (@dcooney)

    It is in fact the same as in the plugin settings where I have to include and exclude categories, isn’t it?

    Oh wow, sorry! Sometimes I forget what functionality my plugin has. You’re correct.

    This is tricky, but I think instead you may need to use the technique found in the docs.
    https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

    Exclude Posts Belonging to Category
    Display all posts except those from a category by prefixing its id with a ‘-‘ (minus) sign.

    $query = new WP_Query( array( 'cat' => '-12,-34,-56' ) );

    I’ve now put the code into a new page, but I saw at the “help-section” of the plugin that I can also create my own archive page with the code, am I right?

    Yes.

    I’ve now put the code into a new page, but I saw at the “help-section” of the plugin that I can also create my own archive page with the code, am I right?

    Yes.

    Thread Starter vervangenenzo

    (@vervangenenzo)

    Thumbs up! Gonna try that tomorrow!

    Thread Starter vervangenenzo

    (@vervangenenzo)

    I created the archive page and I found out that if I when I go to the a link like mywebsite.nl/blog it automatically shows post only with the category. So for me, the problem with exlcuding posts is solved.

    But I’ve two other questions:
    1. In WordPress I changed the Repeater template. Will it be overwritten when the plugin is update?

    2. In my new archive-page I want to show (and load) six posts at the time. It’s five now and I don’t seem to get it changed. Can I add a line in my archive.php that does that or should I change it in the plugin somewhere? (I’m not using the shortcode in a page).

    Thanks for all your help so far!

    Erick

    • This reply was modified 7 years, 9 months ago by vervangenenzo.
    Thread Starter vervangenenzo

    (@vervangenenzo)

    3. Is it also possible to use it in the search.php to display the results?

    Plugin Author Darren Cooney

    (@dcooney)

    Hi @vervangenenzo,
    1. No
    2. Change it in the shortcode posts_per_page="6"
    3. Yes. https://connekthq.com/plugins/ajax-load-more/examples/search-results/

    Thread Starter vervangenenzo

    (@vervangenenzo)

    <?php if(is_author()){ ?>

    <?php

    $author = get_the_author_meta(‘ID’);

    echo do_shortcode(‘[ajax_load_more author=”‘.$author.'”]’);

    ?>

    <?php } ?>

    <?php if(is_category()){ ?>

    <?php

    $cat = get_category( get_query_var( ‘cat’ ) );

    $category = $cat->slug;

    ?>

    <h1 class=”h1-site-item”> <?php echo single_cat_title(”, false );?> </h1>

    <?php

    echo do_shortcode(‘[ajax_load_more category=”‘.$category.'”]’);

    ?>

    <?php } ?>

    <?php if(is_tag()){ ?>

    <h1><span>Tag:</span> <?php echo single_cat_title(”, false );?></h1>

    <?php

    $tag = get_query_var(‘tag’);

    echo do_shortcode(‘[ajax_load_more tag=”‘.$tag.'”]’);

    ?>

    <?php } ?>

    For my archive.php template, I’m not using the shortcode, or at least I don’t know how I can insert it in the code above.

    Plugin Author Darren Cooney

    (@dcooney)

    There is a complete archive example inside the plugin under Help > Examples.

    Thread Starter vervangenenzo

    (@vervangenenzo)

    Thanks! I found the examples under Help. The archive.php code was a great help, because it solved my problems with the excluding categories. But the post_per_pages, I don’t get it completely. How to implement the shortcode into that archive example?

    You see, I’m not that good with php… 🙂 So probably, there will be some questions on their way.

    Erick

    Plugin Author Darren Cooney

    (@dcooney)

    Ok, sounds good. closing this for now.

    Thread Starter vervangenenzo

    (@vervangenenzo)

    I made some new try today. I included the shortcode you gave me into this:

    <?php

    $post = get_posts(‘post’);

    echo do_shortcode(‘[posts_per_page=”6″]’);

    ?>

    Somewhere it’s going wrong, because it doesn’t work yet. In my WordPress-settings the number of posts per page is set to 6, so it’s weird that it still is showing 5.

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

The topic ‘Excluding a categorie’ is closed to new replies.