- This topic has 12 replies, 3 voices, and was last updated 14 years, 8 months ago by imported_Ryan.
-
AuthorPosts
-
January 6, 2010 at 5:20 am #1171buncleMember
I have some subcategories which all have the same parent category, each with their own posts. When the categories are displayed in the PixoPoint menu, they are duplicated both in their correct subcategory *and* the parent category.
Example:
Parent
– SubCategory A
– Cat A Page 1
– Cat A Page 2
– Cat A Page 3
– SubCategory B
– Cat B Page 1
– Cat B Page 2
– Cat B Page 3
– SubCategory C
[i:1n8he7ig] – Cat A Page 1
– Cat A Page 2
– Cat A Page 3
– Cat B Page 1
– Cat B Page 2
– Cat B Page 3[/i:1n8he7ig](Those in italics I don’t expect to be there, as they aren’t directly children of ‘Parent’, but of the subcategories)
Am I missing something obvious?
Thanks in advance!
January 6, 2010 at 5:32 am #7535imported_RyanMemberWeird. What settings are you using in the plugin for the categories.
January 6, 2010 at 6:45 am #7536buncleMemberDropdowns: Infinite
Empty categories? Yes
Single dropdown? No
Show child posts? YesI have found a fix, however I’m not sure whether it is the correct way to go about it…
Inside core.php within the categories_and_posts function, I have added the following code:
[font=courier:3e6yjajm]foreach($posts as $current_post){
[i:3e6yjajm][b:3e6yjajm]if ($current_post->post_parent == $category->cat_ID)
{[/b:3e6yjajm][/i:3e6yjajm]
echo '<li class="post-item post-item-' . $current_post->ID . '"><a href="' . get_permalink($current_post->ID) . '" title="' . $current_post->post_title . '">' . $current_post->post_title . "</a></li>";
[i:3e6yjajm][b:3e6yjajm]}[/b:3e6yjajm][/i:3e6yjajm]
}[/font:3e6yjajm](My changes [i:3e6yjajm][b:3e6yjajm]emboldened[/b:3e6yjajm][/i:3e6yjajm])
January 6, 2010 at 7:46 am #7537imported_RyanMemberThanks ” title=”Smiley” />
I need to get some urgent work done right now, but I’ll take a look at this later on and if your fix works I’ll commit it to the repository as a bug fix.
If I don’t reply within the next 24 hours then it’s because I forgot about this. Just keep pestering me as this sounds like a legitimate bug report (most aren’t).
January 6, 2010 at 3:51 pm #7538buncleMemberJust a little more information for you ready for when you take a look into this…
This issue only occurs when ‘Show Child Posts’ are enabled. This also seems to be a long standing WordPress issue/feature(?) too – http://en.forums.wordpress.com/topic/hiding-a-child-categorys-posts-when-a-parents-posts-are-displayed%5B/url:2o7dt68a%5D
It seems the issue is down to ‘get_posts()’ returning posts from all descendant categories. By adding the condition above, it is working around the issue.
I am incredibly new to WordPress and PHP is not my usual language, so I may be making some incorrect assumptions, but I suspect there may be a way of changing the post query to ensure that get_posts only returns posts of the current depth (which would negate the need for my workaround).
(P.S. I’m happy to help by the way. I know how exasperating it can be providing support for your code. Also, by looking into problems myself, its helping me familiarise myself with WP and PHP ” title=”Smiley” /> )
January 6, 2010 at 5:49 pm #7539buncleMember(Just spotted… my workaround it flawed. I’m using $category->cat_ID outside of the scope where $category is defined. Looking at an alternative now)
January 6, 2010 at 6:36 pm #7540buncleMemberI believe I have found a correct fix for this issue. Instead of the workaround I mentioned earlier (which ended up being incorrect anyway), I have replaced the following line (in ‘categories_and_posts()’):
$posts = ($parent ? get_posts("category=$parent&numberposts=-1") : array());
with:
$posts = ($parent ? get_posts(array(‘category__in’ => array($parent), ‘numberposts’ => ‘-1’,)) : array());
The WordPress reference guide mentions that ‘category__in’ does *not* return grandchildren of the specified parent (which is the behaviour we want), however it seems that using ‘cat’ or ‘category’ does.
Feel free to point out anything wrong with this. As I mentioned earlier, I’m still learning ” title=”Smiley” />
January 7, 2010 at 6:08 am #7541buncleMember…Just chiming in with a quick 24hr reminder! ” title=”Wink” />
January 7, 2010 at 7:50 am #7542imported_RyanMemberOut of time. Haven’t forgotten though.
February 4, 2010 at 8:44 pm #7543AnonymousMemberI can confirm this bug. Thanks so much for fixing it, buncle; I was about to go mad dealing with this terrible software (WordPress, that is, not the plugin).
March 23, 2010 at 6:13 pm #7544AnonymousMemberBuncle – I’m having the same issue where children are showing up multiple times. If I have a child in a level 3 menu the child shows up in level 1, level 2 and level 3. I’m wondering if you found a final work around that you’d recommend for me.
Thanks much
Bob"buncle" wrote:I believe I have found a correct fix for this issue. Instead of the workaround I mentioned earlier (which ended up being incorrect anyway), I have replaced the following line (in ‘categories_and_posts()’):$posts = ($parent ? get_posts("category=$parent&numberposts=-1") : array());
with:
$posts = ($parent ? get_posts(array(‘category__in’ => array($parent), ‘numberposts’ => ‘-1’,)) : array());
The WordPress reference guide mentions that ‘category__in’ does *not* return grandchildren of the specified parent (which is the behaviour we want), however it seems that using ‘cat’ or ‘category’ does.
Feel free to point out anything wrong with this. As I mentioned earlier, I’m still learning ” title=”Smiley” />
March 24, 2010 at 5:21 pm #7545AnonymousMemberIs there a good fix for this issue yet?
March 30, 2010 at 12:22 pm #7546imported_RyanMemberThe latest beta should fix that issue:
https://geek.hellyer.kiwi/pixopoint-menu-plugin-beta-0-8/If it doesn’t, please let me know ” title=”Smiley” />
-
AuthorPosts
- You must be logged in to reply to this topic.