Support » Theme: Academica » Home page show posts from one category only

  • Resolved Pali Madra

    (@palimadra)


    The theme is the right fit for my present requirements and works well.

    There is one issue that I cannot fix and that is that I wanted to show posts from one category only on the home page. However, I have not been able to customize this.

    Any help would be appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • esmi

    (@esmi)

    Forum Moderator

    First create a child theme for your changes. Then you will need to add a custom query to your theme’s main posts page (possibly index.php). See http://codex.wordpress.org/Function_Reference/query_posts

    Thanks.

    Esmi to the rescue as is the case usually! 🙂

    I mean the WordPress forum would not be what it is if you were not around.

    Thank you for finding the solution as creating a child theme did not come to my mind and it would work in most cases.

    However, if it is not too much of a hassle can you let me know where the loop is being run in the theme. The reason I’m asking is purely for knowledge as the Academica theme does not have a typical structure one has come to expect from WordPress themes.

    Thanks for the help. It inspires me to spend sometime giving back to the WordPress community.

    esmi

    (@esmi)

    Forum Moderator

    Looking at the theme’s files in SVN, it seems that the index.php template file is indeed the one that you want. That’s where the Loop is set up, so you’ll need to add your custom query just before:

    <?php
    if ( have_posts() ) :

    A rather more elegant & future-proofed solution would be to add something like:

    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' );

    in your child theme’s functions.php file – where 123 is the id of the category that you want to display. In theory, that should also work.

    As I said esmi you are awesome (for lack of a better word)!

    PS: are you there on Twitter or FB….. maybe I can learn more from there!

    esmi

    (@esmi)

    Forum Moderator

    Sadly, I am obviously too anti-social to use either Twitter or FB. I do post occasionally on http://quirm.net/ if that helps 🙂

    Anti-social? You? though people may assume that because you do not have social accounts but the truth is far too different. I do follow the blog at quirm.net and it has some of the most useful posts.

    Thanks for your time. Appreciate it.

    esmi

    (@esmi)

    Forum Moderator

    Thank you. I am suitably flattered. 🙂

    esmi,

    Staying off FB does not in my opinion make you “anti-social”.

    It demonstrates great wisdom.

    I also thank you for your contribution!

    Sorry for the dupe. My refresh error after being interrupted.

    esmi,

    Staying off FB does not in my opinion make you “anti-social”.

    It demonstrates great wisdom.

    I also thank you for your contribution!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Home page show posts from one category only’ is closed to new replies.