Solved

PHP HTML error

Posted on 2012-04-09
8
275 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now