DotDragnet
February 07, 2012, 01:25:09 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: word press feed into html page  (Read 623 times)
vee
Full Member
***
Posts: 209



View Profile WWW Awards
« on: July 16, 2010, 04:39:33 PM »

Hi I have a news page ona html site aand I pull a feed from the sites wordpress blog into this page

http://www.london-implants.co.uk/dental-implants-news.html

I did not want to make the page a php page (a n SEO company have done this on the homepage and pull a feed from the same blog using simplepie)

Instead I used the following code in the header of the page

<?php
// Include Wordpress
define('WP_USE_THEMES', false);
require('./news/wp-load.php');
query_posts('showposts=5');
?>

and this code to pull the posts in

<div id="rssfeed">
        <?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>">Read more...</a></p>
<?php endwhile; ?>
      </div>

This works fine (provided text is pasted into excerpt in wordpress) except we are getting stange A characters appearing before £ signs.

My client is also complaining that he does not want to have to paste code into excerpt.

Two questions

1 - any clue whats causing the weird As to appear
2- what code would I need to replace  <?php the_excerpt(); ?> with to pull in the main post?

Grateful for any advice


Many thanks

Vanessa
Logged
Charisma Bypass
Hero Member
*****
Posts: 511



View Profile Awards
« Reply #1 on: July 16, 2010, 06:11:19 PM »

1.  encoding error I think.  iso thingy.

2.  I think it's the_post()
Logged
Haze
Hero Member
*****
Posts: 1469



View Profile Awards
« Reply #2 on: July 18, 2010, 10:44:53 AM »

1. I did see this online, not sure if it will help you.
Logged
sarahA
DDN Contribs
Hero Member
*****
Posts: 2123



View Profile WWW Awards
« Reply #3 on: July 18, 2010, 12:11:13 PM »

1. Yes it's encoding. Are they in the title or excerpt? I think for either, ideally they need to be entered as &pound; alternatively you need a function to encode them before they go into the db. You can try just running the output through htmlentities but I don't know if it'll work with just the output being fixed, but it may do.

Also check the charset in your standalone page is the same as for the WordPress page

2. You may find using get_posts() easier than running the whole loop. However, if the excerpt is empty in a post, usually the excerpt is automatically formed from the content (not the case for pages though). Clearly it's not kicking in for you so then you need to call the_content and use a sub string of that to get the first X characters.

So all in all try

Code:
<?php
function truncate_str($str$maxlen) {
if ( 
strlen($str) <= $maxlen ) return $str;

$newstr substr($str0$maxlen);
if ( 
substr($newstr,-1,1) != ' ' $newstr substr($newstr0strrpos($newstr" "));

return 
$newstr;
}
?>


<div id="rssfeed">
    <?php while (have_posts()): the_post(); ?>
        <h2><?php htmlentities(the_title('','',false), ENT_COMPAT "UTF-8"?></h2>
        <?php
        $mycontent 
strip_tags(get_the_content());
        echo 
"<p>".truncate_str($mycontent)."[...]</p>\n";
        
?>

        <p><a href="<?php the_permalink(); ?>">Read more...</a></p>
    <?php endwhile; ?>
</div>

Note, the first function is to prevent your sub string of the content ending in a split word, so this'll tidy it up. I've run the_title through the htmlentities function, the content shouldn't need it, as WP usually fixes all things like that. If it does then just use the same method to clean that up too.
« Last Edit: July 18, 2010, 12:12:48 PM by sarahA » Logged

vee
Full Member
***
Posts: 209



View Profile WWW Awards
« Reply #4 on: July 18, 2010, 02:04:39 PM »

Thanks Sarah I will give that a go.

If excerpt was empty it did pull content infrom the main content section but wit  lots of rogue As everywhere.

I have not had a great deal of experience with word press so I am very grateful for the advice.

I'll let you know how I get on.
Logged
sarahA
DDN Contribs
Hero Member
*****
Posts: 2123



View Profile WWW Awards
« Reply #5 on: July 18, 2010, 05:00:17 PM »

Ah ok, then maybe just use the excerpt and run it through the htmlentities, however my code is a bit more flexible if you want longer excerpts (note all the html tags are stripped out too, same as an excerpt would be smile)
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!