Hallo,
ich würde gerne auf einer externen Seite die letzten Posts anzeigen lassen. Nicht per rss feed sondern per script. Im netz hab ich sehr viele scripte gefunden wo man einfach die db connection einträgt und dann läufts. Die links die dabei aber rauskommen sehen dann so aus:
/?p=1234
Meine Permalink Structure ist aber auf:
/%post_id%/%postname%.html
festgelegt, wie kann ich das in folgendem Code ändern:
(geht wohl damit?) $blog_permalink = mysql_result($query_result, $i, "guid");
PHP
<?php
// include your most recent wordpress blog posts in an external page
// free script from 404 Creative Studios -- www.404creative.com
// set the database parameters -- you should be able to find these in your wp-config.php file
$db_username = '';
$db_password = '';
$db_database = '';
$db_path = 'localhost';
// you may be able to use localhost for your database path depending on your setup
// comment out the previous line with the IP address and uncomment the next if you prefer to use localhost
// $db_path = 'localhost';
// connect to the wordpress database
mysql_connect($db_path, $db_username, $db_password);
@mysql_select_db($db_database) or die("Unable to Connect To Database");
// get the post data from the database --- !PLEASE NOTE, "LIMIT 3" determines how many posts will be displayed. Change the number to suit your preference.
$query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 3";
$query_result = mysql_query($query);
$num_rows = mysql_numrows($query_result);
// close the database connection
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8 /">
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="Robots" content="All" />
<meta http-equiv="Imagetoolbar" content="No" />
<title>Recent Blog Posts</title>
<style type="text/css">
<!--
ul#blogposts {margin:0; padding:0;}
.wp_post {list-style-type:none;}
.wp_post img {display:block; clear:both; margin:0 0 10px 0; display:none;}
.wp_post {width:500px; padding:8px; border:1px solid #eee; margin:10px; font-size:13px; font-family:verdana,arial,sans-serif;}
.wp_post h2 {font-family:"century","book antiqua",serif; font-size:20px; font-weight:normal; padding:0; margin:4px 0; font-style:italic;}
.wp_post h2 a {text-decoration:none; color:#333; display:block; width:99%; border-bottom:1px solid #ccc; padding:4px 0;}
.wp_post h2 a:hover {text-decoration:none; color:#0000EE;}
.wp_post a {text-decoration:none;}
.wp_post a.readmorelink {font-style:italic;}
.wp_post div.postcontent {margin:6px 0;}
-->
</style>
</head>
<body>
<ul id="blogposts">
<?php
// start the loop
for($i=0; $i< $num_rows; $i++){
// assign data to the variables
$blog_title = mysql_result($query_result, $i, "post_title");
$blog_content = mysql_result($query_result, $i, "post_content");
$blog_permalink = mysql_result($query_result, $i, "guid");
// set character limit
$maxchars = 350;
// trim post to specified character length
$blog_content = substr($blog_content, 0, $maxchars);
$blog_content = $blog_content . "...";
?>
<li class="wp_post">
<h2><a href="<?php echo $blog_permalink; ?>"><?php echo $blog_title; ?></a></h2>
<div class="postcontent"><?php echo $blog_content; ?></div>
<a href="<?php echo $blog_permalink; ?>" class="readmorelink">Read More</a>
</li>
<?php
} // end the loop
?>
</ul>
</body>
</html>
Alles anzeigen