【问题标题】:WordPress blog with minimal integration集成最少的 WordPress 博客
【发布时间】:2016-04-24 17:23:10
【问题描述】:

原谅我的无知 - 到目前为止,我只关注 WordPress 几个小时......

我的要求是向现有网站添加一个博客,然后再添加一个 twitter 提要。我认为我还不想完全接受 WordPress,所以我希望在我现有的网站上添加一个新页面,比如blog.php,并且它的内容看起来像这样:

<html>
   ...   
   <!-- My existing HTML -->
   ...
   <?php
      wp_render_posts(10); // TODO - How? Render last 10 blog posts
   ?>
   ...   
   <!-- My existing HTML -->
   ...
</html>

问题:有没有像wp_render_posts 这样的方法,我可以在没有 WordPress 带来的其余部分的情况下使用?

我接受,如果没有其他事情(当然还有数据库),我仍然希望将其余部分部署给管理员。

注意:我宁愿避免使用 iFrame。

【问题讨论】:

  • 你可以使用require_once( "/path/to/wp-load.php" );,然后只使用常规的WordPress函数described in the documentation,但是IMO这比仅仅将WordPress放在/blog/子目录中更麻烦也更麻烦。
  • 很公平,感谢您的帮助。

标签: php wordpress


【解决方案1】:

当我在现有网站上添加 WordPress 博客作为额外部分时,我只需将其安装到不同的目录。

因此,在安装过程中,它会询问您要安装的位置,选择 /blog/,WordPress 将完全单独安装到您现有的站点。现有站点和 Wordpress 博客都是孤立存在的,实际上是 2 个独立的站点,但您可以添加前后导航,以便用户无缝集成。这样,您还可以轻松更新 WordPress 而不会破坏任何内容。

【讨论】:

  • 好的,谢谢 - 我想我会看看这个。只是觉得整个 WordPress 对我来说可能有点矫枉过正,但一旦我启动并正常运行就会看到。
  • 这对你想要的东西来说太过分了。但外部集成也是如此。有很多简单的博客脚本可供使用。
  • 就功能而言,这只是矫枉过正。在时间和维护方面,使用现成的 Word Press 安装将节省您大量的时间和精力,特别是如果您没有使用 WordPress API 的经验。
【解决方案2】:

在进一步调查后回答我自己的问题...

首先,正如 Horaland 所建议的 - 在子目录中安装 WordPress 是一个好方法。再加上自定义 theme 的使用,可以完全控制您使用的 WordPress 的哪些功能。

创建主题

主题很容易创建 - 有关完整信息,请查看 How to create a WordPress theme 和一些更简单的主题,如 WordPress 2015

您的所有主题文件都需要放在 WordPress 安装的 themes 目录下的一个目录 my-simple-theme 中。主题需要从管理控制台激活。

示例

您可能希望创建以下文件;

index.php

<?php get_header(); ?>

<section class="my-posts-wrapper-class">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <h1><?php the_title(); ?></h1>
        <h4>Posted on <?php the_time('F jS, Y') ?></h4>
        <div class="my-post-class">
            <?php the_content(__('(more...)')); ?>
        </div>
    <?php endwhile; else: ?>

</section>

<!-- Optional -->
<section>
    <?php get_sidebar(); ?>
</section>

<?php get_footer(); ?>>

sidebar.php

<aside>
    <h2><?php _e('Categories'); ?></h2>
    <ul>
        <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
    </ul>
    <h2><?php _e('Archives'); ?></h2>
    <ul>
        <?php wp_get_archives('type=monthly'); ?>
    </ul>
</aside>

header.php

<html>
<head>
    <!-- My site's HEAD html -->
    
    <!-- 
        If installing WordPress in a subdirectory, 
        modifiy the document's BASE to ensure CSS and JS imports
        don't need modificaiton.
    -->
    <base href="..">
</head>
<body>
    <!-- My site's NAV and more, e.g. -->
    <nav>
        <ul>
            <li class="active"><a href="#">Blog</a></li>
            ...
        </ul>
    </nav>

footer.php

    <footer>
        <!-- My site's FOOTER html -->
    </footer>
</body>
</html>

style.css

/*
    WordPress specific styles.
    You site's core CSS could be imported in index.php.
*/

【讨论】:

  • 这仍然需要您单独安装 WordPress。主题是 wordpress 不可或缺的一部分。您基本上是在说我的答案不对,但给出了相同的答案。
  • 是的,同意。我希望它能补充你的答案。抱歉,我并没有说你错了,但我已经更详细地介绍了如何使用主题大幅缩减的 WordPress 版本更简单地与现有网站集成。顺便说一句,我个人认为这不值得投反对票。
  • 也许我觉得很明显它需要安装在一个子目录中,但考虑到我当时所理解的一切,我接受了你的回答。现在知道自定义主题可以完全控制您使用的 WordPress 的哪些功能,我相信这是更完整的答案。
猜你喜欢
  • 1970-01-01
  • 2010-11-24
  • 1970-01-01
  • 2012-01-24
  • 2018-12-12
  • 1970-01-01
  • 2010-11-25
  • 1970-01-01
  • 2010-09-19
相关资源
最近更新 更多