WordPress.org

Ready to get started?Download WordPress

Forums

Trouble with homepage defaulting to a catagory (3 posts)

  1. endangermice
    Member
    Posted 1 year ago #

    Hi Guys,

    I'm trying to make it so a blog I'm developing will default to a particular category when a user types in the root url e.g. http://www.endangermice.co.uk. While I can use the code:

    if (is_home()) { query_posts("cat=945"); }

    to make it go straight to the podcasts category, the problem is that the URL doesn't change to represent the podcasts section i.e. it appears as

    http://www.endangermice.co.uk

    and not

    http://www.endangermice.co.uk/category/podcasts/

    This isn't a problem until I try to use the next-posts-link and previous-posts-link functions to cycle through pages containing diffwerent posts in the category. If I'm sitting on the home page, the url becomes http://www.endangermice.co.uk/page/2/ when I press the next link generated by next-posts-link. This means that nothing happens since the actual url should be http://www.endangermice.co.uk/category/podcasts/page/2.

    How can I make it so that the next-posts-link function will work when I land on the homepage and default to a category?

    Hope this makes sense,

    Thanks,

    Damien.

  2. Chris
    Member
    Posted 1 year ago #

    You could do a proper auto-redirect on your homepage:

    $categoryLink  = get_category_link( $categoryID );
    wp_redirect( $categoryLink, 301 );
    exit;
  3. endangermice
    Member
    Posted 1 year ago #

    Chris,

    That's absolutely perfect, a very simple solution. I can't believe I didn't think of this myself!

    Thank you so much for this.

    Cheers,

    Damien.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.