WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Redirecting? (8 posts)

  1. armstrong1118
    Member
    Posted 6 years ago #

    I was wondering if anyone might be able to help me out.

    I am trying to automatically redirect my category-16.php on loading to a specific post within the category.

    I need it to go to the category page first so that the url registers (the post page pulls a sidebar dependent on the referring url) but then I would like to to go directly to the post of my choice within the category.

    Is it possible with just a bit of code, or do I need a plug-n or something?

    Thanks

  2. Jeremy Clark
    Moderator
    Posted 6 years ago #

    Your making it harder than needed. You just need to use this conditional tag. You can use something like this on your sidebar.php file.

    <?php if ( in_category('16') ): ?>
    Put your category's sidebar information here.
    <?php endif; ?>
  3. armstrong1118
    Member
    Posted 6 years ago #

    Im not sure if that will work. My posts fall under many categories each, I have it set up to put posts from the same category in the sidebar, based on which category archive they used to access the post.

    Im using $_SERVER['HTTP_REFERER'] to get that information. I just remembered that there was a flaw where unless you click a link, the referring url doesnt register. So it wouldnt register the url from the archive anyway.

    So it looks like im out of luck on this solution, off to find another one.

    Thanks

  4. Jeremy Clark
    Moderator
    Posted 6 years ago #

    I imagine the answer is somewhere.

  5. moshu
    Member
    Posted 6 years ago #

    I have difficulties getting my head around this whole idea...
    If you would use any kind of "redirect" - that means your category #16 posts can never be listed (as they normally would in category archive view). So, what's the point?

    Or, why not show ONLY that one favourite post of yours in that template file?

    Sorry, I just don't see the reason for all this complication...

  6. armstrong1118
    Member
    Posted 6 years ago #

    jeremy--

    Sorry, I misunderstood you, the in_category is much simpler than what I was doing. I thought that you were saying to use is_category. Sorry again, you actaully helped me out huge.

    moshu --
    Do you know where I can find a resource on showing just a single post on the category page?

  7. moshu
    Member
    Posted 6 years ago #

    Delete the Loop and use get_a_post plugin.
    That's one way. I guess you could also write your own query_posts based Loop.

  8. Jeremy Clark
    Moderator
    Posted 6 years ago #

    You can look here.
    http://codex.wordpress.org/Theme_Development#Theme_Template_Files_List
    http://codex.wordpress.org/Category_Templates

    Basically all you need to do is if you theme doesn't already have a category.php file then you need to create it. A good start is to copy the contents of the main.php and then edit out what you don't need. Also if you only need the template to be different for this one category make the file category-16.php

    Then you need to edit the loop. Resources for that.
    http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.