WordPress automatic and permanent page

Yes, that is doable. I don’t know about running scripts immediately after WP installation is complete, but you could implement your idea perhaps with a must-use plugin. First you probably want some kind of way to get the contact page id. A helper function for that, function get_my_contact_page_id() { return get_option( ‘my_contact_page’, 0 ); // … Read more

Category page showing posts from all categories

That happens because you are overwriting the query with you $args, If you want to modify it and not overwrite it then use this format: //get the $query_string in to your $args array global $query_string; parse_str( $query_string, $args ); //modify whatever you want $args[‘post_type’] = ‘post’; $args[‘posts_per_page’] = 5; $args[‘orderby’] = ‘comment_count’; query_posts($args);

Slugs as breadcrumbs for Pages

Ok, problem solved. I´ll add the script below. Hope it´s useful for someone. if ( is_page() ) { $post = $wp_query->get_queried_object(); if ( $post->post_parent == 0 ){ echo “<li> &raquo; “.ucwords(str_replace(“-“, ” “, $post->post_name)).”</li>”; } else { $title = the_title(”,”, FALSE); $ancestors = array_reverse( get_post_ancestors( $post->ID ) ); array_push($ancestors, $post->ID); foreach ( $ancestors as $ancestor … Read more

Hard Code Pages into a Theme for a Network (multisite) Installation

Hook into wpmu_new_blog and create your pages: add_action(‘wpmu_new_blog’, ‘create_my_pages’, 10, 2); function create_my_pages($blog_id, $user_id){ switch_to_blog($blog_id); // not really need, new blogs shouldn’t have any content if(get_page_by_title(‘About this Network’)) return; // create each page $page_id = wp_insert_post(array( ‘post_title’ => ‘About this Network’, ‘post_name’ => ‘about-this-network’, ‘post_content’ => ‘Co za asy…’, ‘post_status’ => ‘publish’, ‘post_author’ => $user_id, … Read more

posts page – different lengths of excerpt

First, you need to filter excerpt_length. Assuming you want your default excerpt length to be 50 words: <?php function wpse53485_filter_excerpt_length( $length ) { return 50; } add_filter( ‘excerpt_length’, ‘wpse53485_filter_excerpt_length’ ); ?> That will make all excerpts 50 words. Make sure that works first. Then, add in an appropriate conditional, to use a different excerpt length … Read more

How to display error messages using WP_Error class?

With that in functions.php you’d probably have to declare $error to be global like so : if (‘POST’ == $_SERVER[‘REQUEST_METHOD’] && !empty($_POST[‘action’]) && $_POST[‘action’] == ‘registration’) { global $error; $error = new WP_Error(); // the rest of your code And then do global $error; again on your registration page before trying to use it. But … Read more

List all pages and children in separate ul

your code is missing the = after child_of <?php $args = array( ‘sort_column’ => ‘menu_order’, ‘parent’ => 0, ); $pages = get_pages($args); foreach($pages as $page){ ?> <ul> <li> <?php echo ‘<a href=”‘ . get_permalink( $page->ID ) . ‘”>’ . $page->post_title . ‘</a>’; ?> </li> <?php wp_list_pages(‘title_li=&depth=0&child_of=”.$page->ID.”‘); ?> </ul> <?php } ?> if you want to … Read more

How to count current user’s pages?

Look what count_user_posts() does inside and change the post type parameter: global $wpdb; // ‘page’ is the important part here $where = get_posts_by_author_sql(‘page’, true, $userid); $count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts $where” ); Then you change your snippet to: global $wpdb; $user = wp_get_current_user(); $where = get_posts_by_author_sql( ‘page’, true, $user->ID ); $count = $wpdb->get_var( … Read more

How does wordpress calculate the page depth?

Ok, lets break it down, all the links are going to be to the source code. wp_list_pages() only uses get_pages() to (sic!) get pages, walk_page_tree() does the hierarchical structuring inside it. The further course of the process goes Walker_Page – and the generic Walker of course -, unless a custom walker is used. Inside walk_page_tree() … Read more