PHP code in Sidebar Not Working Correctly - php

I am having some issues with my dynamic php sidebar and wanted to see if anyone finds any issues with my code. Right now, the aside and other sidebar classes are closing sooner than the end of the code. I was thinking there might be something else wrong with my code that I'm not aware of.
I have a php widget plugin installed, and the below code is written in the sidebar:
<div class="sidebar-container">
<button class="accordion" style="h5">Education</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . get_field('education') . '</span>'; ?></p>
</div>
<?php if( get_field('licensescertifications') ) : ?><button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('licensescertifications') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('honors') ) : ?><button class="accordion">Honors</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('honors') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('publications') ) : ?><button class="accordion">Publications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('publications') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('affiliations') ) : ?><button class="accordion">Affiliations</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('affiliations') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('languages') ) : ?><button class="accordion">Languages</button>
<div class="accordion-content">
<p><?php the_field('languages'); ?></p>
<?php endif; ?>
</div>
</div>

Maybe you should replace position of "endif" in each block? And replace "the_field" with "get_field" in "echo" line
<?php if( get_field('licensescertifications') ) : ?>
<button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . get_field('licensescertifications') . '</span>'; ?></p>
</div>
<?php endif; ?>
Or shortly:
<?php if( $field_data = get_field('licensescertifications') ) : ?>
<button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . $field_data . '</span>'; ?></p>
</div>
<?php endif; ?>

Related

Both PHP statements are executing

I'm working with the ACF plugin in WordPress. For some reason the else statement is executing even when the first statement is true. Why?
<section id="ParksContainer" class="col-lg-6 col-md-6 col-xs-12">
<h1 id="AdventurePostTitle" class="">Parks</h1>
<?php if( have_rows('adventure_location') ):
while( have_rows('adventure_location') ): the_row(); ?>
<ul id="LocationUl">
<li><b>NATIONAL PARK:</b>
<?php if( the_sub_field('national_park') ):?>
<?php echo '<span class="LocationNameSpan">'; the_sub_field('national_park'); echo '</span>'; ?>
<?php else: ?>
<?php echo '<span class="LocationNameSpan">N/A</span>'; ?>
<?php endif; ?>
</li>
<li>
<b>STATE PARK:</b>
<?php if( the_sub_field('state_park') ) {
echo '<span class="LocationNameSpan">'; the_sub_field('state_park'); echo '</span>';
} else {
echo '<span class="LocationNameSpan">N/A</span>';
}
?>
</li>
</ul>
<?php endwhile; ?>
<?php endif; ?>
</section><!--Parks Container-->
Any suggestions?

Error in wordpress function.php file

I am trying to add a particular shortcode to my theme, but i get an error when i paste the below code in my themes function.php. I already tried including once in the function.php but that did not work.
I think the problem is because of the <?php prefix and ?> suffix it has which is prohibited in wordpress fucntion.php. I had removed all <?php and ?> but it still generates an error.
// Add Shortcode
function acardio_big_grid_1() {
<div class="col-md-12 featt big-grid">
<div class="container-fluid no-padding">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'post', 'posts_per_page' => 5, 'paged' => $paged);
$query = new WP_Query($args);
if( $query->have_posts() ) :
while( $query->have_posts() ) : $query->the_post(); ?>
<?php $count++; ?>
<?php if ($count == 1) : ?>
<div class="big-pane col-xs-6">
<div class="the-big-pane image">
<div class="img-responsive"> <?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail('big-grid-one-image'); ?>
<?php else : ?>
<img src="
<?php if (function_exists('get_option_tree') ) : if (get_option_tree('defualt_fatured_uploader')) : ?>
<?php get_option_tree( 'defualt_fatured_uploader', '', 'true' ); ?>
<?php else : ?>
<?php echo get_template_directory_uri (); ?>/img/nothumb-featured.png
<?php endif; endif; ?>
" />
<?php endif; ?></div>
</div>
<div class="big-pane overlay">
<div class="the-big-pane-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1><?php echo wp_trim_words( get_the_title(), 15 ); ?></h1>
<span class="the-content-post-data"><span class="the-auth-post-image-content" style="padding-top: 0px !important;"> <?php echo get_avatar( get_the_author_meta( 'user_email' ), 100 ); ?> </span> By <?php the_author_posts_link(); ?> <span class="the-content-post-date"> <i class="fa fa-clock-o the-content "></i><?php the_time('jS M, Y') ?></span> </span>
</div>
</div>
</div>
<?php elseif ($count == 2) : ?>
<div class="small-pane-holder1 col-xs-6">
<div class="small-pane col-xs-6 one">
<div class="the-small-pane-image">
<?php the_post_thumbnail();?>
</div>
<div class="small-pane-overlay">
<div class="small-pan-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1 class="small-pane-title"><?php echo wp_trim_words( get_the_title(), 10 ); ?></h1>
</div>
</div>
</div>
<?php elseif ($count == 3) : ?>
<div class="small-pane col-xs-6 two">
<div class="the-small-pane-image">
<?php the_post_thumbnail();?>
</div>
<div class="small-pane-overlay">
<div class="small-pan-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1 class="small-pane-title"><?php echo wp_trim_words( get_the_title(), 10 ); ?></h1>
</div>
</div>
</div>
<?php elseif ($count == 4) : ?>
<div class="small-pane col-xs-6 three">
<div class="the-small-pane-image">
<?php the_post_thumbnail();?>
</div>
<div class="small-pane-overlay">
<div class="small-pan-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1 class="small-pane-title"><?php echo wp_trim_words( get_the_title(), 10 ); ?></h1>
</div>
</div>
</div>
<?php elseif ($count == 5) : ?>
<div class="small-pane col-xs-6 four">
<div class="the-small-pane-image">
<?php the_post_thumbnail();?>
</div>
<div class="small-pane-overlay">
<div class="small-pan-content">
<div class="the-cont-cat">
<span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category)
{ echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
</div>
<h1 class="small-pane-title"><?php echo wp_trim_words( get_the_title(), 10 ); ?></h1>
</div>
</div>
</div>
</div>
<?php else : ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
}
add_shortcode( 'acardio-big-grid-1', 'acardio_big_grid_1' );
Right near the top you have a syntax error - an issue with your PHP tags. You need a closing php tag before the HTML, and an opening PHP tag after. The top of the code should read like so:
function acardio_big_grid_1() {
?>
<div class="col-md-12 featt big-grid">
<div class="container-fluid no-padding">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'post', 'posts_per_page' => 5, 'paged' => $paged);
You have a similar problem near the end of the code sample, but this time missing a opening php tag:
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php
}
add_shortcode( 'acardio-big-grid-1', 'acardio_big_grid_1' );
No guarantees that that is all your issues, but that would be one key issue in the code sample you provided.

Proper way to write this php conditional statement

I am not well versed in php as I'm a newbie in it. I'm trying to use these lines of code but getting error. What is the proper way to write this:
<?php
if ( function_exists( 'wpsabox_author_box' ) ) {
echo wpsabox_author_box();
} else {
echo (
'<div class="postauthor">
<div class="authorprofilepix">'
get_avatar( get_the_author_id() , 80 );
'</div>
<div class="authorprofile">
<h4>' the_author(); '</h4>
<p>' the_author_description(); '</p>
</div>
<div class="clearfix"></div>
</div><!--end postauthor-->');
}
?>
Thanks in anticipation!
You should add dots between the strings and function calls inside the echo call.
e.g.
echo ('string' . function() . ' string ');
use this way :
<?php if (function_exists( 'wpsabox_author_box' ) ) {
echo wpsabox_author_box();
} else { ?>
<div class="postauthor">
<div class="authorprofilepix">'
<?php echo get_avatar( get_the_author_id() , 80 ); ?>
</div>
<div class="authorprofile">
<h4><?php echo the_author(); ?></h4>
<p><?php echo the_author_description(); ?></p>
</div>
<div class="clearfix"></div>
</div><!--end postauthor-->
<?php }
?>
Here's how your code should look in order to work:
<?php
if ( function_exists( 'wpsabox_author_box' ) ) {
echo wpsabox_author_box();
} else {
echo '<div class="postauthor">
<div class="authorprofilepix">' . get_avatar(get_the_author_id(), 80 ); . '</div>
<div class="authorprofile">
<h4>' . the_author() . '</h4>
<p>' . the_author_description() . '</p>
</div>
<div class="clearfix"></div>
</div><!--end postauthor-->';
}
?>
Here's the prefered solution:
<?php if (function_exists( 'wpsabox_author_box' ) ) {
echo wpsabox_author_box();
} else { ?>
<div class="postauthor">
<div class="authorprofilepix">
<?php echo get_avatar( get_the_author_id() , 80 ); ?>
</div>
<div class="authorprofile">
<h4><?php the_author(); ?></h4>
<p><?php the_author_description(); ?></p>
</div>
<div class="clearfix"></div>
</div><!--end postauthor-->
<?php }
?>
As you can see it's slightly correctd Ravi's solution. I can't say it's better but I much prefer it to the other cause it's much more clear.
One more thing. Don't use the_author_description() function, use the_author_meta('description') instead.
Use commas to avoid string concatenation. Also, use get_the_author_meta() as both the get_the_author_id() and the_author_description() have been deprecated.
if ( function_exists( 'wpsabox_author_box' ) ) {
echo wpsabox_author_box();
} else {
echo '<div class="postauthor">
<div class="authorprofilepix">',
get_avatar( get_the_author_meta('ID') , 80 ),
'</div>
<div class="authorprofile">
<h4>', get_the_author(), '</h4>
<p>', get_the_author_meta('description'), '</p>
</div>
<div class="clearfix"></div>
</div><!--end postauthor-->';
}

Custom Image Gallery is not fetching the images on WordPress

I am using an Image Gallery in Custom Post Type on my WordPress Website. The Plugin I am using for that is Advanced Custom Fields. There is some error, due to which image gallery is not getting displayed on frontend.
Please check the page.
http://divinepower.co.in/cof/projects/residential/surrey-hills-vic/
Though the same code is working fine on another custom post type.
http://divinepower.co.in/cof/brands/gloster/asta/
The code I am using is
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
// Show the Gallery
if( have_rows('gallery_slideshow') ):
echo '<div class="projects-gallery-wrap">';
echo '<div class="projects-gallery">';
// loop through the rows of data
while ( have_rows('gallery_slideshow') ) : the_row();
$imgObj = get_sub_field('image', $post->ID);
echo '<img class="item" src="'.$imgObj[sizes]['projects-gallery'].'" alt="'.$imgObj[alt].'"/>';
endwhile;
echo '</div>';
echo '</div>';
endif;
?>
<div id="inner-content" class="wrap cf">
<main id="main" class="main-content" role="main" itemscope itemprop="mainContentOfPage" itemtype="http://schema.org/Blog">
<div class="gallery-controls">
<button class="prev"><i class="fa fa-chevron-left"></i></button>
<button class="next"><i class="fa fa-chevron-right"></i></button>
</div>
<article id="post-<?php the_ID(); ?>" <?php post_class('cf'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<?php
$currentBrandName = cosh_get_brand_name();
$currentBrandSlug = cosh_get_brand_slug();
?>
<div class="content">
<header class="article-header">
<div class="title-wrap">
<h1 class="entry-title single-title" itemprop="headline"><?php the_title(); ?></h1>
<?php
// Brand Image
print apply_filters( 'taxonomy-images-list-the-terms', '', array(
'before' => '<ul class="projects-logos">',
'after' => '</ul>',
'image_size' => 'full',
'taxonomy' => 'brand'
) );
?>
</div>
<?php
// Social share
$currentURL = get_permalink( $post->ID );
?>
<div class="social-share">
<i class="fa fa-facebook"></i>
<i class="fa fa-pinterest-p"></i>
</div>
</header>
<section class="entry-content cf" itemprop="articleBody">
<div class="content-wrap">
<?php the_content(); ?>
<?php
// projects Link
$projectsURL = site_url()."/brand/".$currentBrandSlug;
if($projects){ ?>
View all <?php echo $currentBrandName; ?> projectss ›
<?php }; ?>
</div>
<?php
// Additional Info
$materials = get_field('materials', $post->ID);
$projectsSpecs = get_field('projects_specs', $post->ID);
if($materials || $projectsSpecs){ ?>
<div class="additional-info">
<?php
// Materials
if($materials){ ?>
<h4>Materials <i class="fa fa-pencil"></i></h4>
<p><?php the_field('materials'); ?></p>
<?php };
// projects Specs
if($projectsSpecs){ ?>
Download Specs <i class="fa fa-download"></i>
<?php }; ?>
</div>
<?php } ?>
</section>
<?php/*
// Show the Gallery
if( have_rows('gallery_slideshow') ):
echo '<div class="projects-gallery-wrap-mobile">';
echo '<div class="projects-gallery-mobile">';
// loop through the rows of data
while ( have_rows('gallery_slideshow') ) : the_row();
$imgObj = get_sub_field('image', $post->ID);
echo '<img class="item" src="'.$imgObj[sizes]['projects-gallery'].'" alt="'.$imgObj[alt].'"/>';
endwhile;
echo '</div>';
echo '</div>';
endif;
*/ ?>
</div>
</article>
<?php get_template_part('parts/enquiry_form'); ?>
</main>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Please help me to find the error. Thanks

How to display thumbnail if post have one other wise don't

I would like to display the most recent post in a a block, and if the post is assigned with a thumbnail I would like it to be shown on the left to the post content.
This is my code that I have been trying
<?php query_posts('posts_per_page=1') ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="jumbotron">
<?php if ( has_post_thumbnail(); )?>
<div class="col-md-3">
<?php the_post_thumbnail(); ?>
</div>
<div class="col-md-9">
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<p class="text-muted">Posted on <?php the_time('jS F, Y'); ?></p>
</div>
}
<?php else;?>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<p class="text-muted">Posted on <?php the_time('jS F, Y'); ?></p>
</div>
<?php endwhile; wp_reset_query(); ?>
Hope someone could help me! Thanks in advance!
This may be useful for you try something like :
<?php
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
if (has_post_thumbnail()) {
$image_url = wp_get_attachment_image_src(get_post_thumbnail_id(),'large', true);
echo '<a href="' . $image_url[0] .'" title="' . the_title_attribute('echo=0') . '">';
the_post_thumbnail();
echo '</a>';
} else {
echo 'test';
}
?>

Categories