WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How to use category as homepage

[Resolved] How to use category as homepage

  • Hello.

    I am wondering if it would be possible to use a category as the homepage to my site. Right now, the homepage is “Home” and it contains all the posts. However, I would like it to be the category “News”. Any ideas on how to do this? But, I still want to only have to type in “itsalltech.com” not “itsalltech.com/category/news”. Thanks.

    http://www.itsalltech.com

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hola

    [1] Learn how to make a wordpress page template

    [2] Make a page template with a query_post for a specific category

    [3] Use a page with this page template as an home page in your WP options.

    Look there for more information :

    http://wordpress.org/support/topic/227151?replies=9
    http://wordpress.org/support/topic/156208?replies=7

    @+

    S.

    You don’t even need to do that, a simple conditional query_posts in the theme’s index like so should suffice, to keep it simple…

    if( is_home() ) {
    	$args = array( 'category__in' => array(1) );
    	$args = ( $wp_query && $wp_query->query ) ? array_merge( $wp_query->query , $args ) : $args;
    	query_posts( $args );
    }

    Update the 1 in array(1), to the ID of the category.

    The same could be done with just..

    if( is_home() ) query_posts( 'cat=1' );

    ..however it doesn’t account for preserving any query vars that exist for the query.. hence the slightly bulkier version above which should keep you covered.

    If that all seems too much at all, see the reply above mine.. 😉

    So, where would I post the `if( is_home() ) {
    $args = array( ‘category__in’ => array(1) );
    $args = ( $wp_query && $wp_query->query ) ? array_merge( $wp_query->query , $args ) : $args;
    query_posts( $args );
    }`

    in the index.php file?

    Another very simple solution…

    Use the home.php template file with a query_post from the category you wish to display…

    🙂

    S.

    I don’t have a home.php on my theme. Would that be index.php?

    Juste make a copy of your index.php and rename it home.php…

    Then, edit this file (home.php) to make a loop with query_post…

    It should do the trick.

    S.

    Yes or that, there’s usually lots of ways to do the same thing… 🙂

    There’s also the pre_get_posts method, but let’s not confuse a simple task for OP and leave that for another discussion..

    It’s stil not working. When I try to add that code into index.php or even home.php, it just shows up as code in the browser.

    It’s stil not working.

    Without knowing which method you’re trying to use, it’s hard to know how to help you, are you referring to the code i supplied further up?

    If so, you would need to ensure the code is placed inside the opening and closing PHP tags..

    This

    <?php

    and this..

    ?>

    Else, it’s going into the HTML section of the document which will just output the PHP code as text….

    To make things easier, you could just provide a copy of the file you want to adjust.

    http://wordpress.pastebin.ca/
    NOTE: This is a site for pasting code into, use this in place of the forum (especially for large pieces of code), and report the URL provided back here.

    I’ll then provide an updated version of the code to replace your existing one with, since it’s only a very minor change…

    Thank You! That was it, I did not put it in the PHP code. It works. Thanks for the help.

    No worries, you’re welcome.. 😉

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] How to use category as homepage’ is closed to new replies.