Support » Theme: Hueman » Help with homepage

  • Resolved paconarud16

    (@paconarud16)


    `<div id=”grid-wrapper” class=”post-list group”>
    <div class=”post-row”> <article id=”post-17515″ class=”group grid-item post-17515 post type-post status-publish format-standard has-post-thumbnail hentry category-noticias-militares”>
    <div class=”post-inner post-hover”>`

    That is just the one that goes under the slider with the carousel of the last post, I would like to be able to select which post to show, that is to say that the posts of the categories that I want are shown and not that the last post published. I know it will be easy enough, but I have no idea when writing code, so I beg your help.
    Many thanks friends.

    • This topic was modified 6 years, 2 months ago by paconarud16.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter paconarud16

    (@paconarud16)

    Very good, There is no way, something is happening to me and I do not control it. I enter the code that you told me in the file functions.php of my child theme and it does not work:

    Function my_home_category ($ query) {
        If ($ query-> is_home () && $ query-> is_main_query ()) {
            $ Query-> set ('cat', '123 ');
        }
    }
    Add_action ('pre_get_posts', 'my_home_category');

    Where I put ‘cat’ I replaced it by category and where I put ‘123’ I replaced it with the slug of the category I want it to show and nothing at all, it does not work.

    @paconarud16 – if you check the code again you’ll find it is $query, not $ query. You’re also showing an extra space after your category id.

    Thread Starter paconarud16

    (@paconarud16)

    Impossible, uff. I did what you told me, eliminate the spaces and nothing at all. I have a Category that is called ‘bod’ (this is the slug) and I want to not show the posts of this category in the home page post. This is the code that I enter in the function.php according to what you have told me:

    Function exclude_category ($query) {
        If ($query-> is_home () && $query-> is_main_query ()) {
            $Query-> set ('category','-bod');
        }
    }
    Add_action ('pre_get_posts', 'exclude_category');

    Nothing at all, the posts are still showing. Crazy.

    • This reply was modified 6 years, 2 months ago by paconarud16.

    1. In PHP variable names are case sensitive. $Query is not the same as $query.
    http://php.net/manual/en/language.variables.basics.php

    2. The referenced code snippet used the category id. If you want to use the slug you need to use category_name:
    https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

    Thread Starter paconarud16

    (@paconarud16)

    Wonderful, a thousand thanks, at last, was a syntax error when writing Query. Solved A thousand thanks, a pleasure to count on your support. A greeting.

    You’re welcome; glad to help.

    Thread Starter paconarud16

    (@paconarud16)

    thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Help with homepage’ is closed to new replies.