The following creates a loop of custom post types. This example creates a testimomnials block.
<?php $loop = new WP_Query( array( 'post_type' => 'testimonial',
'posts_per_page' => 4 )
); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$clientname = (types_render_field( "client-name", array( 'raw' => true) ));
$quote = (types_render_field( "quote", array( 'raw' => true) ));
?>
<p><?php echo $quote; ?> <span><?php echo $clientname; ?></span></p>
<?php endwhile; wp_reset_query(); ?>
Put the following in the themes functions.php file:
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
Test it using the following conditional within your theme:
<?php if (is_blog()) { echo 'You are on a blog page'; } else { echo 'no blog'; } ?>
Take a look in the themes comments.php file and you will see a line where the comments area is called in using:
<?php comment_form(); ?>
In some cases I found it was contained within a conditional like this:
if ( comments_open() ) comment_form();
You can replace it with the following code, injecting in any modifications to the fields as you need:
if ( comments_open() ) { ?>
<?php $comment_args = array( 'title_reply'=>'Leave a reply',
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' =>
'<div class="row">
<div class="large-4 columns comment-form-author">' .
'<input id="author"
name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' placeholder="Name*" />
</div>',
'email' =>
'<div class="large-4 columns comment-form-email">' .
'<input id="email" name="email" type="text"
value="' . esc_attr( $commenter['comment_author_email'] ) .
'" size="30"' . $aria_req . ' placeholder="Email*" />
</div>',
'url' =>
'<div
class="large-4 columns comment-form-url">' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" size="30"
placeholder="Website" />
</div>
</div>', )
),
'comment_field' => '<div>' .
'<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" placeholder="Comment*"
></textarea>' .
'</div>',
'comment_notes_after' => '',
);
comment_form($comment_args); ?>
<?php } ?>
This function tells WordPress to remove the default more which looks like this: […], and replace it with a link.
Open your functions.php file, and paste the following code inside the php tags:
Note: check your parent theme to find the appropriate function to be removed.
function child_theme_setup() {
// override parent theme's 'more' text for excerpts
remove_filter( 'excerpt_more', 'blankslate_excerpt_read_more_link' );
remove_filter( 'get_the_excerpt', 'blankslate_excerpt_read_more_link' );
}
add_action( 'after_setup_theme', 'child_theme_setup' );
// Replaces the excerpt "Read More" text by a link
function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
The following code inserted into your child themes functions.php file will create two new widget areas called banner and dropmenu:
/**
* Register our sidebars and widgetized areas.
*
*/
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'banner',
'id' => 'banner',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => 'dropmenu',
'id' => 'dropmenu',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
Create a hook in your theme by using the following:
<?php dynamic_sidebar( 'dropmenu' ); ?>
Here is a quick and wasy way to display the page heading inside a wordpress template:
<h1 class="pageheading"><?php global $post;
echo $post->post_title; ?></h1>
Sometimes when trying to log into the wordpress back end I get the dreaded whitescreen of death. This is usually caused by a plugin. The solution is usually realtively painless: disable all the plugins. This fixes the admin login whitescreen issue. Plugins can then be enabled individually, checking to see which plugin breaks the login page.
The following is a conditional to do something if the post is contained within wither of these three categories:
<?php if (in_category( array( gallery,this,another ) )) {
echo 'BINGO!!';
} ?>
Before you proceed, please note that the code below will remove featured images from all posts on your WordPress site by simply just pasting. Also note that this code will not delete any of your uploaded images, they will still be available in Media Library and you can reuse them anytime.
All you need to do is copy and paste this code in your theme’s functions.php file.
global $wpdb; $wpdb->query( " DELETE FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id' " );
As soon as you save your functions.php file this script will run a database query and remove featured images from all posts.
Important: Please remove this code immediately after saving your functions.php file. You will not be able to set featured images in WordPress as this code will keep removing featured images from posts.
A client needed the events calender to display shortened day headings in the monthly view. Here are two possible solutions:
$days_of_week = tribe_events_get_days_of_week();
$days_of_week = tribe_events_get_days_of_week( true );
<th id="tribe-events-<?php echo strtolower($day) ?>" title="<?php echo $day ?>"><?php echo substr($day, 0, 3); ?></th>