How do I reformat this to add php inside php?

As PHP documentation says Often you’d want to have more than one statement to be executed conditionally. Of course, there’s no need to wrap each statement with an if clause. Instead, you can group several statements into a statement group. So You have to use curly braces {} to add more statement within if else … Read more

Conditional sidebar menu

Bainternet’s solution will definitely work, but it you want to use the page slug instead of ID you could put this in your functions.php file: // GET PAGE ID FROM THE SLUG, HELPER FUNCTION FOR IS_TREE function get_ID_by_slug($page_slug) { $page = get_page_by_path($page_slug); if ($page) { return $page->ID; } else { return null; } } // … Read more

Create citation and url in post using 3 custom fields with conditions for each field… So close!

I’m not sure if I’m meeting all of your requirements here, but I think this might work. <div class=”source”> <?php $name = get_post_meta($post->ID, ‘sourcename’, true); $url = get_post_meta($post->ID, ‘sourceurl’, true); $title = get_post_meta($post->ID, ‘sourcetitle’, true); $snippet = str_replace( “http://”, “”, $url ); $snippet = substr( $snippet, 0, 22 ) . “…”; if ( !empty( $title … Read more

Template tag for /page/# structure

WordPress provides is_paged() which returns true on any archive or blog that stretches over multiple pages. This isn’t what you want, but the is_paged Codex article tells us where to go: If you need to check which page of the blog you are on, you can look in $wp_query->query_vars[‘paged’]. Remember that inside functions you might … Read more

How do I add a nested conditional within an echo – to use a default image if there isn’t one in the post?

try this $second_query = new WP_Query( $args ); if ( $second_query->have_posts() ): while( $second_query->have_posts() ) : $second_query->the_post(); $attachment_id = get_field(‘image’); $size = “customfeatins”; // (thumbnail, medium, large, full or custom size) $my_image = wp_get_attachment_image_src( $attachment_id, $size ); if (!my_image !== ”){ $image = $my_image[0]; } else { $image=”http://domain/image_source/your_image.jpg”; } endif; echo ‘<article> <img src=”‘ . … Read more

Subpage Conditional

Hmm, I’ll take a crack at this. There’s a few ways to go about this. Check to see if page is a direct child, check if it is an ancestor. Something like below might work for you if (283 == $post->post_parent) { echo ‘this post has a parent of 283 so do this’; }else { … Read more