【问题标题】:Embed Wordpress content into html将 Wordpress 内容嵌入 html
【发布时间】:2016-12-30 17:20:06
【问题描述】:

我想将 Wordpress(帖子)页面/网站的新闻部分嵌入到没有 Wordpress 菜单或页脚的 html 页面中,并使其内容看起来好像是该 HTML 页面的一部分。这是因为对于初学者来说,在 Wordpress 中上传新闻报道更容易。

【问题讨论】:

  • 使用 jQuery 将 iframe 注入 html 并使用 .remove() 从中删除所有不需要的东西...希望这可行:)

标签: wordpress html embed blogs


【解决方案1】:

你可以这样用

<ul>
<?php
global $wpdb;
global $post;
$str = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'";
$result = $wpdb->get_results($str);
foreach($result as $post):
  setup_postdata($post);?>
    <li><a href="<?php the_permalink()?>"><?php the_title();?></a></li><?php 
endforeach;?>
</ul>

或者这个

<?php
  // Include WordPress
  global $wpdb;
  define('WP_USE_THEMES', false);
  require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
  query_posts('posts_per_page=1');
?>

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

【讨论】:

    【解决方案2】:

    推荐的解决方案是使用 WordPress 来显示您使用其管理界面创建的帖子/内容。您可以从头开始创建主题(或修改现有主题),以匹配您现有的网站设计。

    但是,如果您使用 PHP 生成其他 html 页面,您还可以包含 WordPress 引导文件 (wp-load.php),然后使用 WordPress 函数 get_posts() 检索帖子列表。例如:

    您的 .php 文件:

    <?php
    
    // ...
    // other stuff you do
    // ...
    
    require_once('/path/to/your/wordpress/installation/wp-load.php');
    
    $posts = get_posts();
    
    // do whatever you want with the array of found posts
    var_dump($posts);
    
    // ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-09
      相关资源
      最近更新 更多