php query_posts orderby=random causing css to break - php

<?php query_posts($query_string . '&orderby=rand') ?>
Hey all,
I've tried to implement the above piece of code into my portfolio page template.php.
http://www.some-things.net/category/work/
It's causing the css to break every so often. Reload it until it breaks and you will see what I mean. It pushes 2 of the portfolioitem blocks to the right a touch and forces the third to drop a line?
<div style="clear:both"></div>
<div class="gallery">
<?php query_posts($query_string . '&orderby=rand') ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="portfolioItem">
<a href="<?php the_permalink() ?>" class="desctitle" title="<?php the_title();?>"><?php the_post_thumbnail(); ?>
<span class="desctitle"><?php the_title(); ?></a>
</span>
</div>
<?php endwhile; ?>
</div>

The error isn't in the random layout code. It's caused by an empty "tile" in your page. here's the source of the offending tile:
<div class="portfolioItem">
<span class="desctitle">Love Jungle</span>
</div>
Notice there's no image.

Related

Toggle Show/Hide Configuration on Mobile - ACF Repeater

I am using the ACF Repeater to create rows of images/content and to show/hide when clicked. Everything looks good on desktop screens, with a row of 3 images, when an image is clicked, the hidden div shows up below and the background color toggles on so you know which image's content you are looking at.
My problem, is I am trying to get the same functionality on mobile, but when an image is clicked, the content shows up under the 3rd div. I want to be below the image that was clicked. Since I am using the ACF repeater, my php script creates the parent div (3 across) first and then the hidden divs below.
I don't mind creating a separate html markup for mobile, I just can't figure out how to make it work with the ACF repeater.
<div class="staff">
<?php if (have_rows('staff_rows')):
while (have_rows('staff_rows')): the_row(); ?>
<div class="staff-wrap">
<div class="staff_images">
<?php if (have_rows('staff_images')):
while (have_rows('staff_images')): the_row(); ?>
<a href="#/" class="<?php the_sub_field('staff_class'); ?> show staff-box">
<img src="<?php the_sub_field('staff_image'); ?>"><div class="image-box"><h3>
<?php the_sub_field('staff_name'); ?></h3>
<h3><?php the_sub_field('staff_position'); ?></h3></div>
</a>
<?php endwhile;
endif; ?>
<?php if (have_rows('staff_bios')):
while (have_rows('staff_bios')): the_row(); ?>
<div class="bios">
<div class="wrap">
<div class="<?php the_sub_field('bio_class'); ?> row"><?php
the_sub_field('bio_text'); ?></div>
</div>
</div>
<?php endwhile;
endif; ?>
</div>
http://toolboxdevmachine.com/TechNiche/about-us
Thanks for your help
I'm guessing you've already figured this out by now, in 2019. It looks like you are missing a few closing <div> tags, as well as ending your while loop and the primary conditional. I broke out the code, indented it and wrote it with the correct closing tags:
<div class="staff">
<?php if (have_rows('staff_rows')):
while (have_rows('staff_rows')): the_row(); ?>
<div class="staff-wrap">
<div class="staff_images">
<?php if (have_rows('staff_images')):
while (have_rows('staff_images')): the_row(); ?>
<a href="#/" class="<?php the_sub_field('staff_class'); ?> show staff-box">
<img src="<?php the_sub_field('staff_image'); ?>">
<div class="image-box">
<h3><?php the_sub_field('staff_name'); ?></h3>
<h3><?php the_sub_field('staff_position'); ?></h3>
</div>
</a>
<?php endwhile;
endif; ?>
<?php if (have_rows('staff_bios')):
while (have_rows('staff_bios')): the_row(); ?>
<div class="bios">
<div class="wrap">
<div class="<?php the_sub_field('bio_class'); ?> row">
<?php the_sub_field('bio_text'); ?>
</div>
</div>
</div>
<?php endwhile;
endif; ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>

Wordpress post page loop acting strange

I am having an issue with my Wordpress post loop where if I add or update a post it decides to kill one odd and it disappears? Has any had this issue before?
<?php query_posts('posts_per_page=4&cat=3'); while(have_posts()) : the_post(); ?>
<div class="eventPostOuter">
<div class="eventPost">
<span class="eventsImage">
<?php the_post_thumbnail( array(200,200) ); ?></span>
<h3><?php the_title(); ?></h3>
<span style="padding-bottom: 40px;" class="exerpt"><p><?php echo substr(get_the_excerpt(), 0,200); ?> [...]</p></span>
<!--<span class="excerpt" style="padding-top: 20px;"><p><a class="excerptLink" href="<?php the_permalink(); ?>">Read full article</a></p></span>-->
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
That is my code, perhaps I have made an error in there somewhere? I am unable to see what the issue is and it has only just begun doing it...
Ok, I fixed the issue which is so strange, I changed the character limit from 200 to 180 and all of the posts show perfectly. :S

Getting the post title in index php in a while loop

I have
<?php while ( have_posts() ) : the_post(); ?>
<div class="boxes-third boxes-first">
<div class="latestthree">
<div class="title">
<?php get_the_title($id); ?> // I am trying to get the post title here but doesn't work
<span class="titlearrow"></span>
</div>
<div class="latestthreeimage">
<a rel="prettyPhoto" title="<?php get_the_title($id); ?>"> /same here
<?php the_post_thumbnail(array(300,133)); ?>
</a></div>
<div class="text">
Here i would like to get the excerpt of the post that is no longer than 25 words
<span class="textarrow"></span>
</div>
</div>
</div>
<?php endwhile; ?>
I am trying to do the above mentioned, but did not worked and on the last one did not find related info. I am using wp 3.7.1. Please help me.
You have used get_the_title() which does not print. To print out the title, add an extra echo:
<?php echo get_the_title(); ?>
Or you can use the_title(), which also prints:
<?php the_title();?>
Try just using,
the_title();
Reference.

WordPress: Parse error: syntax error, unexpected '<' in C:\Inetpub\wwwroot\

This is my first major WordPress site from absolute scratch. My PHP skills are only starting out and this is the error I am getting. I know what the problem is, I just don't know how to write this block of PHP code correctly and would appreciate some help please.
As far as I have read, I cannot put html markup into a block of PHP code like I have done here which is odd, as all the example WP Loops I have seen has HTML markup in it.
<?php
/**
* Template Name: Home Page
*
* This Full Width template removes the primary and secondary asides so that content
* can be displayed the entire width of the #content area.
*
*/
// calling the header.php
get_header();
// action hook for placing content above #container
thematic_abovecontainer();
?>
<div id="container">
<?php thematic_abovecontent(); ?>
<div id="content" class="home-content">
<?php
// calling the widget area 'page-top'
get_sidebar('page-top');
the_post();
thematic_abovepost();
?>
<div id="post-<?php the_ID();
echo '" ';
if (!(THEMATIC_COMPATIBLE_POST_CLASS)) {
post_class();
echo '>';
} else {
echo 'class="';
thematic_post_class();
echo '">';
}
// creating the post header
// thematic_postheader();
?>
<div class="entry-content">
<?php
the_content();
wp_link_pages("\t\t\t\t\t<div class='page-link'>".__('Pages: ', 'thematic'), "</div>\n", 'number');
edit_post_link(__('Edit', 'thematic'),'<span class="edit-link">','</span>') ?>
</div>
</div><!-- .post -->
<div class="featureBlocks">
<div class="news">
<div class="featTitle">
<h3>News <br />& Events</h3>
<div class="featSubTitle">What's happening in the world of Process Engineering</div>
<div class="clear"></div>
</div>
<?php
query_posts('cat=4&posts_per_page=1');
if (have_posts()) : while (have_posts()) : the_post();
the_title();
the_content();
/*<a href='<?php the_permalink(); ?>' rel='bookmark' title='Permanent Link to <?php the_title_attribute(); ?>'><?php the_title(); ?></a>*/
endwhile; endif;
// Reset Query
wp_reset_query();
?>
</div>
<div class="research">
<div class="featTitle">
<h3>Research <br />Highlights</h3>
<div class="featSubTitle">Find out what exciting research is happening Process Engineering</div>
<div class="clear"></div>
</div>
<?php
query_posts('cat=5&posts_per_page=1');
if (have_posts()) : while (have_posts()) : the_post();
<strong>the_title();</strong>
the_content();
endwhile; endif;
// Reset Query
wp_reset_query();
?>
</div>
<div class="studentStories">
<div class="featTitle">
<h3>Student <br />Stories</h3>
<div class="featSubTitle">Student life at the Department of Process Engineering</div>
<div class="clear"></div>
</div>
<?php
query_posts('cat=6&posts_per_page=1');
if (have_posts()) : while (have_posts()) : the_post();
the_title();
the_content();
endwhile; endif;
// Reset Query
wp_reset_query();
?>
</div>
<div class="clear"></div>
</div>
<?php
thematic_belowpost();
// calling the comments template
thematic_comments_template();
// calling the widget area 'page-bottom'
get_sidebar('page-bottom');
?>
</div><!-- #content -->
<?php thematic_belowcontent(); ?>
</div><!-- #container -->
<?php
// action hook for placing content below #container
thematic_belowcontainer();
// calling footer.php
get_footer();
?>
I'd appreciate it if someone could show me what I am doing wronf.
Many thanks!
You have an unquoted string inside a <?php ?> block. Anything inside these blocks is interpreted as PHP syntax instead of raw HTML.
This line:
<h1>the_title();</h1>
Should probably be something like:
echo '<h1>' . the_title() . '</h1>';
Here, we concatenate <h1>, the output of the_title() and </h1> together to form a single string.
The syntax error pertains to the first < present in the <h1> tag. As it's not valid PHP syntax in the context it's in (being inside <?php ?> tags), it throws an error. As Pekka says, SO's syntax highlighting picks this up almost instantly.
You should check your code more thoroughly and find an editor with syntax highlighting or turn it on if you already have a capable one. The PHP errors usually give a line number. Find the line, and work out what the error is.
In the problem outlined in the comments (this: <strong>the_title();</strong> throwing an error), PHP is again encountering unquoted string literals. <strong> is perfectly invalid PHP syntax, because you haven't quoted it into a string.
This:
<strong>the_title();</strong>
Needs to become this:
echo '<strong>' . the_title() . '</strong>';
Please consider reading up on basic PHP syntax such as this; it's a trivial problem and is covered by many tutorials.
As a newbie, I would like to use something like that:
<div class="news">
<div class="featTitle">
<h3>News <br />& Events</h3>
<div class="featSubTitle">What's happening in the world of Process Engineering</div>
<div class="clear"></div>
</div>
<?php
query_posts('cat=4&posts_per_page=1');
if (have_posts()) : while (have_posts()) : the_post();
?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<a href='<?php the_permalink(); ?>' rel='bookmark' title='Permanent Link to <?php the_title_attribute(); ?>' ><?php the_title(); ?></a>
<?php
endwhile; endif;
// Reset Query
wp_reset_query();
?>
</div>
Wrapping only php code inside <?php CODE ?> tag.
Someone else managed to answer my question on another forum. Kash, I hope this works for you too.
<?php query_posts('cat=5&posts_per_page=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<strong><?php the_title();?></strong>
<?php the_content();
endwhile; endif;
?>
Thanks everyone else who pitched in! :)

Accordion Issue

I am setting up this site at games.nyls.edu. If you see when you click on any of the links on the 2nd column it opens up the first link. heres the code:
<?php query_posts('category_name=computable-diagrams&showposts=10'); ?>
<?php echo '<a onclick="changeCssClass(\'widget-title3\')" id="imageDivLink" href="javascript:toggle3(\'wp-cpl-widget3\', \'imageDivLink\');"><h3 id="widget-title3" class="widget-title">Computable Diagrams</h3></a> <ul id="wp-cpl-widget3" class="wp-cpl-widget" style="display: none;">'; while (have_posts()) : the_post(); ?>
<li class="wp-cpl wp-cpl-even"><a href="javascript:toggle9('testcontent3', 'imageDivLink6');">
<?php the_title(); ?>
</a> </li><div id="testcontent3" style="display:none;"><?php the_content();?></div>
<?php endwhile; ?>
</ul>
I would appreciate any help
<div id="testcontent3" style="display:none;">
this is inside loop ... will produce duplicate ids on the page ...you need to have unique id's for divs

Categories