Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ilikechapstick
Jun 17, 2007

very, very notorious.

magicalblender posted:

How about something like this:
code:
hyphenated_string = substr(string,0,3) . "-" . substr(string, 3,3) . "-" . substr(string,6,4)

Perfect, thanks!
Knew it would be easy...

Adbot
ADBOT LOVES YOU

nbv4
Aug 21, 2002

by Duchess Gummybuns

bt_escm posted:

I found this http://www.webservicex.com/airport.asmx and I was able to get a couple of coordinates for a few airports.

I think google maps would be ideal for this.

Thats not quite as comprehensive as I'd like. Anyways, I found airnav.com, which is 100% comprehensive for american airports, which is about as good and I'm going to find I'm afraid.

Now, I'm wondering, whats the best way to go about mining the data from the page? I'm looking around the web, but I'm not finding much on how to actually build a web crawler... Anyone know of any good resources/tools for doing something like this?

Evil Angry Cat
Nov 20, 2004

nbv4 posted:

Thats not quite as comprehensive as I'd like. Anyways, I found airnav.com, which is 100% comprehensive for american airports, which is about as good and I'm going to find I'm afraid.

Now, I'm wondering, whats the best way to go about mining the data from the page? I'm looking around the web, but I'm not finding much on how to actually build a web crawler... Anyone know of any good resources/tools for doing something like this?

To be honest you're best off using Google Maps. If you notice that searching "KBOS" or "LAX" or "LGW" in Google Maps brings up the airport in question it's jut matter of using the API to get the latitude and longitude (or whatever information you're looking for). Much simpler than parsing a page of tables (which the airnav.com page is) to extract data.

nbv4
Aug 21, 2002

by Duchess Gummybuns

Evil Angry Cat posted:

To be honest you're best off using Google Maps. If you notice that searching "KBOS" or "LAX" or "LGW" in Google Maps brings up the airport in question it's jut matter of using the API to get the latitude and longitude (or whatever information you're looking for). Much simpler than parsing a page of tables (which the airnav.com page is) to extract data.

The reason I wanted to use airnav is because the information is 100% reliable. Relying on Google hits just doesn't seem very robust to me. But anyways, for the hell of it I looked into using the google API, and so far the results I've gotten have been pretty good, so gently caress it, I'll just use google. I have one problem though: Here is the PHP function that I wrote that gets the coordinates and then puts them into the database:

code:
function crawl_google($airport)
	{
		$page = file_get_contents(
			"http://maps.google.com/maps/geo?q={$airport}&output=xml&key=ABQIAAAAtDznsRv92g_KZ0HK9XszwoT5A");
		
		$xml = simplexml_load_string($page);
		
		$location = $xml->Response->Placemark->address;		
		$coordinates = $xml->Response->Placemark->Point->coordinates;
		
		$sql = "INSERT INTO airports (`coordinates`, `location`, `identifier`) VALUES('$coordinates', '$location', '$airport')";
		
		print "$sql<br>\n";
		
		mysql_query($sql);
	
		return $location;
	}
There is a 3 or 4 second delay for the link to return the XML, which adds to to a lot when you have 500 airports to look up. When I load the page that ends up running this function, the page will just hang until it's 100% done, then display all the contents. What kind of voodoo am I going to have to perform to have it print out the stuff progressively, so the user doesn't think the site is down or something?

nbv4 fucked around with this message at 03:35 on May 26, 2008

ohgodwhat
Aug 6, 2005

nbv4 posted:

There is a 3 or 4 second delay for the link to return the XML, which adds to to a lot when you have 500 airports to look up. When I load the page that ends up running this function, the page will just hang until it's 100% done, then display all the contents. What kind of voodoo am I going to have to perform to have it print out the stuff progressively, so the user doesn't think the site is down or something?

Does the location of an airport change really frequently or something? Couldn't you just go through the 500 airports once, storing it in a DB, like it seems you are, and query that when you want to display a page?

If you can't or don't want to do that for some reason, you could use AJAX, and create a page that has some javascript in it that calls another php script that queries Google for that airport, filling in some element of the page when it's received the location. The first page will load as quickly as is normal, and there are plenty of js frameworks that handle the AJAX bit very easily.

Phase
Feb 21, 2007

No matter where I put the function alphanumeric part I always get:
code:
Fatal error:  Call to undefined function alphanumerc() in /var/www/file.php
The specific line the error is talking about is: elseif (!alphanumerc($user)) {

code:
<?PHP
	function alphanumeric($string) {
		if (preg_match('/[[:alnum:]]+/', $string, $matches)
		&& ($matches[0] == $string)) { return 1; }
		return 0;
	}
	if (isset($_POST['submit'])) { 
		$user = $_POST['username']; 
        	$filter = "edited-out";
        	$ldapsearch = "edited-out";
		$ldapsearch_ext = "edited-out";

		echo "<form action=\"file.php\" method=\"POST\">";
		echo "Username: <input type=\"text\" name=\"username\" /><br />";
		echo "<input type=\"checkbox\" name=\"ewhois\" value=\"ewhois\" /> Extended WHOIS ";
		echo "<input type=\"submit\" name=\"submit\" value=\"submit\" />";

		echo "<br />";
		echo "<br />";
		if (alphanumeric($user)) {
			if ($_POST['ewhois']) {
        			system($ldapsearch_ext);
			}
			else {
				system($ldapsearch);
			}
		}
		elseif (!alphanumerc($user)) {
			echo "<span style=\"font-size: small;\">Only usernames containing letters and numers are allowed.</span>";
		}
	}
	else {
		echo "<form action=\"file.php\" method=\"POST\">";
		echo "Username: <input type=\"text\" name=\"username\" /><br />";
		echo "<input type=\"checkbox\" name=\"ewhois\" value=\"ewhois\" /> Extended WHOIS ";
		echo "<input type=\"submit\" name=\"submit\" value=\"submit\" />";
	}
?>
Any ideas? I don't know how to fix this.

MrEnigma
Aug 30, 2004

Moo!

Phase posted:

No matter where I put the function alphanumeric part I always get:
code:
Fatal error:  Call to undefined function alphanumerc() in /var/www/file.php

function alphanumeric($string) {

elseif (!alphanumerc($user)) {

Any ideas? I don't know how to fix this.

Spell it the same way as when you defined it?

bt_escm
Jan 10, 2001

magicalblender posted:

How about something like this:
code:
$hyphenatedstring = substr($string,0,3) . "-" . substr($string, 3,3) . "-" . substr($string,6,4);
edit: whoops, forgot my $s and ;s

This would be so much better as a regular expression
php:
<?
$phone = '2145551212';
$formattedString = preg_replace('/(\d{3})(\d{3})(\d{4})/','$1-$2-$3',$phone);
?>

Evil Angry Cat
Nov 20, 2004

bt_escm posted:

This would be so much better as a regular expression
php:
<?
$phone = '2145551212';
$formattedString = preg_replace('/(\d{3})(\d{3})(\d{4})/','$1-$2-$3',$phone);
?>

Although I think considering the user is so new to php that he thought splitting a string required some sort of loop, substr() is a better method than reg exps.

bt_escm
Jan 10, 2001

Evil Angry Cat posted:

Although I think considering the user is so new to php that he thought splitting a string required some sort of loop, substr() is a better method than reg exps.

Perhaps, but at least now they've seen two ways to do it, and have been given some exposure to a valuable tool.

bt_escm fucked around with this message at 15:51 on May 26, 2008

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

ilikechapstick posted:

Quick question about PHP, I have used it only a couple times and have very limited PHP knowledge.

I have a phone number (of type string) in a database formatted as xxxxxxxxx.

I would like it to be printed as xxx-xxx-xxxx.

My job is to design the webpages, however this is pissing me off from a design standpoint so I need to figure it out. I can only assume I would need some kind of loop, but help me please!

I hope you don't get paid much to "design the webpages" since you can't even google 3 words.

http://www.google.com/search?hl=en&safe=off&q=php+phone+format&btnG=Search

MrEnigma
Aug 30, 2004

Moo!

fletcher posted:

I hope you don't get paid much to "design the webpages" since you can't even google 3 words.

http://www.google.com/search?hl=en&safe=off&q=php+phone+format&btnG=Search

To be fair design and development although sometimes combined (sometimes in the same person) are usually at opposite ends of the spectrum. I wouldn't ever expect our design team to be able to do that.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

MrEnigma posted:

To be fair design and development although sometimes combined (sometimes in the same person) are usually at opposite ends of the spectrum. I wouldn't ever expect our design team to be able to do that.

You can just google it and copy paste the examples with 0 knowledge

Grigori Rasputin
Aug 21, 2000
WE DON'T NEED ROME TELLING US WHAT TO DO

bt_escm posted:

Your authentication scheme is fine for a basic site. I'm assuming you have a collection of php pages that contain the layout and any processing logic in them. Doing that is fine for a smaller site or a site that doesn't really do anything. If you goal is to try and build something more complicated than a site with bunch of content and a few contact forms, then I recommend looking into a framework.

To force the sessions to time out set session.gc_maxlifetime in your php.ini to however many seconds you want before the session file is erased. If you are on a shared host then you may need to use ini_set('session.gc_maxlifetime',#seconds) before you call session start or set it in a .htaccess file for your whole site.

When you say framework, would something like PEAR's Auth be adequate?

ilikechapstick
Jun 17, 2007

very, very notorious.
Right now I am building a website that requires users to have the ability to rate and review things. I have very little PHP knowledge, so I would not know where to start coding a system like this.

The perfect system would be something like this:
http://cityguide.aol.com/washington/bars_and_clubs/ugly-mug/v-190049/

With mySQL integration, etc. It only needs to have 3 simple things, their name, their review, and their rating.

I've been scouring the internet for even tutorials on how to write a system like that but haven't found any. Was wondering if maybe you guys knew of anything out there like this?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

ilikechapstick posted:

I've been scouring the internet for even tutorials on how to write a system like that but haven't found any. Was wondering if maybe you guys knew of anything out there like this?

Did you not like these?

bt_escm
Jan 10, 2001

Grigori Rasputin posted:

When you say framework, would something like PEAR's Auth be adequate?

Yes, pear_auth would be fine. By framework I was talking about a framework like the zend framework, cake or syphony or any of the other dozen or so php frameworks.

w_rogers82
Apr 11, 2008
I'm writing a calendar script for event/project tracking and am trying to figure out how to get the end days of the previous month and/or the beginning days of the following month to fill the calendar.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


date('t', $timestamp) will give you the number of days in the timestamp's month.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

cal_days_in_month() is fun too.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
The PEAR Calendar object may also be useful to you.

iCasm
Jan 23, 2005
Prototypical Non-Conformist
I'm working on a little script to let me download an entire directory as an archive instead of file by file. It's kind of a PHP learning project for me, but here's my first stab at it:
code:
<?php

$loc = $_GET['loc'];
$file = $_GET['file'];

chdir("../$loc");
$sfile = addcslashes($file," ()[]");
$dfile = str_replace(" ","-",$file);

exec("zip -r0 $sfile $sfile");

header("Content-type:application/zip");
header("Content-Disposition:attachment;filename=$dfile.zip");
readfile("$file.zip");

unlink("$file.zip");
?>
The script is working for the most part, but main problem I'm having is that if the download gets canceled, the .zip file gets created but never deleted and hangs around and takes up space.

Also, I'm not sure that my ad hoc text formatting via addcslashes is going to catch all of the cases that might cause problems. Is there another standard method I should be using? What about directories that have an & in the name? How can I pass those through $_GET?

MrEnigma
Aug 30, 2004

Moo!

iCasm posted:

I'm working on a little script to let me download an entire directory as an archive instead of file by file. It's kind of a PHP learning project for me, but here's my first stab at it:
code:
<?php

$loc = $_GET['loc'];
$file = $_GET['file'];

chdir("../$loc");
$sfile = addcslashes($file," ()[]");
$dfile = str_replace(" ","-",$file);

exec("zip -r0 $sfile $sfile");

header("Content-type:application/zip");
header("Content-Disposition:attachment;filename=$dfile.zip");
readfile("$file.zip");

unlink("$file.zip");
?>
The script is working for the most part, but main problem I'm having is that if the download gets canceled, the .zip file gets created but never deleted and hangs around and takes up space.

Also, I'm not sure that my ad hoc text formatting via addcslashes is going to catch all of the cases that might cause problems. Is there another standard method I should be using? What about directories that have an & in the name? How can I pass those through $_GET?

Well you really don't want to drop any variables directly from a GET into a shell command, filter them or do something to prevent that from happening. But if you must do it at least use escapeshellarg (http://us3.php.net/manual/en/function.escapeshellarg.php), this will make it somewhat safe (and prevent you from doing doing addslashes/strreplace).

As far as deleting the file, look into register_shutdown_function, basically when the script dies it will automatically call the function you specify, in this case you would want to have it call a function that calls unlink.

There are also some built in zip functions in php, and if you can use something built in, it's almost always better than having to run stuff directly on the server to get something done, then again the zip stuff might not work for you (http://us3.php.net/manual/en/ref.zip.php)

Edit: Some clarification

MrEnigma fucked around with this message at 21:10 on Jun 1, 2008

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?
I got a PHP/wordpress problem. Basically, I created a template for a page with a custom loop.

Here's the code

code:
<?php 
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('cat=6&showposts=3'.'&paged='.$paged); 
?>

<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
			<ul class="pmeta">
				<li>Posted by <?php the_author() ?></li>
				<li>On <?php the_time('F j, Y') ?></li>
				<li><br /><?php the_category(', ') ?></li>
				<?php if (function_exists('the_tags')) { the_tags('<li>Tags ', '</li>'); } ?>
				<li><br /><?php comments_popup_link('No Comments', '1 Comment', '% Comments' );?></li>
				<?php edit_post_link('Edit', '<li>', '</li>'); ?>
			</ul>
			<div class="apost">
				<h2 id="post-<?php the_ID(); ?>">
<?php if (function_exists('get_cat_icon')) get_cat_icon('small=false'); ?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
				<div class="pmain">
					<!-- spost -->

<?php the_content('Read more...'); ?>

					<!-- epost -->
				</div>
<?php if ($count==1) { ?>

<!-- PLACE YOUR 468x60 ADSENSE CODE (OR BANNER) BELOW -->
<script type="text/javascript"><!--


google_ad_width = 468;

google_ad_height = 60;

//-->

</script>

<script type="text/javascript"

src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

</script>

<!-- PLACE YOUR 468x60 ADSENSE CODE (OR BANNER) ABOVE -->

<?php } ?>
<?php $count = $count + 1; ?>
			</div>
			<div class="extra"></div>
<?php endwhile; ?>
			<div class="lead">
				<span class="ppre"><?php next_posts_link('&laquo; Previous Posts') ?></span>
				<span class="pnex"><?php previous_posts_link('Next Posts &raquo;') ?></span>
			</div>
<?php else : ?>
			<div class="apost">
				<h2 class="subh">Oops!</h2>
				<p class="nopost">Sorry, but you are looking for something that isn't here.</p>
			</div>
<?php endif; ?>
		</div>
	</div>
<?php $wp_query = null; $wp_query = $temp;?>
The problem is that it dies at the ELSE towards the end. What am I doing wrong?

Zorilla
Mar 23, 2005

GOING APE SPIT

clockworkjoe posted:

I got a PHP/wordpress problem. Basically, I created a template for a page with a custom loop.

Here's the code

...

The problem is that it dies at the ELSE towards the end. What am I doing wrong?

Your if and while loops are overlapping instead of one being nested inside the other. Basically, you're doing this:

php:
<?php

while ($condition) :
    if ($condition) :
        // do stuff here
    endwhile;
else :
    // do something else
endif;

?>



When you should be doing this:

php:
<?php

if ($condition) :
    while ($condition) :
        // do stuff here
    endwhile;
else :
    // do something else
endif;

?>

Zorilla fucked around with this message at 00:38 on Jun 2, 2008

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?

Zorilla posted:

Your if and while loops are overlapping instead of one being nested inside the other.

So where should I put what?

Hmm, here's where the original index.php starts

<?php if (have_posts()) : ?>

which I replaced with
<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('cat=6&showposts=3'.'&paged='.$paged); ?>


How can i rewrite the ELSE to say if there are no posts then do this? or am I off base?

Zorilla
Mar 23, 2005

GOING APE SPIT

clockworkjoe posted:

How can i rewrite the ELSE to say if there are no posts then do this? or am I off base?

Probably something like:

php:
<?php if ($wp_query->have_posts) : while ($wp_query->have_posts) : $query->the_post(); ?>

<!-- post loop stuff goes here -->

<?php endwhile; ?>
<?php else: ?>

<!-- error message about no posts being found goes here -->

<?php endif; ?>


I think WordPress handles pages with no entires on them automatically, so there's no need to put an "else" section in your template script.

I also thought of something else. It looks like your template is calling a specific set of posts. The correct way to do this is make a template that calls a generic set of posts (i.e. have_posts() instead of wp_query->have_posts() ) and then giving your template a special meaning by using a comment block at the top. Then, you manage that page in the WordPress backend and tell it to use that custom template instead of the default one. In other words, get rid of all that special query stuff and put this at the top instead:

php:
<?php
/*
Template Name: My Special Template
*/
?>

Zorilla fucked around with this message at 00:53 on Jun 2, 2008

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?
Where do I put the ('cat=6&showposts=3'.'&paged='.$paged); in that code you posted?

I think the else is needed for the formatting - to close off the div tags or something correctly.

I have the special template already set up.

clockworkjoe fucked around with this message at 00:55 on Jun 2, 2008

Zorilla
Mar 23, 2005

GOING APE SPIT

clockworkjoe posted:

Where do I put the ('cat=6&showposts=3'.'&paged='.$paged); in that code you posted?

I think the else is needed for the formatting - to close off the div tags or something correctly.

The idea is that you shouldn't have to force the template to call a fixed set of posts. I think your script will end up like this:

php:
<?php
/*
Template Name: My Special Page
*/
?>

<?php get_header(); ?>

<?php get_sidebar(); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <ul class="pmeta">
            <li>Posted by <?php the_author() ?></li>
            <li>On <?php the_time('F j, Y'?></li>
            <li><br /><?php the_category(', '?></li>
            <?php if (function_exists('the_tags')) : the_tags('<li>Tags ''</li>'); ?>
            <li><br /><?php comments_popup_link('No Comments''1 Comment''% Comments' ); ?></li>
            <?php edit_post_link('Edit''<li>''</li>'); ?>
        </ul>
        
        <div class="apost">
            <h2 id="post-<?php the_ID(); ?>">
                <?php if (function_exists('get_cat_icon')) : get_cat_icon('small=false'); ?>
                <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
            </h2>
            <div class="pmain">
                <!-- spost -->
<?php the_content('Read more...'); ?>
                <!-- epost -->
            </div>
            
<?php if ($count==1) : ?>
            <!-- PLACE YOUR 468x60 ADSENSE CODE (OR BANNER) BELOW -->
            <script type="text/javascript">
            <!--
            google_ad_width = 468;
            google_ad_height = 60;
            //-->
            </script>
            <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
            <!-- PLACE YOUR 468x60 ADSENSE CODE (OR BANNER) ABOVE -->
            
<?php endif; $count $count 1;?>
        </div>
        
        <div class="extra"></div>
        
        <div class="lead">
            <span class="ppre"><?php next_posts_link('&laquo; Previous Posts'?></span>
            <span class="pnex"><?php previous_posts_link('Next Posts &raquo;'?></span>
        </div>
<?php endwhile; endif; ?>

<?php get_footer(); ?>


Then go in the WordPress backend and set that category view to use this template instead of the default. There's a pull-down menu somewhere for this, and with that comment block at the top that says "Template Name:", this template (called "My Special Page") will be listed in it.

I don't know if this method allows you to limit the view to three posts like you probably want, but there's got to be a better way to do this than through a hardcoded query. You might consider moving your Google AdSense code to header.php as well, assuming Google provides a way to call ads to show up in the middle of the page from a script inside <head>.

Zorilla fucked around with this message at 01:28 on Jun 2, 2008

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?
Well it's not pretty but it works. Besides, I only want three posts from category 6.

I will give this a try though.

Zorilla
Mar 23, 2005

GOING APE SPIT
It seems weird, I'm sure, but the idea is that category 6 is set to use this template, rather than the template looking for category 6 (which would be backwards). Flexibility is the key here- and you want as much stuff as possible to be customizable through the WordPress backend as possible instead of having to open up a code editor any time you want to make changes.

If you find no point-and-click way to limit the view to 3 posts, you could probably replace...

while (have_posts()) :

...with...

for ($i = 0;$i < 3;$i++) :

But I would just recommend setting category 6 to paginate every 3 posts. That way, users can view older articles by clicking "Previous Posts" if they wish.

Zorilla fucked around with this message at 01:50 on Jun 2, 2008

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?

Zorilla posted:

It seems weird, I'm sure, but the idea is that category 6 is set to use this template, rather than the template looking for category 6 (which would be backwards). Flexibility is the key here- and you want as much stuff as possible to be customizable through the WordPress backend as possible instead of having to open up a code editor any time you want to make changes.

If you find no point-and-click way to limit the view to 3 posts, you could probably replace...

while (have_posts()) :

...with...

for ($i = 0;$i < 3;$i++) :

But I would just recommend setting category 6 to paginate every 3 posts. That way, users can view older articles by clicking "Previous Posts" if they wish.

how is category 6 is set to use this template? I see nothing in it that refers to cat 6. I also see nothing about paginating a specific category. The thing is, the main index specifically excludes category 6 posts. I want ONLY blog posts under raillery.tv/blog and everything BUT blog posts on the main index. I see no way of doing that in the backend admin interface.

clockworkjoe fucked around with this message at 01:57 on Jun 2, 2008

Zorilla
Mar 23, 2005

GOING APE SPIT
Ok, if there's no way to do that, then yeah, you'd instead need to use your original query method in the template, create a new Page in the WP backend, and then set it to use this template in the pull-down menu.

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?

Zorilla posted:

Ok, if there's no way to do that, then yeah, you'd instead need to use your original query method in the template, create a new Page in the WP backend, and then set it to use this template in the pull-down menu.

How does the code change with the query instead of the If have posts?

Zorilla
Mar 23, 2005

GOING APE SPIT
Just put it back to the way you had it before (except I don't think you needed all those other variable assignments like $temp = $wp_query, as all non-sessioned variables should vanish at the end of a script run. Tell me if I'm totally wrong on this.):

php:
<?php

$wp_query = new WP_Query();
$wp_query->query('cat=6&showposts=3&paged='.$paged);

?>

<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

<!-- stuff that goes after the post text -->

<?php endwhile; ?>

Zorilla fucked around with this message at 02:34 on Jun 2, 2008

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?
I got it from here http://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/

because query posts breaks prev and next links.

Zorilla
Mar 23, 2005

GOING APE SPIT
Ok, it seems like you have this under control, though it seems like it would just be easier to use a different variable name than $wp_posts to instantiate a new object rather than copying its old value elsewhere, then restoring it at the end of the script. I'm sure there's a reason for doing that I don't realize, so I probably shouldn't say anything more.

I think I just wasted 3/4 of a page telling you how to do something that wouldn't actually work. All you really needed to take away from all this is to make sure your if and while loops are nested properly.

Zorilla fucked around with this message at 02:42 on Jun 2, 2008

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?

Zorilla posted:

Ok, it seems like you have this under control, though it seems like it would just be easier to use a different variable name than $wp_posts to instantiate a new object rather than copying its old value elsewhere, then restoring it at the end of the script. I'm sure there's a reason for doing that I don't realize, so I probably shouldn't say anything more.

I think I just wasted 3/4 of a page telling you how to do something that wouldn't actually work. All you really needed to take away from all this is to make sure your if and while loops are nested properly.

This is what I have

code:

<?php
/*
Template Name: zee blog 1
*/
?>

<?php get_header(); ?>

<?php 
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('cat=6&showposts=3'.'&paged='.$paged); 
?>

<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
		<ul class="pmeta">
			<li>Posted by <?php the_author() ?></li>
			<li>On <?php the_time('F j, Y') ?></li>
			<li><br /><?php the_category(', ') ?></li>
			<?php if (function_exists('the_tags')) : the_tags('<li>Tags ', '</li>'); ?>
			<li><br /><?php comments_popup_link('No Comments', '1 Comment', '% Comments' ); ?></li>
			<?php edit_post_link('Edit', '<li>', '</li>'); ?>
		</ul>
		
		<div class="apost">
			<h2 id="post-<?php the_ID(); ?>">
				<?php if (function_exists('get_cat_icon')) : get_cat_icon('small=false'); ?>
				<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
			</h2>
			<div class="pmain">
				<!-- spost -->
<?php the_content('Read more...'); ?>
				<!-- epost -->
			</div>
			
<?php if ($count==1) : ?>
			<!-- PLACE YOUR 468x60 ADSENSE CODE (OR BANNER) BELOW -->
			<script type="text/javascript"><!--

google_ad_client = "pub-3013390817658009";

/* 468x60, created 4/26/08 */

google_ad_slot = "3972895344";

google_ad_width = 468;

google_ad_height = 60;

//-->

</script>

<script type="text/javascript"

src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

</script>
			<!-- PLACE YOUR 468x60 ADSENSE CODE (OR BANNER) ABOVE -->
			
<?php endif; $count = $count + 1;?>
		</div>
		
		<div class="extra"></div>
		
		<div class="lead">
			<span class="ppre"><?php next_posts_link('&laquo; Previous Posts') ?></span>
			<span class="pnex"><?php previous_posts_link('Next Posts &raquo;') ?></span>
		</div>
<?php endwhile; endif; ?>


<?php get_sidebar(); ?>
<?php get_footer(); ?>

Screws up on the ENDWHILE

clockworkjoe
May 31, 2000

Rolled a 1 on the random encounter table, didn't you?
Also, this is the index.php which works correctly so use that as a reference

code:

<?php get_header(); ?>
<?php
   if (is_home()) {
      query_posts("cat=-6");
   }
?>


<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
			<ul class="pmeta">
				<li>Posted by <?php the_author() ?></li>
				<li>On <?php the_time('F j, Y') ?></li>
				<li><br /><?php the_category(', ') ?></li>
				<?php if (function_exists('the_tags')) { the_tags('<li>Tags ', '</li>'); } ?>
				<li><br /><?php comments_popup_link('No Comments', '1 Comment', '% Comments' );?></li>
				<?php edit_post_link('Edit', '<li>', '</li>'); ?>
			</ul>
			<div class="apost">
				<h2 id="post-<?php the_ID(); ?>">
<?php if (function_exists('get_cat_icon')) get_cat_icon('small=false'); ?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
				<div class="pmain">
					<!-- spost -->

<?php the_content('Read more...'); ?>

					<!-- epost -->
				</div>
<?php if ($count==1) { ?>

<!-- PLACE YOUR 468x60 ADSENSE CODE (OR BANNER) BELOW -->



<!-- PLACE YOUR 468x60 ADSENSE CODE (OR BANNER) ABOVE -->

<?php } ?>
<?php $count = $count + 1; ?>

			</div>

			<div class="extra"></div>
<?php endwhile; ?>

			<div class="lead">
				<span class="ppre"><?php next_posts_link('&laquo; Previous Posts') ?></span>
				<span class="pnex"><?php previous_posts_link('Next Posts &raquo;') ?></span>
			</div>
<?php else : ?>
			<div class="apost">
				<h2 class="subh">Oops!</h2>
				<p class="nopost">Sorry, but you are looking for something that isn't here.</p>
			</div>
<?php endif; ?>
		</div>
	</div>
	
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php

?>

Adbot
ADBOT LOVES YOU

Zorilla
Mar 23, 2005

GOING APE SPIT
You have this:

<?php endwhile; endif; ?>

...when you should have this (like shown in my example)...

<?php endwhile; ?>

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply