custom loop ad in wordpress - php

I am trying to show google ads in my website. I would like insert one at the top of the loop. 1st one and now more. It echo ad front every post, but I would like just show it once before the first one.
This is the code what I am using.
<div class="search-results">
<div class="row">
<?php
$counter_max = 4;
$column_size = 'col-sm-6 col-md-3';
if( $ads_search_layout == 'style-left' ){
$counter_max = 3;
$column_size = 'col-sm-6 col-md-4';
}
if( $view == 'list' ){
$counter_max = 2;
$column_size = 'col-md-6';
if( $ads_search_layout == 'style-left' ){
$counter_max = 1;
$column_size = 'col-md-12';
}
}
$counter = 0;
if( $ads->have_posts() ) {
while( $ads->have_posts() ){
$ads->the_post();
if( $counter == $counter_max ){
$counter = 0;
echo '</div><div class="row">';
}
?>
<div class="<?php echo esc_attr( $column_size ); ?>">
<?php
if(($counter>1) && ($counter == 0)){
echo( classifieds_load_path( 'includes/adsence.php' ) );
}
if( $view == 'grid' ){
$image_size = 'classifieds-ad-box-bug';
include( classifieds_load_path( 'includes/ad-box.php' ) );
}
else{
$excerpt_max = 154;
include( classifieds_load_path( 'includes/ad-box-alt.php' ) );
}
$counter++;
?>
</div>
<?php
}
}
?>
</div>
</div>
<?php wp_reset_postdata(); ?>

Related

Get ACF fields of taxonomy in foreach loop

I have created a function that allows me to display the next/previous category, by order of their position. This is working fine, the problem I am having is getting ACF fields to display specific to each category.
I currently have a colour picker ACF field for every category - which is different for each one, this is set to display on each link. At the moment, the ACF field is only bringing in the hex value from the current category that is being viewed, as opposed to the next/previous ones.
function next_prev_cat() {
$this_taxonomy = get_queried_object();
if (is_category()) {
$taxonomies = get_categories();
}
if (is_tag()) {
$taxonomies = get_tags();
}
foreach ($taxonomies as $position => $tax):
if ($this_taxonomy->term_id == $tax->term_id):
$next_tax = $position + 1;
$prev_tax = $position - 1;
break;
endif;
endforeach;
$showPrev;
$showNext;
if ($prev_tax < 0) {
$prev_tax=count($taxonomies) - 1;
$showPrev='';
} else {
$prev_tax;
$showPrev = $taxonomies[$prev_tax]->name;
}
if ($prev_tax == count($taxonomies)-2) {
$next_tax = 0;
$showNext = '';
} else {
$showNext = $taxonomies[$next_tax]->name;
}
$prevLink = get_term_link( $taxonomies[$prev_tax] );
$nextLink = get_term_link( $taxonomies[$next_tax] );
?>
<div class="area-links">
<a style="border:1px solid <?php the_field('brand_colour', $tax); ?>" href="<?php echo $prevLink;?>"><?php echo $showPrev; ?></a>
<a style="border:1px solid <?php the_field('brand_colour', $tax); ?>"href="<?php echo $nextLink;?>"><?php echo $showNext ?></a>
</div>
<?php
}
Here is updated version of code
function next_prev_cat() {
$this_taxonomy = get_queried_object();
$id_for_color=false;
if (is_category()) {
$taxonomies = get_categories();
}
if (is_tag()) {
$taxonomies = get_tags();
}
$colors=array();
foreach ($taxonomies as $position => $tax):
$id_for_color=$tax->term_id;
$colors[$id_for_color]=get_field('brand_colour', $id_for_color);
$cats=array_push($cats,$id_for_color );
if ($this_taxonomy->term_id == $tax->term_id):
$next_tax = $position + 1;
$prev_tax = $position - 1;
break;
endif;
endforeach;
$showPrev;
$showNext;
if ($prev_tax < 0) {
$prev_tax=count($taxonomies) - 1;
$showPrev='';
} else {
$prev_tax;
$prev_color=$colors[$taxonomies[$prev_tax]->term_id];
$showPrev = $taxonomies[$prev_tax]->name;
}
if ($prev_tax == count($taxonomies)-2) {
$next_tax = 0;
$showNext = '';
} else {
$next_color=$colors[$taxonomies[$next_tax]->term_id];
$showNext = $taxonomies[$next_tax]->name;
}
$prevLink = get_term_link( $taxonomies[$prev_tax] );
$nextLink = get_term_link( $taxonomies[$next_tax] );
?>
<div class="area-links">
<a style="border:1px solid <?php echo $prev_color; ?>" href="<?php echo $prevLink;?>"><?php echo $showPrev; ?></a>
<a style="border:1px solid <?php echo $next_color; ?>"href="<?php echo $nextLink;?>"><?php echo $showNext ?></a>
</div>
<?php}

Filter content PHP

Trying filter content with get data:
<?php
$min_quadrature = $sanitizer->text($input->get->min_quadrature);
$max_quadrature = $sanitizer->text($input->get->max_quadrature);
$min_price = $sanitizer->text($input->get->min_price);
$max_price = $sanitizer->text($input->get->max_price);
?>
<div class="gallery-items four-columns grid-small-pad">
<?php foreach($pages->find("parent=projects") as $parent): ?>
<?php
$show = "";
if(!empty($min_quadrature) && !empty($max_quadrature) && !empty($min_price) && !empty($max_price) && $parent->quadrature >= $min_quadrature && $parent->quadrature <= $max_quadrature && $parent->price >= $min_price && $parent->price <= $max_price) {
$show = "d-block";
} else if(!empty($min_quadrature) && $parent->quadrature >= $min_quadrature) {
$show = "d-block";
} else if(!empty($max_quadrature) && $parent->quadrature <= $max_quadrature) {
$show = "d-block";
} else if(!empty($min_price) && $parent->price >= $min_price) {
$show = "d-block";
} else if(!empty($max_price) && $parent->price <= $max_price) {
$show = "d-block";
} else if(empty($max_price) && empty($min_price) && empty($min_quadrature) && empty($max_quadrature)) {
$show = "d-block";
} else {
$show = "d-none";
}
?>
<div class="gallery-item projects <?= $show; ?>" data-budget="<?= $parent->price; ?>" data-quadrature="<?= $parent->quadrature; ?>">
<div class="grid-item-holder">
<?php
$image = $parent->background;
$thumb = $image->size(300, 170);
?>
<img src="<?= $thumb->url; ?>" alt="">
<div class="port-desc-holder">
<div class="port-desc">
<div class="grid-item mt-2">
<h3 class="m-0"><?= $parent->title; ?></h3>
<p class="price d-none"><?= $parent->price; ?></p>
<p class="quadrature p-0 m-0"><?= $parent->quadrature; ?> m2</p>
</div>
</div>
</div>
</div>
</div>
<?php endforeach ?>
</div>
All my items have $min_quadrature, $max_quadrature, $min_price, $max_price
I try show blocks if input data in range, my solution working bad, some combinations with all 4 input data

3 posts in a row instead of 2 / wordpress

I have a wordpress theme which displays blog feed in two different ways. I am using the second option (called: Small) with 2 posts in a row so the layout looks like there are two columns with posts. I would like to have three posts in a row.
This is a code responsible for a blog feed:
?php
$example_i = 1; $example_ad = 0; $example_flag = true; $example_div_open = 0;
if ( have_posts() ) {
while ( have_posts() ) : the_post();
/*** Mixed: 2 Small Posts, Followed by 1 Full ***/
if($example_blog_feed_post_format == 'Mixed') {
if ($example_i == 1 && $example_flag) { ?><div class="row" data-fluid=".entry-title"><div class="col-md-6"><?php $example_entry = 'small'; include(locate_template('parts/entry.php')); $example_i = 2; $example_flag = false; ?></div><?php }
if ($example_i == 2 && $example_flag) { ?><div class="col-md-6"><?php $example_entry = 'small'; include(locate_template('parts/entry.php')); $example_i = 3; $example_flag = false; ?></div></div><?php }
if ($example_i == 3 && $example_flag) { $example_entry = 'full'; include(locate_template('parts/entry.php')); $example_i=1; $example_flag = false; }
}
/*** Small: Small Image and Excerpt, 2 in a Row ***/
else if($example_blog_feed_post_format == 'Small') {
if($example_i%2 != 0) { $example_div_open = 1; ?><div class="row"><?php } ?>
<div class="col-md-6"><?php $example_entry = 'small'; include(locate_template('parts/entry.php')); $example_i++; ?></div>
<?php if($example_i%2 != 0) { ?></div><?php $example_div_open = 0;} ?><?php
}
$example_flag = true;
endwhile;
if($example_i == 2 && $example_blog_feed_post_format == 'Mixed') { ?></div><?php } else if ($example_div_open == 1) { ?></div><?php }
} else { ?><div class="blog-feed-empty"><p><?php esc_html_e('No posts found.', 'example'); ?></p></div><?php } ?>
</div>
I was trying to modify this piece of code:
/*** Small: Small Image and Excerpt, 2 in a Row ***/
else if($example_blog_feed_post_format == 'Small') {
if($example_i%2 != 0) { $example_div_open = 1; ?><div class="row"><?php } ?>
<div class="col-md-6"><?php $example_entry = 'small'; include(locate_template('parts/entry.php')); $example_i++; ?></div>
<?php if($example_i%2 != 0) { ?></div><?php $example_div_open = 0;} ?><?php
}
but with no success.
Could someone help how should I change this code to have three posts in a row instead of two?
I would be very grateful for help.
Edit (29 Nov):
I tried to use the code sent me by Shital below, but it's not working. After using this solution I get:
<div class="blog-feed-posts">
<div class="row">
<div class="col-md-4"></div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
<div class="row">
<div class="col-md-4"></div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
And my intention was to have three posts in a row. I also tried other modifications but none of them seemed to work. Could someone help me with this code?
add below code for 3 posts in a row.
<?php
$example_i = 1; $example_ad = 0; $example_flag = true; $example_div_open = 0;
if ( have_posts() ) {
while ( have_posts() ) : the_post();
/*** Mixed: 2 Small Posts, Followed by 1 Full ***/
if($example_blog_feed_post_format == 'Mixed') {
if ($example_i == 1 && $example_flag) { ?><div class="row" data-fluid=".entry-title"><div class="col-md-6"><?php $example_entry = 'small'; include(locate_template('parts/entry.php')); $example_i = 2; $example_flag = false; ?></div><?php }
if ($example_i == 2 && $example_flag) { ?><div class="col-md-6"><?php $example_entry = 'small'; include(locate_template('parts/entry.php')); $example_i = 3; $example_flag = false; ?></div></div><?php }
if ($example_i == 3 && $example_flag) { $example_entry = 'full'; include(locate_template('parts/entry.php')); $example_i=1; $example_flag = false; }
}
/*** Small: Small Image and Excerpt, 3 in a Row ***/
else if($example_blog_feed_post_format == 'Small') {
if($example_i%3 != 0) { $example_div_open = 1; ?><div class="row"><?php } ?>
<div class="col-md-4"><?php $example_entry = 'small'; include(locate_template('parts/entry.php')); $example_i++; ?></div>
<?php if($example_i%3 != 0) { ?></div><?php $example_div_open = 0;} ?><?php
}
$example_flag = true;
endwhile;
if($example_i == 2 && $example_blog_feed_post_format == 'Mixed') { ?></div><?php } else if ($example_div_open == 1) { ?></div><?php }
} else { ?><div class="blog-feed-empty"><p><?php esc_html_e('No posts found.', 'example'); ?></p></div><?php } ?>
</div>

wordpress get_terms and WP_Query not working as expected

i've created a colophon for my website in which i post all the logos of the different sponsors i have. I add all the sponsors via custom post type. i also added a specific custom taxonomy to distinguish between the different typologies of sponsorships.
I use this code in the footer.php to display them:
<?php $terms = get_terms('sponsor_tipology');
$count = count( $terms );
if ( $count > 0 ) {
foreach ( $terms as $term ) { ?>
<div class="col-xs-12 <?php echo $term->slug ;?>">
<h3><?php echo $term->name;?></h3>
<?php $arg = array (
'post_type' => 'colophone',
'post_per_page' => -1,
'sponsor_edition' => 'current',
'sponsor_tipology' => $term->slug,
);
$pesca_post = new WP_Query ($arg);
$quanti_post = $pesca_post->post_count;
if(have_posts()){
while ($pesca_post->have_posts()) : $pesca_post->the_post();
$featured = get_the_post_thumbnail_url(get_the_ID(),'large');
if ($quanti_post == 5){
$classe_bootstrap = 15;
}elseif ($quanti_post > 5){
$classe_bootstrap = "2 text-center";
}elseif($quanti_post < 5){
$classe_bootstrap = 12/$quanti_post;
}
echo '<div class="col-md-' . $classe_bootstrap . '">';
if (isset($featured)){
$img = $featured;
}else{
$img = get_template_directory_uri() . '/img/placeholder.png';
} ?>
<a href="<?php echo esc_attr(get_permalink($msd_settings['partner_page'])); ?>" title="<?php echo get_the_title($post->ID);?>" >
<div class="col-xs-12" style="background-image:url(<?php echo esc_url($img); ?>); height:100px;background-size:contain;background-repeat:no-repeat;background-position:center center;"></div>
</a>
<?php echo '</div>';
endwhile;
}?>
</div>
<?php }
}?>
my problem is that this code is completely working just on some pages, on other it shows the contents avoiding the ones belonging to the first term, no matter which it will be.
I have noticed that it works in pagaes where i use other queries.
What am i doing wrong?
i changed it in this way and now it's working!
$terms = get_terms('sponsor_tipology');
$count = count( $terms );
if ( $count > 0 ) {
foreach ( $terms as $term ) { //per ogni termine presente
$nome = $term->slug;?>
<div class="col-xs-12 <?php echo $term->slug ;?>">
<h3><?php echo $term->name;?></h3>
<?php $arg = array (
'post_type' => 'colophone',
'post_per_page' => -1,
'sponsor_edition' => 'current',
'sponsor_tipology' => $nome,
);
$elementi = get_posts($arg);
$quanti_post = count( $elementi );
if ($quanti_post == 5){
$classe_bootstrap = 15;
}
elseif ($quanti_post > 5){
$classe_bootstrap = "2 text-center";
}
elseif($quanti_post < 5){
$classe_bootstrap = 12/$quanti_post;
}
foreach($elementi as $elemento){
$featured = get_the_post_thumbnail_url($elemento->ID,'large');
if (isset($featured)){
$img = $featured;
}
else{
$img = get_template_directory_uri() . '/img/placeholder.png';
} ?>
<div class="col-md-<?php echo $classe_bootstrap; ?>">
<a href="<?php echo esc_attr(get_permalink($msd_settings['partner_page'])); ?>" title="<?php echo get_the_title($elemento->ID);?>" >
<div class="col-xs-12" style="background-image:url(<?php echo esc_url($img); ?>); height:100px;background-size:contain;background-repeat:no-repeat;background-position:center center;"></div>
</a>
</div>
<?php }?>
</div>
<?php }
}?>

Wordpress Magnifying function using images from custom filed "et_gallery"

The goal effect is: When clicked on the magnifying icon, it uses the "Fancybox" plugin to display big size images (mutiple images separated by commas) in the custom filed "et_gallery".
Right now the magnifying isn't working at all.
http://heidixu.com/#!/?page_id=4
It was working fine once. And then I accidently replaced the final code with an earlier version. So the version I currently have is pretty close but something is not right or missing and I can't figure out what because I'm not an expert in php...
This is the page: http://heidixu.com/#!/?page_id=4 and every other pages with thumbnails work the same.
This is my current version of php code that was edited:
<?php
/*
Template Name: Portfolio Page
*/
?>
<?php
$et_ptemplate_settings = array();
$et_ptemplate_settings = maybe_unserialize( get_post_meta($post->ID,'et_ptemplate_settings',true) );
$fullwidth = true;
$et_ptemplate_showtitle = isset( $et_ptemplate_settings['et_ptemplate_showtitle'] ) ? (bool) $et_ptemplate_settings['et_ptemplate_showtitle'] : false;
$et_ptemplate_showdesc = isset( $et_ptemplate_settings['et_ptemplate_showdesc'] ) ? (bool) $et_ptemplate_settings['et_ptemplate_showdesc'] : false;
$et_ptemplate_detect_portrait = isset( $et_ptemplate_settings['et_ptemplate_detect_portrait'] ) ? (bool) $et_ptemplate_settings['et_ptemplate_detect_portrait'] : false;
$gallery_cats = isset( $et_ptemplate_settings['et_ptemplate_gallerycats'] ) ? (array) $et_ptemplate_settings['et_ptemplate_gallerycats'] : array();
$et_ptemplate_gallery_perpage = isset( $et_ptemplate_settings['et_ptemplate_gallery_perpage'] ) ? (int) $et_ptemplate_settings['et_ptemplate_gallery_perpage'] : 12;
$et_ptemplate_portfolio_size = isset( $et_ptemplate_settings['et_ptemplate_imagesize'] ) ? (int) $et_ptemplate_settings['et_ptemplate_imagesize'] : 2;
$et_ptemplate_portfolio_class = '';
if ( $et_ptemplate_portfolio_size == 1 ) $et_ptemplate_portfolio_class = ' et_portfolio_small';
if ( $et_ptemplate_portfolio_size == 3 ) $et_ptemplate_portfolio_class = ' et_portfolio_large';
?>
<?php get_header(); ?>
<div class="single_container et_shadow">
<div class="single_content">
<div class="entry post clearfix">
<?php get_template_part('loop','page'); ?>
<div id="et_pt_portfolio_gallery" class="clearfix<?php echo $et_ptemplate_portfolio_class; ?>">
<?php $gallery_query = '';
$portfolio_count = 1;
$et_open_row = false;
if ( !empty($gallery_cats) ) $gallery_query = '&cat=' . implode(",", $gallery_cats);
else echo '<!-- gallery category is not selected -->'; ?>
<?php
$et_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
?>
<?php query_posts("showposts=$et_ptemplate_gallery_perpage&paged=" . $et_paged . $gallery_query); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $width = 260;
$height = 170;
if ( $et_ptemplate_portfolio_size == 1 ) {
$width = 140;
$height = 94;
$et_portrait_height = 170;
}
if ( $et_ptemplate_portfolio_size == 2 ) $et_portrait_height = 315;
if ( $et_ptemplate_portfolio_size == 3 ) {
$width = 430;
$height = 283;
$et_portrait_height = 860;
}
$et_auto_image_detection = false;
if ( has_post_thumbnail( $post->ID ) && $et_ptemplate_detect_portrait ) {
$wordpress_thumbnail = get_post( get_post_thumbnail_id($post->ID) );
$wordpress_thumbnail_url = $wordpress_thumbnail->guid;
if ( et_is_portrait($wordpress_thumbnail_url) ) $height = $et_portrait_height;
}
$titletext = get_the_title();
$et_portfolio_title = get_post_meta($post->ID,'et_portfolio_title',true) ? get_post_meta($post->ID,'et_portfolio_title',true) : get_the_title();
$et_videolink = get_post_meta($post->ID,'et_videolink',true) ? get_post_meta($post->ID,'et_videolink',true) : '';
$thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,true,'et_portfolio');
$thumb = $thumbnail["thumb"];
if ( $et_ptemplate_detect_portrait && $thumbnail["use_timthumb"] && et_is_portrait($thumb) ) {
$height = $et_portrait_height;
} ?>
<?php if ( $portfolio_count == 1 || ( $et_ptemplate_portfolio_size == 2 && (!$fullwidth && ($portfolio_count+1) % 2 == 0) ) || ( $et_ptemplate_portfolio_size == 3 && (($portfolio_count+1) % 2 == 0) ) ) {
$et_open_row = true; ?>
<div class="et_pt_portfolio_row clearfix">
<?php } ?>
<div class="et_pt_portfolio_item">
<?php if ($et_ptemplate_showtitle) { ?>
<h2 class="et_pt_portfolio_title"><?php echo $et_portfolio_title; ?></h2>
<?php } ?>
<div class="et_pt_portfolio_entry<?php if ( $height == $et_portrait_height ) echo ' et_portrait_layout'; ?>">
<div class="et_pt_portfolio_image<?php if ($et_videolink <> '') echo ' et_video'; ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, ''); ?>
<?php $gallery = explode(',', get_post_meta($post->ID, 'et_gallery', true));
foreach ($gallery as $item) { ?>
<a class="fancybox" href="<?php echo $item; ?>" style="display: none;" rel="gallery[<?php echo $post->ID; ?>]" title="<?php the_title(); ?>"></a>
<?php } ?>
<span class="et_pt_portfolio_overlay"></span>
<a class="et_portfolio_zoom_icon <?php if ($et_videolink <> '') echo 'et_video_lightbox'; else echo('fancybox'); ?>" title="<?php the_title(); ?>"<?php if ($et_videolink == '') echo ' rel="gallery[' . $post->ID . '"]'; ?> href="<?php if ($et_videolink <> '') echo $et_videolink; else echo($thumbnail['fullpath']); ?>"><?php esc_html_e('Zoom in','Sky'); ?></a>
<a class="et_portfolio_more_icon" href="<?php the_permalink(); ?>"><?php esc_html_e('Read more','Sky'); ?></a>
</div> <!-- end .et_pt_portfolio_image -->
</div> <!-- end .et_pt_portfolio_entry -->
<?php if ($et_ptemplate_showdesc) { ?>
<p><?php truncate_post(90); ?></p>
<?php } ?>
</div> <!-- end .et_pt_portfolio_item -->
<?php if ( ($et_ptemplate_portfolio_size == 2 && !$fullwidth && $portfolio_count % 2 == 0) || ( $et_ptemplate_portfolio_size == 3 && ($portfolio_count % 2 == 0) ) ) {
$et_open_row = false; ?>
</div> <!-- end .et_pt_portfolio_row -->
<?php } ?>
<?php if ( ($et_ptemplate_portfolio_size == 2 && $fullwidth && $portfolio_count % 3 == 0) || ($et_ptemplate_portfolio_size == 1 && !$fullwidth && $portfolio_count % 3 == 0) || ($et_ptemplate_portfolio_size == 1 && $fullwidth && $portfolio_count % 5 == 0) ) { ?>
</div> <!-- end .et_pt_portfolio_row -->
<div class="et_pt_portfolio_row clearfix">
<?php $et_open_row = true; ?>
<?php } ?>
<?php $portfolio_count++;
endwhile; ?>
<?php if ( $et_open_row ) {
$et_open_row = false; ?>
</div> <!-- end .et_pt_portfolio_row -->
<?php } ?>
<div class="page-nav clearfix">
<?php if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<?php get_template_part('includes/navigation'); ?>
<?php } ?>
</div> <!-- end .entry -->
<?php else : ?>
<?php if ( $et_open_row ) {
$et_open_row = false; ?>
</div> <!-- end .et_pt_portfolio_row -->
<?php } ?>
<?php get_template_part('includes/no-results'); ?>
<?php endif; wp_reset_query(); ?>
<?php if ( $et_open_row ) {
$et_open_row = false; ?>
</div> <!-- end .et_pt_portfolio_row -->
<?php } ?>
</div> <!-- end #et_pt_portfolio_gallery -->
</div> <!-- end .entry -->
</div> <!-- end .single_content -->
<div class="content-bottom"></div>
</div> <!-- end .single_container -->
<?php if (get_option('sky_show_pagescomments') == 'on') comments_template('', true); ?>
Could any php experts please take a look. Thank you so much.
-Heidi
So far, when you click on the magnifying icon, it produces this error:
Error: a is undefined
Source File: http://heidixu.com/wp-content/themes/Sky/epanel/page_templates/js/fancybox/jquery.fancybox-1.3.4.pack.js?ver=1.3.4
Line: 19
It looks like the link (the <a> tag) is not bound to fancybox regardless it has the specified class.
I want to believe that your generated code is not well formed; you have this html:
Zoom in
and wonder if this part specifically
... ]="" rel="gallery[ ....
...is creating the error. I cannot find what part of your php code generates those (misplaced?) brackets.

Categories