bobby_baboon
Forum Replies Created
-
Forum: Plugins
In reply to: wp_list_pages links to first childI came across this problem last night and here is how I solved it. My client wanted it so if you clicked on a parent in the menu you would be linked to the first child. Not in this example the menu only shows parents:
function gl_list_pages() { $pages = wp_list_pages('echo=0&sort_column=menu_order&depth=1&title_li='); $pages = explode("</li>", $pages); $children = get_pages('sort_column=menu_order'); $childrenParent = array(); foreach ($children as $child){ //we're going to loop through all of the pages and get rid of any that aren't children. if ($child->post_parent == 0) continue; $childrenParent[$child->post_parent] = $child; } $count = 0; foreach($pages as $page) { foreach ($childrenParent as $child){ //now we're going to find the link to the parent and replace it with a link to the first child if (strstr($page,'page-item-'.$child->post_parent)){ $newurl = 'href="'.get_permalink($child->ID).'"'; $page = preg_replace('/href="(.*)\/"/',$newurl,$page); } } $pages[$count] = $page; $count++; } $pages = implode('</li>',$pages); echo $pages; }
I’m sure someone with a better grasp of php could make this code have a few less loops in it, but this worked for my situation.
Forum: Plugins
In reply to: [Plugin: MobilePress] Change default homepageI’m wondering the same thing…
Forum: Fixing WordPress
In reply to: Order posts by most comment dateI’m looking for the same thing. If anyone knows an answer it would be super helpful!
Forum: Fixing WordPress
In reply to: Add Avatar for Admin and AuthorsSimplest way I know is to go here: https://en.gravatar.com/ and upload your image. Then set your email address to the same email address you used for creating your gravatar and all should be well.
Forum: Fixing WordPress
In reply to: Sub Sub Pages – Showing Main Parent DynamicallyI struggled with this same thing. Luckily, I was just able to solve it since it was hard to find solutions online. This post helped me immensely…
What I did was use his breadcrumb functions and put them in my functions.php
function get_parent_id ( $child = 0 ) { global $wpdb; // Make sure there is a child ID to process if ( $child > 0 ) { $result = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID = $child"); } else { // ... or set a zero result. $result = 0; } // return $result; } function get_ancestor_ids ( $child = 0, $inclusive=true, $topdown=true ) { if ( $child && $inclusive ) $ancestors[] = $child; while ($parent = get_parent_id ( $child ) ) { $ancestors[] = $parent; $child = $parent; } // If there are ancestors, test for resorting, and apply if ($ancestors && $topdown) krsort($ancestors); if ( !$ancestors ) $ancestors[] = 0; // return $ancestors; }
Then in my header I checked to see if the pages top-most ancestor matched my pages ID. So first I added this to header.php:
<?php $ancestors = get_ancestor_ids($post->ID, false);//call to function in functions.php $grandparent = $ancestors[1]; // find the grandparent ?>
Then on my link to a page my code would look like this:
<?php if ( is_page('about') || $grandparent == '2' || $post->post_parent == '2' ) { echo " class=\"active\""; } ?>
I imagine you don’t need to also have the $post->post_parent in there since the grandparent would just be the parent when you’re only one level deep…
Hope this helps!
Forum: Plugins
In reply to: Limit Categories by Owen Winkler