2012-06-20 48 views
1

之外我在我的定制网站WordPress的博客,我显示来自WordPress博客的一些文章到我的网站基于标签,如下面显示WordPress的某些部分发布的WordPress博客

require('../news/wp-blog-header.php'); 
          $query = new WP_Query('tag=Dalaman'); 

          if ($query->have_posts()): 
           while ($query->have_posts()) : $query->the_post(); 
            ?> 
            <h3> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
            <p><?php the_content();?></p> 
            <?php 
           endwhile; 
          endif; 

the_content显示10 posts从WordPress数据库基于WP_Query

问题:我想显示文章的某一部分,让我们说55个chracters 岗位,我的数据库不具有默认excerpt,我做NT要使用the_exerpt()因为它删除HTML代码和我的帖子包含<img>对每一个岗位

我尝试了很多事情,但徒劳都去了,我也用PHP的substr()功能的开始,但它并没有在这种情况下工作。

那么我如何显示帖子的某些部分与图像?

非常感谢。

亲切的问候!

回答

1

,你可以像下面,

$limit = 55; 
          $content = explode(' ', get_the_content(), $limit); 

          if (count($content) >= $limit) { 
           array_pop($content); 
           $content = implode(" ", $content) . '...'; 
          } else { 
           $content = implode(" ", $content); 
          } 
          $content = preg_replace('/\[.+\]/', '', $content); 
          $content = apply_filters('the_content', $content); 
          $content = str_replace(']]>', ']]&gt;', $content); 
          echo $content; 
+0

哦克拉,它的工作。谢谢队友! – user1458253

1

http://codex.wordpress.org/Function_Reference/the_content

我建议你做的文章说什么,并插入一个<!--more-->在每当断点 - 这是比剥离的任意字符的数量,因为你可能会打破你的HTML标记,这样更安全。

如果你不担心这一点,那么代替

<?php the_content(); ?> 

<?php 
$content = get_the_content(); //get the content as a string 
$content = substr($content, 0, 55); //cut the first 55 characters 
echo $content; //display it as usual 
?> 
+0

对不起队友,它不工作通过这种方式,注定要注意 – user1458253

+0

,并且我还导入了其他cutom博客条目的所有帖子,所以帖子没有''和我acnt修改所有职位,因为他们更2000计数,所以必须这样做,我不知道为什么 – user1458253

+0

*如何*这是“不工作”?你有错误吗,你会得到一个不想要的结果吗? – pixelistik