Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP HTML error

Posted on 2012-04-09
8
279 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:jonathan1978
  • 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:jonathan1978
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

Author Comment

by:jonathan1978
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:jonathan1978
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 500 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:jonathan1978
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
multiple selects 23 48
selector:validator cookies 4 30
2 separate CSS animations 2 16
IF statment In Powershell 12 15
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

860 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