This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $args = array( | |
| 'posts_per_page' => 40, | |
| 'post_type' => 'page' | |
| ); | |
| $posts = get_posts( $args ); | |
| if ( $posts ) { | |
| $count = count( $posts ); | |
| $counter = 1; // Start the counter at 1 | |
| $cols_per_row = 4; // How many columns do you want per row? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function get_post_type_name( $term_id ) { | |
| // Here we use the term id to identify the name of the post type the related taxonomy is registered to | |
| $term = get_term( $term_id ); | |
| $taxonomy = $term->taxonomy; | |
| $tax_object = get_taxonomy( $taxonomy ); // Get the taxonomy object | |
| $post_types = $tax_object->object_type; // Get the object type (as an array) the taxonomy is registered to | |
| $post_type_object = get_post_type_object( $post_types[0] ); // Use the object type to get details on the object type | |
| $post_type_name = $post_type_object->labels->name; // Get the name label of the the object | |
| return $post_type_name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Function to check if post has any parents | |
| function is_bastard() { | |
| global $post; | |
| $parent = $post->post_parent; | |
| if( $parent == 0 ) { | |
| return true; | |
| } else { | |
| return false; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // True or false function to check for child pages | |
| function has_children() { | |
| global $post; | |
| $children = get_pages( | |
| array( | |
| 'child_of' => $post->ID | |
| ) | |
| ); | |
| if( count( $children ) == 0 ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Function to return parent page title | |
| function parent_title() { | |
| global $post; | |
| $parent_id = wp_get_post_parent_id( $post->ID ); | |
| $parent_post = get_post( $parent_id ); | |
| $parent_post_title = $parent_post->post_title; | |
| return $parent_post_title; | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function parent_template() { | |
| global $post; | |
| $parent_id = wp_get_post_parent_id( $post->ID ); | |
| $parent_template_name = get_page_template_slug( $parent_id ); | |
| return $parent_template_name; | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $childpages = get_pages( | |
| array( | |
| 'child_of' => $post->ID, | |
| 'parent' => $post->ID | |
| ) | |
| ); | |
| foreach( $childpages as $page ) { | |
| $page_title = $page->post_title; | |
| $page_link = get_page_link( $page->ID ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Generating a meta description using standard WP components | |
| function meta_description( $char_limit ) { | |
| $tagline = get_bloginfo ( 'description' ); | |
| $post_object = get_post(); | |
| $excerpt = $post_object->post_excerpt; // Get the raw excerpt, warts (tags) and all. | |
| $content = $post_object->post_content; // Get the raw content. | |
| if ( !empty( $excerpt ) ) { // If there is an excerpt lets use it to generate a meta description | |
| $excerpt_stripped = strip_tags( $excerpt ); // Remove any tags using the PHP function strip_tags. | |
| $excerpt_length = strlen( $excerpt_stripped ); // Now lets count the characters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function trim_the_excerpt( $char_limit, $ellipsis = true ) { | |
| $excerpt = get_the_excerpt(); | |
| $excerpt_stripped = strip_tags( $excerpt ); // Remove any tags using the strip_tags function. | |
| $excerpt_length = strlen( $excerpt_stripped ); // Now lets count the characters so we can compare | |
| if ( $excerpt_length > $char_limit ) { // Now work out if we need to trim the character length. | |
| $offset = $char_limit - $excerpt_length; // This gives us a negative value. | |
| $position = strrpos( $excerpt_stripped, ' ', $offset ); // This starts looking for a space backwards from the offset | |
| $trimmed_excerpt = substr( $excerpt_stripped, 0, $position ); // Trim up until the point of the last space. | |
| $last_character = substr( $trimmed_excerpt, -1 ); // Identify the last character of the newly trimmed excerpt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if( have_rows('repeater_field_name') ): | |
| echo '<ul>'; | |
| while( have_rows('repeater_field_name') ): the_row(); | |
| $name = get_sub_field('name'); | |
| echo '<li>'; | |
| echo '<h3>' . $name . '</h3>'; | |
| echo '</li>'; | |
| endwhile; | |
| echo '</ul>'; |