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

Loop to pull content from parent element in custom post type [duplicate]

Use the following to change the query from querying the current page to querying the parent of the current page: query_posts( ‘p=’.$post->post_parent ); That will change the $wp_query object to hold only the parent of the current post. Note: this is untested. update You can also do it with a custom WP_Query as so: $args … 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

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