2013-07-03 33 views
0

我刚刚完成了这个网站,我想将现有的wordpress与它整合。 注意上我想从WordPress数据库拉文和短表显示为如下在现有网站中整合wordpress文章

图像0​​标题 摘录

我也想充分帖子的内容到另一个页面博客页面显示的主页。 即

获取从DB 显示内容

帖子内容所有我想知道的是,有没有办法,只是从数据库中获取该帖的内容,并使用它,因为我想在我的自定义页面?

+0

这是绝对有可能的,但最好的行动当然会将您现有的网站集成到WP主题中。 –

+0

如何做到这一点,与php很好 – Udo

+0

请参阅下面的回答,将WordPress带到Wordpress以外的地方:}可能需要根据您的环境和WP的安装位置来调整路径到“wp-load.php”。 –

回答

1

可以WordPress的外部访问WordPress和执行查询,像这样:

<?php 

    // Bring in WordPress 
    require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'); 

    // Setup your query 
    $args = array(
     'numberposts' => 3, 'orderby' => 'date', 'order' => 'DESC', 'post_status'=>'publish' 
     // adjust as you need 
    ); 

    // Execute your query 
    $posts = new WP_Query($args); 
    if($posts->have_posts()) { 
     while($posts->have_posts()) { 
      // Loop through resulting posts 

      $posts->the_post(); 
      if (has_post_thumbnail(get_the_ID())) { 
       $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'thumb-rectangle'); 
      } 

      // Now do something with your post 
?> 
<div class="pod"> 
<?php if($thumbnail) { ?><img src="<?php echo($thumbnail[0]); ?>" width="" height="" alt="<?php the_title(); ?>" /><?php } ?> 
<h2><?php the_title(); ?></h2> 
<?php the_excerpt(); ?> 
</div> 
<?php   
     } 
    } 

快速修改显示一个帖子:

<?php 

    // Bring in WordPress 
    require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'); 

    // Setup your query 
    $args = array(
     'p' => __post_id_here__ 
     // adjust as you need 
    ); 

    // Execute your query 
    $posts = new WP_Query($args); 
    if($posts->have_posts()) { 

      $posts->the_post(); 
      if (has_post_thumbnail(get_the_ID())) { 
       $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'thumb-rectangle'); 
      } 

      // Now do something with your post 
?> 

<?php if($thumbnail) { ?><img src="<?php echo($thumbnail[0]); ?>" width="" height="" alt="<?php the_title(); ?>" /><?php } ?> 
<h2><?php the_title(); ?></h2> 
<?php the_content(); ?> 
<?php   
    } 
+0

感谢百万@set sail媒体 – Udo

+0

但我也想在页面上显示特定的帖子(全部)。 – Udo

+0

看看更新! –

相关问题