Check if password protected post is visible
post_password_required(): whether post requires password and correct password has been provided. <?php if ( post_password_required() ) { echo ‘xxx’; } else { echo ‘zzz’; }
post_password_required(): whether post requires password and correct password has been provided. <?php if ( post_password_required() ) { echo ‘xxx’; } else { echo ‘zzz’; }
The Codex page for is_single should be updated, what you’re seeing is correct behavior. According to the main Conditional Tags Codex page: is_single() When any single Post (or attachment, or custom Post Type) page is being displayed. (False for Pages) You can exclude attachments by also checking ! is_attachment(). Also, you may want to move … Read more
Check for global variable $wp_customize: if ( empty ( $GLOBALS[‘wp_customize’] ) ) { // show something } Update: in WordPress 4.0, you can use is_customize_preview().
From look at the code the following logic happens in your case: query is for one post type that has archive is_post_type_archive gets set to true is_archive gets set to true is_home gets set to false since it is seen as archive I am not sure about all implications without extensive testing, but probably approaches … Read more
$posts = get_posts(array(‘name’ => ‘your-posts-name’, ‘post_type’ => ‘faq’)); foreach ($posts as $post) { $title = get_the_title($post->ID); $permalink = get_permalink($post->ID); break; //use this to limit to a single result }
A template tag is just a function, so I can’t understand the difference from a function in functions.php and a template tag. So the choiches are 2: function VS file. The right choice depend case by case, and all things @shazzad pointed found me agree. I prefer use file and get_template_part when the code need … Read more
Yep, wp_trim_words(): <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?> Or in your case: <?php echo apply_filters( ‘the_content’, wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>
function register_tag_styles() { wp_register_style( ‘tag-circulair-template’, get_stylesheet_directory_uri() . ‘/layout-circulair.css’ ); wp_register_style( ‘tag-circulair-kantoor-template’, get_stylesheet_directory_uri() . ‘/layout-circulair.css’ ); } add_action( ‘wp_enqueue_scripts’, ‘register_tag_styles’ ); This code does the trick for me, but i think it’s too complicated when i have more than 10 tags with different stylesheets…..
How I have done custom queries in the past is use $wpdb->get_col() and just returned an array of IDs of the posts. Then I pass that to a get_posts() passing the IDs to the post__in parameter. That way you can then use WP standard controls.
Try this: $posttags = get_the_tags(); $count=0; if ($posttags) { foreach($posttags as $tag) { $count++; echo ‘<a href=”‘.get_tag_link($tag->term_id).'”>’.$tag->name.'</a> ‘; if( $count >4 ) break; } }