Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP HTML error

Posted on 2012-04-09
8
Medium Priority
?
285 Views
Last Modified: 2012-04-09
I am having trouble with my All Artist page being displayed correctly.  I would like Each Category be displayed left to right,  3 Categories per line,  then artists attached to that cateogry listed underneath.  

I think i have my Query wrong though, seems like it is closing off a div to early.  

Here is the page in question My Website

And here is the template code for that page :

<?php
/**
 Template Name:  All Artists 
 */
get_header(); ?>
<div id="primary">
<div id="content" role="main">
	<div id="full-white" style="background:#fff;color:#333;width:800px;">

		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<div class="inner">
				
				<header class="entry-header">
					<h1 class="entry-title">Registry</h1>	
				</header>
	<?php
		$hide_empty = true;
		$hierarchical = true;
		$args = array(
 				'hide_empty' => $hide_empty,
 				'hierarchical' => $hierarchical,
			);
			$catarray = get_terms('category',$args);
			//print_r($catarray);
				foreach ($catarray as $category) {
   				$catid = $category->term_id;
   				$link = get_category_link($catid);
   					if (!$hide_empty || $hierarchical) {
      						echo "<div class='category-list'> <h2 class='cat-title'>$category->name</h2>";
   					}
   						//echo '<p>';print_r($category);echo '</p>';
   					$myquery = new WP_Query(array('category__in' => array($catid), 'post_type' => 'artist'));
   						if ($myquery->have_posts()) :
      						if ($hide_empty && !$hierarchical ) 
							echo "<div class='category-list'> <h2 class='cat-title'>$category->name</h2>";
      						while ($myquery->have_posts()) : $myquery->the_post(); ?>
         					<ul>	
                            	<li class ="artist-links">
           							 <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
           							 	<?php the_title(); ?>
           							 </a>
                                </li>
                            </ul>
                                </div>
            
      					<?php endwhile;
   						else:
      							if (!$hide_empty || $hierarchical) echo '<p> &nbsp;&nbsp;&nbsp;- None Found -</p>';
   						endif;
				}
			?></div>
    
				
	</div>
</div><!-- #content -->
<!-- insert Gallery Hours, Facebook & Twitter -->		
<?php require_once( get_stylesheet_directory(). '/connections.php' ); ?>
</div><!-- #primary -->

<?php get_footer(); ?>

Open in new window

0
Comment
Question by:Jon Imms
  • 4
  • 4
8 Comments
 
LVL 7

Expert Comment

by:rgranlund
ID: 37824375
You are not closing this first div, before you start the next "Category-List";

//print_r($catarray);
				foreach ($catarray as $category) {
   				$catid = $category->term_id;
   				$link = get_category_link($catid);
   					if (!$hide_empty || $hierarchical) {
      						echo "<div class='category-list'> <h2 class='cat-title'>$category->name</h2>";
   					}
   						//echo '<p>';print_r($category);echo '</p>';
   					$myquery = new WP_Query(array('category__in' => array($catid), 'post_type' => 'artist'));
   						if ($myquery->have_posts()) :
      						if ($hide_empty && !$hierarchical ) 

Open in new window

Close the category-list, after this initial div and for all other "category-list" divs after this. The way you have it they are all printing into each prior div.
0
 

Author Comment

by:Jon Imms
ID: 37824409
Where do i put the closing div ??  sorry, i cannot see where to put it in the code.
0
 
LVL 7

Expert Comment

by:rgranlund
ID: 37824705
Should it be here?

foreach ($catarray as $category) {
                           $catid = $category->term_id;
                           $link = get_category_link($catid);
                                 if (!$hide_empty || $hierarchical) {
                                          echo "<div class='category-list'> <h2 class='cat-title'>$category->name</h2></div>";
                                 }

Also, I ran it through: http://validator.w3.org/ and you are missing a closing div.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Jon Imms
ID: 37824937
No that is wrong putting the end div there

Basically i want my loop to be

<div class="category-list">
  <h2 class="cat-title">$category->name</h2>
  <ul>	
       <li class ="artist-links">
           <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
       </li>
   </ul>
</div><!-- #category-list -->

Open in new window

<?php
/**
 Template Name:  All Artists 
 */
get_header(); ?>
<div id="primary">
<div id="content" role="main">
	<div id="full-white" style="background:#fff;color:#333;width:800px;">

		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<div class="inner">
				
				<header class="entry-header">
					<h1 class="entry-title">Registry</h1>	
				</header>
	<?php
		$hide_empty = true;
		$hierarchical = true;
		$args = array(
 				'hide_empty' => $hide_empty,
 				'hierarchical' => $hierarchical,
			);
		$catarray = get_terms('category',$args);
		//print_r($catarray);
		foreach ($catarray as $category) {
   			$catid = $category->term_id;
   			$link = get_category_link($catid);
   				if (!$hide_empty || $hierarchical) {
      				echo "<div class='category-list'> <h2 class='cat-title'>$category->name</h2></div>";
   				}
   					//echo '<p>';print_r($category);echo '</p>';
   			$myquery = new WP_Query(array('category__in' => array($catid), 'post_type' => 'artist'));
   				if ($myquery->have_posts()) :
      				if ($hide_empty && !$hierarchical ) 
						echo "<div class='category-list'> <h2 class='cat-title'>$category->name</h2></div>";
      				while ($myquery->have_posts()) : $myquery->the_post(); ?>
         				<ul>	
                       		<li class ="artist-links">
           						<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
           							<?php the_title(); ?>
           						</a>
                          	</li>
                       	</ul>
                     
            
      					<?php endwhile;
   						else:
      							if (!$hide_empty || $hierarchical) echo '<p> &nbsp;&nbsp;&nbsp;- None Found -</p>';
   						endif;
					}
			?>
			</div><!-- #inner -->
    </article>
    
	</div><!-- #full-white -->
</div><!-- #content -->
<!-- insert Gallery Hours, Facebook & Twitter -->		
<?php require_once( get_stylesheet_directory(). '/connections.php' ); ?>
</div><!-- #primary -->

<?php get_footer(); ?>

Open in new window

0
 
LVL 7

Expert Comment

by:rgranlund
ID: 37825033
You can see, if you run it through the validator, you are missing a closing div, someplace within that script.
0
 

Author Comment

by:Jon Imms
ID: 37825045
I've figured it out.

needed to close the div after the endwhile

<?php
/**
 Template Name:  All Artists 
 */
get_header(); ?>
<div id="primary">
<div id="content" role="main">
	<div id="full-white" style="background:#fff;color:#333;width:800px;">

		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<div class="inner">
				
				<header class="entry-header">
					<h1 class="entry-title">Registry</h1>	
				</header>
				<?php
					$hide_empty = true;
					$hierarchical = true;
					$args = array(
 							'hide_empty' => $hide_empty,
 							'hierarchical' => $hierarchical,
							);
					$catarray = get_terms('category',$args);
					foreach ($catarray as $category) {
   						$catid = $category->term_id;
   						$link = get_category_link($catid);
   					if (!$hide_empty || $hierarchical) {
      						echo "<div class='category-list'> <h2 class='cat-title'>$category->name</h2>";
   						}

   					$myquery = new WP_Query(array('category__in' => array($catid), 'post_type' => 'artist'));
   					if ($myquery->have_posts()) :
      				if ($hide_empty && !$hierarchical ) 
							echo "<div class='category-list'> <h2 class='cat-title'>$category->name</h2>";
      				while ($myquery->have_posts()) : $myquery->the_post(); ?>
         			<ul>	
                    	<li class ="artist-links">
           					<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
           						<?php the_title(); ?>
           					</a>
                      	</li>
                     </ul>
                     
            
      					<?php endwhile;
      					echo "</div>"; 
   						else:
      							if (!$hide_empty || $hierarchical) echo '<p> &nbsp;&nbsp;&nbsp;- None Found -</p>';
   						endif;
					}
			?>
			</div><!-- #inner -->
    </article>
    
	</div><!-- #full-white -->
</div><!-- #content -->
<!-- insert Gallery Hours, Facebook & Twitter -->		
<?php require_once( get_stylesheet_directory(). '/connections.php' ); ?>
</div><!-- #primary -->

<?php get_footer(); ?>

Open in new window

0
 
LVL 7

Accepted Solution

by:
rgranlund earned 2000 total points
ID: 37825061
Awesome.  I bet you feel a great sense of relief!  Sometimes, it can be pesky finding the small things.  I would recommend using a lot more comments in you script, showing where each part stops and starts.  It can't hurt.
0
 

Author Comment

by:Jon Imms
ID: 37825129
Cheers for your help on this.  I did not write the script, so looking in as a 3rd party, but agree with the comments,  always makes life easier for everybody.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question