Solved

PHP HTML error

Posted on 2012-04-09
8
282 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
[X]
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
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 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: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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

623 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