html sitemap via recursive function

I'm trying to render my page structure as an ordered list (<ol>) showing the hierarchy using nested ordered lists. So it should look something like <ol> <li> About <ol> <li> Leadership <ol> <li>CEO</li> <li>COO</li> </ol> </li> </ol> </li> <li>Services</li> <li>Products</li> </ol> or About Leadership CEO COO Services Products I created a function to get 1 level of pages which I call recursively for any pages with child pages. function aiv_get_sibling_pages($cur_page = null) { $front_page_id = get_option('page_on_front'); $next_page = $cur_page ? …
Category: Web

Why am I getting an infinite loop with have_posts?

I have the following code, which causes an infinite loop for some reason. Can anybody explain what's going on please? Thanks! <?php $flagged_stores = new WP_Query( array ( 'post_type' => 'store', 'orderby' => 'post_id', 'meta_key' => 'flagged', 'limit' => 10 ) ); if($flagged_stores->have_posts()): ?> <div class="table"> <table class="form-table"> <tr> <th>Store</th> <th>Flag Reason</th> <th>Delete Flag</th> </tr> <?php while($flagged_stores->have_posts()): ?> <td><?php echo the_title(); ?></td> <td><?php// echo get_post_custom_values('flagged'); ?></td> <td><?php// echo "Delete"; ?></td> <?php endwhile;?> </table> <?php else: ?> No flags found. <?php …
Category: Web

wp_insert_post wrong post type

Much like this question, I'm having trouble with wp_insert_post causing recursive post adding. I do, however, have implemented a page type check - the problem is the inserted post always gets added as the same type, no matter the type specified. function create_auto_post($post_ID) { if (get_post_type($post_ID) != 'manually-published') return; $post_ID = wp_insert_post( array( 'post_status' => 'publish', 'post_type' => 'automatically-published' ) ); } add_filter( 'save_post', 'create_auto_post', 1, 1); The inserted post is of type manually-published, therefore triggering a recursive insertion of …
Category: Web

How to get post count including nested categories

I am traversing through categories using function like this function hierarchical_term_tree($category = 0) { $r = ''; $args = array( 'parent' => $category, ); $next = get_terms('product_cat', $args); if ($next) { $r .= '<ul>'; foreach ($next as $cat) { $r .= '<li><a href="' . get_term_link($cat->slug, $cat->taxonomy) . '" title="' . sprintf(__("View all products in %s"), $cat->name) . '" ' . '>' . $cat->name . ' (' . $cat->count . ')' . '</a>'; $r .= $cat->term_id !== 0 ? hierarchical_term_tree($cat->term_id) : …
Category: Web

Get the last month with posts using a recursive function…

There is probably another way but I would like to understand why this code returns null... I only have posts in october and here's the recursive function: function last_post( $month,$year ) { $args = array( 'monthnum' => $month, 'year' => $year ); $query = new WP_Query( $args ); var_dump( $month ); // int 11, int 10 if( $query->have_posts() ){ return $args; } else { last_post( $month-1, $year ); // here is the problem ? } } $args = last_post( 11, …
Category: Web

Is there any good reason for two CSS files to @import each other?

I'm working on some critical style revisions for a client's WordPress site that was designed by another team. The CSS seems to be a tangled mess. One of the idiosyncrasies I've found is that the theme's main stylesheet style.css, @imports another stylesheet from a subdirectory: css/default.css. Meanwhile, default.css @imports the main stylesheet at the top of its file too. I removed the @import directives and added the content of the default.css to style.css, but that breaks the layout regardless of …
Category: Web

How to show only parents subpages of current page item in vertical menu?

I just can't find a way to make it possible to show only current parent items down to current page item in a vertical menu the "wordpress way". What I want to achieve is the following dynamic structure, if I visit Page 3.2.2.2: Page 1 Page 2 Page 3 Page 4 Page 3.1 Page 3.2 Page 3.2.1 Page 3.2.2 Page 3.2.2.1 Page 3.2.2.2 Page 3.2.2.2.1 Page 3.2.2.2.2 Page 3.2.2.3 Page 3.2.3 Page 3.3 Page 3.4 Page 3.5 So, only submenus …
Category: Web

Pushing stored procedure to a multisite database in WordPress

I am given a WordPress multisite and need to extract information from the site. I have written a stored procedure that recursively builds a tree relationship for posts of a certain kind. Now I am wondering how to push the stored procedure to the databases of all the sites.(Since this is a multisite configuration, each site(subdomain in this case) has a separate database.) Please help me in this regard. WordPress version: 3.5.1 Multisite config type: subdomains //code needs refinement DELIMITER …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.