I just installed something that will arrange my posts based on how many Facebook likes it gets. I’m using the code from http://peterbending.com/wordpress/how-to-order-posts-by-number-of-facebook-likes/
I have it setup on my test site: iconfirmation.org
Instead of needing to create a new page template for each category, I decided to edit the category.php in my theme. My only issue is with this string:
$featuredPosts1->query('cat=1&posts_per_page=10&meta_key=_my_key&orderby=meta_value&order=desc&paged='.$paged); while ($featuredPosts1->have_posts()) : $featuredPosts1->the_post(); ?>
At the beginning of the string, it says ‘cat=1’
When I was creating a different page for each category, this was where I would change which category to show, but now, I want it to automatically select the category id based on which category I’ve opened.
For example, if I go to iconirmation.org/category/test it would show it’s posts and when I go to iconirmation.org/category/likes it shows it’s posts.
I have literally scoured google trying to find a code that would work, but nothing does! Can anyone help?
Thanks so much!
Not really sure if you have got your answer by now. As the post is kinda old, I should assume so.
Whenever a wordpress page is visited on your website, some variables are used to query the database so it can generate the page content. There’s a nice way to check the variables in a particular page.
Just add the line:
This will display the array of variables on that particular page so you can find out which ones you need to retrieve using something like:
$variable = get_query_var('variable_name');
In your particular case, to retrieve the category ID, you should use the variable called ‘cat’.
It would look like this
$cat = get_query_var('cat');
After storing the category ID to your variable called ‘$cat’, just add it to your quuery. Here is the code…
$featuredPosts1->query('cat=' . $cat .'&posts_per_page=10&meta_key=_my_key&orderby=meta_value&order=desc&paged='.$paged);
Not sure if that’s what you were looking for, but I think it might be of some help to someone.
- The topic ‘Sort Posts by Facebook Likes…sort of working, But I need help.’ is closed to new replies.