Solved

PHP HTML error

Posted on 2012-04-09
8
281 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Form submit takes only for one form 23 54
Error Handler 8 43
html link offset in page with umlaut character in address 5 32
change site header 8 32
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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).

751 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