Basically, I need for the image at the bottom of the page with no text wrapped around it to be in the place of test post 4 (it's going to be a Google Adsense block but I am using images as a placeholder for now). I'm not sure how to do this, right now the code is the following:
<div class="google_ad_post">
<?php if ($count == 3) { ?>
<br /><img src="****" alt="post ad">
<?php } ?>
<?php $count++; ?>
</div>
Yet, the image is still at the bottom of the page. How can I fix this?
Here is the image:
I can't post pictures just yet so the URL to the image is http://i.imgur.com/7rw5B.jpg
I have to see your code to help you better with the Scripting Part, but something logical like this should work:
<?php
$count = 0;
foreach( $posts as $post ) : ?>
<?php if ($count == 3) { ?>
<div class="google_ad_post">
<img src="****" alt="post ad">
</div>
<?php } else { ?>
<div class="post" id="post-<?php the_ID(); ?>><div class="content"><?php the_content(); ?></div>
<?php } ?>
<?php $count++; ?>
<?php endforeach; ?>
Related
I am attempting to display the correct HTML under a "p" tag with PHP based on a true/false value which is pulled from WordPress ACF plugin, for every individual post. It's my first time using PHP and I'm not sure how to go about this.
My code is:
<p class="applied-grid-filter">
<?php if (the_field('relocation', $job->ID) === 1) ?>
</p>
Currently, if the post has "relocation" marked as false - an empty applied-grid-filter "p" tag appears. If the post has "relocation" marked as true - an applied-grid-filter "p" tag with the number "1" for true appears.
How can I make it so that when it is marked false, no P tag is made at all - and when the post is marked true, a P tag with textcontent of "Relocation" is made?
edit full context:
<section class="job-search-grid">
<?php if (count($jobs)) { ?>
<div class="job-search-grid-container">
<?php foreach ($jobs as $job) { ?>
<div class="job-search-grid-item">
<h2 class="job-search-grid-title"><?= esc_html($job->post_title) ?></h2>
<div class="salary-location-container">
<h2 class="job-search-grid-salary"><?php the_field('minimum_salary', $job->ID) ?>K
- <?php the_field('maximum_salary', $job->ID) ?>K</h2>
<div class="job-search-location-icon-container">
<img
class="job-search-location-icon"
src="<?= get_template_directory_uri() ?>/assets/location-icon.png"
/>
<p class="job-search-grid-location">Louisville, KY</p>
</div>
</div>
<p class="job-search-grid-description">
<?php the_field('short_description', $job->ID) ?>
</p>
<div class="applied-grid-filters">
<?php foreach (get_terms('industry', ['object_id' => $job->ID]) as $term) { ?>
<p class="applied-grid-filter"><?= esc_html($term->name) ?></p>
<?php } ?>
<?php foreach (get_terms('job_type', ['object_id' => $job->ID]) as $term) { ?>
<p class="applied-grid-filter"><?= esc_html($term->name) ?></p>
<?php } ?>
<?php
if (the_field('relocation', $job->ID) === 1) { ?>
<p class="applied-grid-filter">Relocation</p>
<?php } ?>
<?php
if (the_field('travel', $job->ID) === 0) { ?>
<p class="applied-grid-filter">No Travel</p>
<?php } ?>
</div>
<a class="job-view-more" href="<?php the_permalink($job->ID) ?>">View More</a>
</div>
<?php } ?>
</div>
<?php } else { ?>
<p class="no-results">No results found! Try another search.</p>
<?php } ?></section>
Just move the html code inside your php code. You also might wanna use get_field instead of the_field. Also consider using the equal == instead of the identical === comparison operator which will be tolerant if the return value is not a number but for example true/false.
Also have a look at https://www.php.net/manual/en/language.operators.comparison.php for this.
<?php
if (get_field('relocation', $job->ID) == 1) { ?>
<p class="applied-grid-filter"></p>
<?php }; ?>
Apologies, I am relatively new to PHP and am learning as I go, but am stuck on this... I have this template for a page-title section with a background image. I can add the background image, but if there is no background-img:url elected on the page, is there a way to write in a default background-img:url into this template?
<section class="page-title" <?php if($bg):?>style="background-image:url('<?php echo esc_url($bg);?>');"<?php endif;?>>
<div class="auto-container">
<h1><?php if($title) echo balanceTags($title); else wp_title('');?></h1>
<div class="bread-crumb">
<?php echo convo_get_the_breadcrumb();?>
</div>
</div>
Add this before your code:
if(empty($bg)){
$bg = '/path/to/your/default/image.jpg';
}
<section class="page-title" <?php if($bg):?>style="background-image:url('<?php echo esc_url($bg);?>')" <?php else: ?>
style="background-image:url('your URL')"
<?php endif; ?>>
Using #psdev's code, I was able to add in a default background-image if $bg was empty. Thanks!!
<section class="page-title" <?php if(empty($bg)){$bg = 'http://aqmenalt.mhsites.co.uk/wp-content/uploads/2017/06/Banner-10.png';} if($bg):?>style="background-image:url('<?php echo esc_url($bg);?>');"<?php endif;?>>
<div class="auto-container">
<h1><?php if($title) echo balanceTags($title); else wp_title('');?></h1>
<div class="bread-crumb">
<?php echo convo_get_the_breadcrumb();?>
</div>
</div>
So I have this code I want to repeat. Uses wordpress acf to generate the image:
`<div class="row">
<?php if( get_field('image_1') ): ?>
<img class="this-image" src="<?php the_field('image_1'); ?>" />
<?php endif; ?>
</div>`
I'm just wondering how I can loop this in with which I would also need to increment the numbers (ie. image_1, image_2, image_3).
I'm having trouble figuring out the logic of PHP, if there already is a similar post, a kind link would be much appreciated, thanks!
Use below code - it is using for loop to iterate through all images from image_1 to image_X (where X can be defined by you). similar code can be modified by add an array to store all the image names, just in case if there is no patterns for the image names.
<div class="row">
<?php $numImages = 10; #Define how many images you have
for ($i=1; $i<= $numImages; $i++){ #starting from image_1 ?>
<?php if( get_field('image_' . $i)): ?>
<img class="this-image" src="<?php the_field('image_' . $i); ?>" />
<?php endif; ?>
<?php } ?>
</div>
You can try something like this
`<div class="row">
<?php
for (i=1; i<=3; i++) {
if( get_field('image_'.i) ): ?>
<img class="this-image" src="<?php the_field('image_'.i); ?>" />
<?php endif; } ?>
</div>`
My page http://www.allyourpods.no/ has some odd "holes" that I cant for the life of me figure out.
I would love some help to figure out how to make it automagickly fill the site in a proper fashion.
My template-file for the start-screen looks like this:
<?php
/*
Template Name: Home Template
*/
get_header(); ?>
<?php query_posts('cat='.recPodcastCategory.'&showposts=30');?>
<?php $categories = get_categories('child_of='.recPodcastCategory); ?>
<?php if($categories): $count=0;?>
<div class="recommended">
<div class="wrapper">
<div class="main_recommended_main_block">
<?php foreach($categories as $category) { if($count<30) { $count++;
if($count!=30) $class='recommend_block'; else $class='recommend_block_1'; ?>
<?php if (function_exists('get_terms_meta'))
{
$cat_image = get_terms_meta($category->term_id, 'image',true);
$add_play_podcast = get_terms_meta($category->term_id, 'play_download',true);
}?>
<div class="<?php echo $class;?>">
<div class="main">
<?php $play_podcast = get_post_meta($post->ID,'play_podcast',true);?>
<div class="view view-fifth"><?php if($cat_image):?><img src="<?php echo $cat_image;?>" alt="category image" /><?php endif;?>
<?php if($add_play_podcast):?>
<div class="mask">Play</div>
<?php endif; ?>
</div>
</div>
<?php echo substr( category_description( $category->term_id ),0,100 ) . "..."; ?>
</div>
<?php } } ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if(!isset($_GET['pod_category']))$class_all = ' class="active"'; ?>
<div class="clr"></div>
<?php get_footer(); ?>
If any more information is needed please let me know.
You should add this css:
.recommend_block:nth-child(4) {
clear: left;
}
The problem is one of the first two is a little lower than the others, so it is blocking the float.
Edit: that should be
.recommend_block:nth-child(4n)
I have a parent page that acts as menu for my portfolio.
It pulls in thumbnail images from the child pages which i have been able to accomplish with magic fields and some code. It dumps the images into a grid layout. The thumbnails are pulled into one container div like so:
div id="folio-content">
<div class="thumb-container">
<div class="thumb"><img src="/images/pic.jpg"/>
</div>JCPenny</div>
... </div>`
when the div gets filled up with 2 thumbnails I want to create a new container div and fill it with 2 images again and so on after 2 images.
So, if you had 4 images it would look like this.
<div id="folio-content"><!--/Main Container/-->
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>JCPenny</div>
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>Champ Car</div></div>
<div id="folio-content"><!--/Main Container/-->
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>JCPenny</div>
<div class="thumb-container">
<div class="thumb"><img src="/images/pic1.jpg"/>
</div>Champ Car</div></div>
this is the code I am using in my page.php file.
<?php get_header(); ?>
<div id="folio-content">
<?php
$projectpage = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
$count = 0;
foreach($projectpage as $page)
{
$content = $page->post_content;
if(!$content)
continue;
if ($count == 10) --- this is geting 10 images now, but I want to get them all.
break;
$count++;
$content = apply_filters('the_content', $content);
?>
<div class="thumb-container">
<div class="thumb"><a href="<?php echo get_permalink($page->ID); ?>"<?php echo get_image ("thumbnail",1,1,1,$page->ID);?></a>
</div><?php echo $page->post_title ?>
</div>
<?php
}
?>
</div><!--/close set!-->
</div>
also, how can I get ALL child pages? I have it set to 10 now with this if ($count == 10)
any help? thanks a ton again!!!!
I'm not familiar with "get_pages" but since Wordpress treats posts and pages in an identical manner you could use this.
$projectpage = get_posts('numberposts=-1&post_type=page&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
The -1 removes the limit and gets ALL the specified pages.
I have cobbled together some code, that sort of sounds right but does not work at all! Which I am not surprised. But it is a starting point - please take a look at this code, maybe it is step in the right direction?
<?php
$projectpage = get_posts('numberposts=-1&post_type=page&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
if (have_posts()) :
$i=0; // counter
while(get_posts()) : the_post();
if($i%2==0) { // if counter is multiple of 3, put an opening div ?>
<!-- <?php echo ($i+1).'-'; echo ($i+2); ?> -->
<div>
<?php } ?>
<div class="single_item">
<h2><?php the_title(); ?></h2>
</div>
<?php $i++;
if($i%2==0) { // if counter is multiple of 3, put an closing div ?>
</div>
<?php } ?>
<?php endwhile; ?>
<?php
if($i%2!=0) { // put closing div here if loop is not exactly a multiple of 3 ?>
</div>
<?php } ?>
<?php endif; ?>