Parse error: syntax error, unexpected 'else' (T_ELSE) in E:\Work Data\Sites\Portfolio\wp-content\themes\Portfolio\index.php on line 42 - wordpress-theming

<?php
get_header();
?>
<!-- PORTFOLIO AREA -->
<section>
<hr class="no-margin" />
<?php
wp_nav_menu(array(
'theme_location' => 'category-menu',
'container' => '',
'menu_class' => 'inline align-center portfolio-header',
'menu_id' => 'portfolio-sorting'
));
?>
<div class="middle-container section-content">
<div class="container">
<?php if (have_posts()) : ?>
<ul class="row portfolio-entries">
<?php while(have_posts()) : the_post(); ?>
<li class="span4 box portfolio-entry">
<div class="hover-state align-right">
<p><?php the_title(); ?></p>
<em>Click to see project</em>
<!-- end hover-state -->
</div>
<?php if (has_post_thumbnail()) : ?>
<figure>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</figure>
<?php endif; ?>
</li>
<? endwhile; ?>
</ul>
<?php else: ?>
<div class="middle-container section-content">
<div class="container box section-content align-center"><h2>No posts were found.</h2>
<!-- end container -->
</div>
<!-- end middle-container -->
</div>
<?php endif; ?>
<div class="box align-center portfolio-nav">
<ul class="inline">
<li>← Previous Page</li>
<li>Next Page →</li>
</ul>
<!-- end cta -->
</div>
<!-- end container -->
</div>
<!-- end middle-container -->
</div>
<!-- End Portfolio Area -->
</section>
<?php get_footer();
?>
I'm trying to learn the Wordpress Theme Development and I'm new/fresh in coding of PHP and Wordpress for now I'm just trying to understand the coding of PHP and how to develop Wordpress theme. During a Wordpress theme I am getting the error line given in the title bar and I am unable to understand why I'm getting this error ..?
Any help please.. ??

You used
<? endwhile; ?>
Instead of
<?php endwhile; ?>
The first one may not work if short_open_tag in your php.ini is not set.
See this question for details.

Related

ACF Repeater Accordion with Bootstrap 5

im attempting to use an ACF repeater field to build an FAQ accordion using Bootstrap 5 with a simple question and answer field. i'm getting the results to print out but the accordion expander opens all fields on click and not just the targeted field on click. How can i adjust the IDs to only open the field that is clicked?
CURRENT CODE
<?php elseif ( get_row_layout() == 'module__faq' ) : ?>
<!-- Module: FAQ
================================================== -->
<div class="section-interior-content bg-white py-5">
<div class="container text-center text-md-start">
<div class="row">
<div class="col-12 col-lg-4 text-center text-md-start order-lg-first">
<h2 class="black">
Lorem ipsum
</h2>
</div>
<div class="col-12 col-lg-8 order-first">
<?php if ( have_rows( 'faq' ) ) : ?>
<div class="accordion accordion-flush" id="faqlist">
<?php $i=1; while ( have_rows( 'faq' ) ) : the_row(); ?>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed text-uppercase" type="button" data-bs-toggle="collapse" data-bs-target="#faq-content-1">
<?php the_sub_field( 'question' ); ?>
</button>
</h2>
<div id="faq-content-1" class="accordion-collapse collapse" data-bs-parent="#faqlist">
<div class="accordion-body px-4">
<?php the_sub_field( 'answer' ); ?>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- END Module: FAQ
================================================== -->
<?php endif; ?>
UPDATE: SOLUTION
I solved this the quickest way by adding a unique id field for each FAQ - based off this post: Issue with ACF repeater accordeon loop
I solved this the quickest way by adding a unique id field for each FAQ based on this post: Issue with ACF repeater accordeon loop

Divs appears inside a brother div, not inside his parent

Im working on a wordpress page, want to display the content of posts in a specific layout, it work well, but when I add another post, the posts "dos" and "tres", appears inside the post "uno", instead of on his real parent the "nested" div. any clues?
<div class="grid">
<div class="post principal">
<!--show data-->
</div>
<div class="nested">
<?php if($count_post>1){?> <!--if there is more post fill div with data-->
<div class="post uno">
<!--show data-->
</div>
<?php }else{?>
<div class="post uno">
<!--dont show anything but keep the div-->
</div>
<?php } ?>
<?php if($count_post>2){?>
<div class="post dos">
<!--show data-->
</div>
<?php }else{?>
<div class="post dos">
<!--dont show anything but keep the div-->
</div>
<?php } ?>
<?php if($count_post>3){?>
<div class="post tres">
<!--show data-->
</div>
<?php }else{?>
<div class="post tres">
<!--dont show anything but keep the div-->
</div>
<?php } ?>
</div> <!--end nested-->
</div> <!--end grid-->
here it is all the code, the wierd thing is that lets say I have two posts in the array and all is correctly displayed, but when I add another the post "dos" and "tres" changes parent
<?php $the_query = new WP_Query( 'posts_per_page=7' );?>
<!--Obtener la cantidad de post-->
<?php $count_post = $the_query->post_count;?>
<div class="grid">
<div class="post principal">
<!--Obtener la id del post-->
<?php $post_id = $the_query->posts[0]->ID;?>
<!--Obtener la id de la imagen-->
<?php $thumbnail_id = get_post_thumbnail_id($post_id);?>
<!--Obtener source de la imagen-->
<?php $img = wp_get_attachment_image_src( $thumbnail_id, 'full');?>
<img id="img_prin" src="<?php echo $img[0] ?>" alt="">
<a href="<?php echo get_permalink($the_query->posts[0]);?>">
<h2>
<?php echo $the_query->posts[0]->post_name;?>
</h2>
</a>
<?php $content = get_post_field('post_content', $post_id);?>
<p>
<?php echo $content;?>
</p>
</div>
<div class="nested">
<?php if($count_post>1){?>
<div class="post uno">
<?php $post_id1 = $the_query->posts[1]->ID;?>
<?php $thumbnail_id1 = get_post_thumbnail_id($post_id1);?>
<div class="img_post">
<?php $img1 = wp_get_attachment_image_src( $thumbnail_id1);?>
<img src="<?php echo $img1[0] ?>" alt="">
</div>
<div class="cont">
<h5>
<?php echo $the_query->posts[1]->post_name;?>
</h5>
<?php $full_post1 = get_post_field('post_content', $post_id1);?>
<?php echo $excerpt1 = substr($full_post1,0,50).'...';?>
</div>
</div>
<?php }else{?>
<div class="post uno"><div class="img_post"></div><div class="cont"></div>
</div><?php } ?>
<?php if($count_post>2){?>
<div class="post dos">
<?php $post_id2 = $the_query->posts[2]->ID;?>
<?php $thumbnail_id2 = get_post_thumbnail_id($post_id2);?>
<?php $img2 = wp_get_attachment_image_src( $thumbnail_id2); >
<div class="img_post">
<img src="<?php echo $img2[0] ?>" alt="">
</div>
<div class="cont">
<h5>
<?php echo $the_query->posts[2]->post_name;?>
</h5>
<?php $full_post2 = get_post_field('post_content', $post_id2);?>
<?php echo $excerpt2 = substr($full_post2,0,50).'...';?> <!--EXCERPT-->
</div>
</div>
<?php }else{?>
<div class="post dos"><div class="img_post"></div><div class="cont"></div>
</div><?php } ?>
<?php if($count_post>3){?>
<div class="post tres">
<?php $post_id3 = $the_query->posts[3]->ID;?>
<?php $thumbnail_id3 = get_post_thumbnail_id($post_id3);?>
<?php $img3 = wp_get_attachment_image_src( $thumbnail_id3);>
<div class="img_post">
<img src="<?php echo $img3[0] ?>" alt="">
</div>
<div class="cont">
<h5>
<?php echo $the_query->posts[3]->post_name;?>
</h5>
<?php $full_post3 = get_post_field('post_content', $post_id3);?>
<?php echo $excerpt3 = substr($full_post3,0,50).'...';?>
</div>
</div>
<?php }else{?>
<div class="post tres"><div class="img_post"></div><div class="cont"></div>
</div><?php } ?>
</div>
<?php wp_reset_postdata(); ?>
</div>

links on Bootstrap's nested columns not working when on small screen

I'm trying to have my columns take the complete width of the screen in small screens and divide their content in two columns.
The following structure does that in small screens, but the links on the nested columns don't work when there are more than one column.
note:
when on small screens the links on the last nested columns always work regardless of how many columns there are.
If the columns are filled with the same content of the first column, the links work on small screens.
I really appreciate your help.
Here are my nested columns:
<div class="container ">
<!-- Example row of columns -->
<div class="row reading-field">
<div class="col-md-4">
<div><h2 class="center">Recent<h2></div>
<?php
$postslist = get_posts('numberposts=2&category=-5');
foreach ($postslist as $post) :
setup_postdata($post);
?>
<div class="post col-sm-6 ">
<h3 class="center"><?php the_title(); ?>
</h3>
<p> <?php the_excerpt(); ?> <p>
</div>
<?php endforeach ?>
</div>
<div class="col-md-4">
<div>
<h2 class="center">Media<h2>
</div>
<?php
$postslist = get_posts('numberposts=2&offset=0&category=5');
foreach ($postslist as $post) :
setup_postdata($post);
?>
<div class="post col-sm-6 center">
<h3>
<?php the_title(); ?>
</h3>
<p> <?php the_excerpt(); ?> <p>
</div>
<?php endforeach ?>
</div>
</div>
</div>
This seems to be using Bootstrap (judging by the class names).
You are nesting your columns incorrectly. You can't directly nest a column inside a column. You need to nest a column inside a row inside a column:
<div class="container ">
<!-- Example row of columns -->
<div class="row reading-field">
<div class="col-md-4">
<div class="row"> <!-- ***** This was missing ***** -->
<div><h2 class="center">Recent<h2></div>
<?php
$postslist = get_posts('numberposts=2&category=-5');
foreach ($postslist as $post) :
setup_postdata($post);
?>
<div class="post col-sm-6 ">
<h3 class="center"><?php the_title(); ?>
</h3>
<p> <?php the_excerpt(); ?> <p>
</div>
<?php endforeach ?>
</div> <!-- ***** and don't forget the extra closing tag ***** -->
</div>
</div>
</div>

anchors all link to one point

I am using anchors in my wordpress child theme, the base theme uses a Zurb Foundation Grid.
I am simply using the standard anchor code;
<a name="anchor">
and
<a href="#anchor">
Someone told me that the 'name' thing doesn't work in wordpress and you should use ID, but this still gives me the same result. I have three different anchors but they all get directed to the same spot on the page, even though the names are different and all the tags are nicely closed. Why is this happening? This never happened to me before and hours of googling could not solve my problem.
This is my full html code of the homepage, with the anchors in it.
<?php
/*
Template Name: Homepage
*/
?>
<?php get_header(); ?>
<div id="content" class="twelve columns">
<div id="main" role="main">
<?php echo do_shortcode('[orbit-slider]') ?>
</div> <!-- end #main -->
<div class="row">
<div class="nine columns">
</div>
<div id="logoblock" class="three columns">
<img src="http://i44.tinypic.com/2pyw3sl.png">
</div>
</div>
</div> <!-- end #content -->
<div class="row buttonbar">
<div class="twelve columns rowmargintop">
<div id="downloads" class="four columns"><a href="#downloads">
<img src="http://i39.tinypic.com/2v3j8na.png">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Downloads Button Homepage') ) : ?>
<?php endif; ?>
</a></div>
<div id="locator" class="four columns"><a href="#locator">
<img src="http://i42.tinypic.com/25zgdwj.png">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Locator Button Homepage') ) : ?>
<?php endif; ?>
</a></div>
<div id="specials" class="four columns"><a href="#specials">
<img src="http://i40.tinypic.com/16101l1.png">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Specials Button Homepage') ) : ?>
<?php endif; ?>
</a></div>
</div>
</div>
<div class="row rowmargin">
<div class="twelve columns">
<div class="twelve columns downloadbg">
<a id="downloads">
<div class="four columns downloadcontent">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Download Left') ) : ?>
<?php endif; ?>
</div></a> <div class="four columns downloadcontent">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Download Mid') ) : ?>
<?php endif; ?>
</div>
<div class="four columns downloadcontent">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Download Right') ) : ?>
<?php endif; ?>
</div>
</div>
<div class="twelve columns downloadbg emailmargin">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Email Me') ) : ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="row rowmargin">
<div class="twelve columns">
<div class="twelve columns">
<div class="twelve columns locatorcontent">
<a id="locator">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Store Locator') ) : ?>
<?php endif; ?></a>
</div>
</div>
</div>
<div class="row"><a id="specials">
<div class="twelve columns rowmargin">
<div class="twelve columns">
<div class="twelve columns">
<div class="twelve columns specialcontent specialstop">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Specials Top Content') ) : ?>
<?php endif; ?>
</div>
</div>
<div class="twelve columns">
<div class="twelve columns specialcontent">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Specials Bottom Content') ) : ?>
<?php endif; ?>
</div>
</div>
</div>
</div></a>
</div>
</div> <!-- end twelve columns -->
<?php get_footer(); ?>
And I uploaded the full code of the page when I open it (it's local atm) and use 'show page source', hoping I could give you guys some more info. http://codepad.org/J9OEq49f
remove the id #locator from your wrapper.
<div id="locator" class="four columns"><a href="#locator">
Also, don't ever use more than one id with the same name on a page. It breaks your code.
That's the problem here. You got multiple id's with the same name. He will fixate on your wrapper instead of your content block down the code.
Note: As you already mentioned, you can also use the name attribute instead of an id attribute.

href links not working when nested in data section

So I'm designing a site that utilizes parallax scrolling and the HTML5 data attribute. The problem is that nested in one of the data sections (data-slide), I have a link, and it doesn't seem to work unless I place it outside of the data-slide.
url: http://ericbrockmanwebsites.com/dev3/ (at the bottom of the page, in "projects")
Here's the markup:
<div class="slide" id="slide4" data-slide="4" data-stellar-background-ratio="0">
<div class="container clearfix">
<div class="row">
<div class="span10 offset1">
<div class="row">
<div class="span3">
<div class="slideno">
Projects
</div> <!-- slideno -->
</div> <!-- span3 -->
<div class="span7">
<div class="gridContainer">
<?php $the_query = new WP_Query( array(
'post_type' => 'page',
'post_parent' => 0,
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 999)); // how many posts to show
x = 0;
while ( $the_query->have_posts() ) :
$the_query->the_post(); ?>
<div class="view view-tenth">
<?php the_post_thumbnail('grid-image'); ?>
<div class="mask">
<h2><?php the_title(); ?></h2>
<p></p>
Explore
</div> <!-- mask -->
</div> <!-- view view-tenth -->
<?php $x++; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div> <!-- gridContainer -->
</div> <!-- span7 -->
</div> <!-- row -->
</div> <!-- span10 offset1 -->
</div> <!-- row -->
</div> <!-- container clearfix -->
</div><!-- Slide 4 -->
Any advice on what I am doing wrong or how to get around this?
Thanks, as always!
Did you try this one?
input type="button" name="Release" onclick="document.write('<?php the_permalink() ?>');" value="Explore"
Its a different approach of the href.