[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

adjust php code

Posted on 2011-10-12
8
Medium Priority
?
301 Views
Last Modified: 2012-05-12
I have the following php code and after the first two blog posts, a sales banner image appears below them.  Below that sales banner image display the remaining blog posts.  However, the image that I'm displaying for those bottom blog posts needs to be a different image.  Any idea how I would do that?
<div class="post<?php if (($counter % 2) == 0) { echo ' last'; } ?>">

			<img src="/images/New-Sales-Banner-$395.png" width="289px;" height="347px;" alt="" title="" align="center" border="0" />
			
			<div class="dotted-line"></div> 
	        </div><!-- /.post -->
		
            <?php if ( $counter == 2 ) { ?>
			
			<div style="margin-bottom: 20px;margin-top: -10px; float:left">
			<a href="/"><img src="/images/DPR-local-sales-banner-b.png" alt="" title="" width="619" height="160" class="noflashbanner" /></a></div>
			<?php } ?>
                                                
        	<?php endwhile; else: ?>            
        
			<?php endif; $counter = 0; ?>

Open in new window

0
Comment
Question by:COwebmaster
  • 5
  • 2
8 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36957947
Line 11.  Replace the information inside the quotes.

src="/images/DPR-local-sales-banner-b.png"
0
 

Author Comment

by:COwebmaster
ID: 36957991
That is the banner graphic that shows up below the top two blog post images.  So I need to add another image below that banner graphic.  so visually, it's like this:

A  A
  B
C  C
C  C
C  C

So, A, B and C are all different image graphics
0
 

Author Comment

by:COwebmaster
ID: 36958647
Actually, I missed adding in some of that code above.  Below is the php code I have.  I changed out the name of the banners to reflect what I'm needing.  So currently only banner A and B is showing up on the page, but I'm not sure where to place banner C so that is shows up like this:

A  A
  B
C  C
C  C
C  C
<?php if (have_posts()) : $counter = 0; ?>
<?php while (have_posts()) : the_post(); $counter++; ?>                                                                
        <div class="post<?php if (($counter % 2) == 0) { echo ' last'; } ?>">

	<img src="/images/A.png" width="289px;" height="347px;" alt="" title="" align="center" border="0" />
			
	<div class="dotted-line"></div>
			
	</div><!-- /.post -->
		
            <?php if ( $counter == 2 ) { ?>			
			<div style="margin-bottom: 20px;margin-top: -10px; float:left">
			<a href="/"><img src="/images/B.png" alt="" title="" width="619" height="160" class="noflashbanner" /></a></div>
	    <?php } ?>
                                                
<?php endwhile; else: ?>            
        
<?php endif; $counter = 0; ?>

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 34

Accepted Solution

by:
Slick812 earned 2000 total points
ID: 36964133
greetings COwebmaster, , I looked over your your code, and it seemed inconsistent to me, in one place you have
if (have_posts()) :
with the : as a way to tell PHP where the if begins, , ans in another place you have
if ( $counter == 2 ) {
with the { as a way to tell PHP where the if begins, I would think that using the same syntax or PHP writing methods throughout your code would help you to read and understand it?

I can not really see what kind of set up the  functions  have_posts()  and  the_post()  do in this stuff, and you give no info about the changing image names, you simple use A.png. B.png etc.

If you are going to run a while loop,and have a counter variable  $counter  then I would use an ARRAY to hold all of your image names.
I have changed your code so I could run it, I had to leave out the functions  have_posts()  and  the_post() , and I used an array to hold the image names, I used GIF images instead of the png, but you will need to change the image names to YOUR images.

I do not have your class diffinitions, so I can only guess at what the image arrangement might be?
I do not see why you use two A's in your-

A  A
  B
C  C
C  C
C  C

I do not see in your code where it displays two side by side images?

I have code below that I ran, and it works to display 5 different images, but I do not see why you have a class with a float:left to get the arrangement you have in your
A  A
  B
C  C
C  C
C  C

where the  B  would have the  float:left ? ?

look at my code and see if it gives you any help in doing what you want to do, ask questions about what does not work for you.
<?php $imgArray = array('a.gif','a.gif','b.gif','c.gif','d.gif','e.gif');
	if (true /*have_posts()*/) { $counter = 0;
	while ($counter < 5 /*have_posts()*/) { /*the_post();*/  $counter++;
		if ( $counter == 2 ) { ?>		
		<div style="margin-bottom: 20px;margin-top: -10px; float:left">
		<a href="/"><img src="/images/<?php echo $imgArray[$counter]; ?>" alt="" title="" width="619" height="160" class="noflashbanner" /></a></div>
			<?php continue;} ?>
		<div class="post<?php if (($counter % 2) == 0) { echo ' last'; } ?>">

		<img src="/images/<?php echo $imgArray[$counter]; ?>" width="289px;" height="347px;" alt="" title="" align="center" border="0" />
			
		<div class="dotted-line"></div>
			
		</div><!-- /.post -->
                                                
<?php } ?>            
        
<?php } $counter = 0; ?>

Open in new window

0
 

Author Comment

by:COwebmaster
ID: 36964307
Hi Ray.  So the two A's represent two banner graphics.  B is a different banner graphic and C is a different banner graphic.

In total, I have 2 A banner graphics, 1 B banner graphic, and 6 C banner graphics.  So I need to loop through each of the 8 blogs that I have and display those graphics in the order like this:

A  A
  B
C  C
C  C
C  C
0
 

Author Comment

by:COwebmaster
ID: 36964606
okay, so I added in each image however, the right side image above the B banner graphic is missing.  Any idea on that?
<?php $imgArray = array('New-Sales-Banner-$395.png','New-Sales-Banner-$395.png','DPR-local-sales-banner-b.png','New-Sales-Banner-$295.png','New-Sales-Banner-$295.png','New-Sales-Banner-$295.png','New-Sales-Banner-$295.png','New-Sales-Banner-$295.png','New-Sales-Banner-$295.png');
	if (true /*have_posts()*/) { $counter = 0;
	while ($counter < 9 /*have_posts()*/) { /*the_post();*/  $counter++;
		if ( $counter == 2 ) { ?>		
		<div style="margin-bottom: 20px;margin-top: -10px; float:left;">		
		<a href="/"><img src="/images/<?php echo $imgArray[$counter]; ?>" alt="" title="" width="619" height="160" class="noflashbanner" /></a>		
		</div>		
		
			<?php continue;} ?>
		<div class="post<?php if (($counter % 2) == 0) { echo ' last'; } ?>">

		<img src="/images/<?php echo $imgArray[$counter]; ?>" width="289px;" height="347px;" alt="" title="" align="center" border="0" />
			
		<div class="dotted-line"></div>
			
		</div><!-- /.post -->
                                                
<?php } ?>            
        
<?php } $counter = 0; ?>

Open in new window

0
 
LVL 34

Expert Comment

by:Slick812
ID: 36965824
I do not know what your html or css may be doing to limit the width, or give other settings to make your images show 2 in a row, since you say that the  New-Sales-Banner-$295.png  or "C" images are in their proper places, 2 by 2, then I will suggest you try and change the code

change line 3 -
if (true /*have_posts()*/) { $counter = 0;

to

if (true /*have_posts()*/) { $counter = -1;

Zero to minus one, I did not change it in the first code, because I thought that the counter may be used in other ways, as a database access or in the code for  the_post($counter);
please see if you can follow what the code is doing, and why if you start it at $counter = -1; , , the first time it is used, it has been changed to zero
0
 

Author Closing Comment

by:COwebmaster
ID: 36965946
Perfect.  Thanks Ray!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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.
While Plesk offers many potential benefits to website administrators, including compatibility with Windows Server and other leading technologies, the company has also been working to differentiate it from other control panels for content management…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 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