Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mariahlullaby

macrumors 6502a
Original poster
Jan 19, 2005
852
3
NYC
Hi,

Can anyone help me with this problem? I'm not a programmer by any means, so I don't know what I'm screwing up. I want to add a section on the front page of my site listing my latest blog posts. I'm following the instructions from Word Press and making sure to change the URLs in the code to reflect mine. Instead of it doing anything, I'm just getting some gross text of a portion of the code on the main page. Any thoughts?

If you need to see it to know what I mean, just post here and I'll upload a screen cap. Thanks, guys!
 
Can we see the code? It could be all sorts of things.

One thing to check for might be missed quote marks in strings. Or perhaps unescaped quote marks.

That means, if you wanted to put this into your page:

It's cold.

You couldn't do:

PHP:
echo 'It's cold.';

You'd have to do one of these:

PHP:
echo 'It\'s cold.'; // escaping the apostrophe
echo "It's cold.";
echo 'It’s cold.';

That first method is called "escaping". The backslash isn't printed.

Anyway, that's my guess, but it could be something completely different.
 
Thank you! For reference, I uploaded a demo of the page here: http://www.w3promotions.com/home.html

The code is:

PHP:
									<?php
$how_many=3; //How many posts do you want to show
require_once("/blog/wp-config.php"); // Change this for your path to wp-config.php file ?>
<ol id="whats-new">
<?
$news=$wpdb->get_results("SELECT `ID`,`post_title` FROM $wpdb->posts
WHERE `post_type`=\"post\" AND `post_status`= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
foreach($news as $np){
print ("<li><a href=\"");
echo get_permalink($np->ID);
print ("\">$np->post_title</a></li>");
} ?>
</ol>
 
Thank you! For reference, I uploaded a demo of the page here: http://www.w3promotions.com/home.html

The code is:

PHP:
									<?php
$how_many=3; //How many posts do you want to show
require_once("/blog/wp-config.php"); // Change this for your path to wp-config.php file ?>
<ol id="whats-new">
<?
$news=$wpdb->get_results("SELECT `ID`,`post_title` FROM $wpdb->posts
WHERE `post_type`=\"post\" AND `post_status`= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
foreach($news as $np){
print ("<li><a href=\"");
echo get_permalink($np->ID);
print ("\">$np->post_title</a></li>");
} ?>
</ol>

Make the <? into <?php. Some servers need the php added to <? to be interpreted correctly.
 
It seems like no PHP is being executed. That could be because the server isn't set up to recognise .html files as PHP. Perhaps you could try renaming it to home.php instead and see if that makes a difference.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.