- This topic is empty.
April 16, 2010 at 1:32 pm #28691jackosborneMember
I’ve created a custom page and it is set as my homepage, within this custom page I am pulling out the latest post from a specific category, I’ve also created a form of pagination which when clicked upon will take the user to single.php. My intention for the single.php is to have two custom loops.
Custom loop one
I want single.php to distinguish that it has came from the homepage and loop through all of the posts tagged with the same category as the one on the homepage.
Some of these posts will have to be tagged with more than one category, so the loop will have to know to ignore the other categories and just pay attention to the category in question. Does that make sense?
Custom loop two
If the user hasn’t arrived from the homepage, single.php will just act as it normally does i.e, if the user comes from index.php (the blog) they will be taken to this second loop (blog post)
However I don’t seem to be able to make the distinction between the two loops, I might be over complicating matters, as I’ve got a loop which wraps everything together and then I have a loop for my custom pagination.
Here is the code below to show you what I’m talking about
custompage.php (set to home) – This works just fine but I’ll post it just incase anyone is able to tidy it upCode:
if (have_posts()) :
while ($myPosts->have_posts()) : $myPosts->the_post();
single.php – Currently brokenCode:
$.backstretch("ID, $key, true);?>");
id=”post-“>Read the rest of this entry »
Sorry, no posts matched your criteria.
Any help would be greatly appreciated. Cheers!May 5, 2010 at 8:26 pm #75134Chris CoyierKeymaster
I think the fundamental weirdness here is the idea that you want to use single.php for all of this. I think I’d just have the links from your homepage link to another custom template that handles your special category loop stuff. So for the homepage likeCode:
/special-area/ would be some published page that uses a special page template just for this purpose. That special page would use a special page template, which would snag the variable out of the URL like $cat = $_GET. Just sanitize the shit out of that…
Then you could use that category ID to run your loop, likeCode:query_posts(“cat=$cat”);
So now you have a special page for your homepage links to point to, but everywhere else on the site can use the regular single.php template with no fancy alterations.
Although now that I’m thinking about this. If you are trying to link to a page that has a list of posts of a particular category from the homepage, why not just use the default like
Which basically uses the archive.php template…Code:
etc. etc.AuthorPostsViewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘Back End’ is closed to new topics and replies.