首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自安装的wordpress在静态页面上显示多个博客

自安装的wordpress在静态页面上显示多个博客
EN

Stack Overflow用户
提问于 2013-12-12 23:04:52
回答 2查看 103关注 0票数 0

这是我的代码,我想在主页上显示4个博客(相同的数据库),并有2个需要4个标题。如果我做4个独立的脚本,我可以。但我想让他们都在同一个地方..在order by date中(所以如果creativeace与tnw在同一天发布,它们就会出现..等)但是,这只显示了tirednwired..请原谅我的无知!这个脚本非常简单,需要编辑。

代码语言:javascript
复制
 <style>
 h3{display:inline;}
</style>

<?php require('tnw/wp-blog-header.php');?>
<?php require('creativeace/wp-blog-header.php');?>
<?php require('madnessfromthelab/wp-blog-header.php');?>
<?php require('brainsick/wp-blog-header.php');?>

<?php 
$args = array( 'numberposts' => 20, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );

foreach ($postslist as $post) : setup_postdata($post); ?>

<strong><?php the_date(); ?></strong><br>
<h3><?php the_title(); ?></h3>
<br>
<?php the_excerpt(); ?>

<center><img src="line.jpg"></center>

</P>


<?php endforeach; ?> 
EN

回答 2

Stack Overflow用户

发布于 2013-12-12 23:20:40

这更像是一个评论,但是有太多的信息不能放在评论中。

通过在主页中要求每个站点的wp-blog-header.php是不可能做你想做的事情的。如果你看一下wp-blog-header.php中的代码,你会发现它只是一个用于请求其他WP核心文件的包装器,它甚至有一个标志来防止多次需要该文件。所有需要的调用都在相同的上下文中,因此对于所有需要的wp-blog-header.php文件,$wp_did_header标志都是相同的。

但是,即使标志不在那里,需要多个wp-blog-header.php文件也不会神奇地为您合并不同的可湿性粉剂表。

wp-blog-header.php:

代码语言:javascript
复制
/**
 * Loads the WordPress environment and template.
 * @package WordPress
 */

if ( !isset($wp_did_header) ) {
    $wp_did_header = true;
    require_once( dirname(__FILE__) . '/wp-load.php' );
    wp();
    require_once( ABSPATH . WPINC . '/template-loader.php' );
}

可能的解决方案的提示:

  • 也许你可以通过WP功能从每个WP中获取post。
  • 你总是可以从数据库中获取原始的post数据。这样做还可以方便地按日期对帖子进行排序。在您的SQL statement.
  • Maybe中,有一种官方方法可以从多站点WP配置中的子WP中提取帖子,前提是它可以在您的情况下实现。
票数 1
EN

Stack Overflow用户

发布于 2013-12-13 00:07:27

代码语言:javascript
复制
$sql = ("SELECT * FROM $table WHERE post_content !='' AND post_status = 'publish' AND      post_author IN (6,8, 10)
UNION
SELECT * FROM $table2 WHERE post_status = 'publish' AND post_author = '3'
UNION
SELECT * FROM $table3 WHERE post_status = 'publish' AND post_author = '2'
UNION
SELECT * FROM $table4 WHERE post_author = '1' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 20");


$getit = mysql_query ( $sql, $conn );


while($row = mysql_fetch_array($getit, MYSQL_ASSOC))
{
print "<b>$row[post_title]</b><font size=1> <br>posted on ";

$row[post_date] = date("Y-m-d H:i",strtotime(str_replace('/','-',$row[post_date]))); 
print "$row[post_date] by ";

if ($table.$row['post_author'] == wp_wiredposts.'8') {
print "Blogger 1"; }
elseif ($table.$row['post_author'] == wp_wiredposts.'6') {
print "Blogger 2"; }
elseif ($table.$row['post_author'] == wp_wiredposts.'10') {
print "Blogger 3"; }
elseif ($bstable.$row['post_author'] == brains_posts.'2') {
print "Blogger 4"; }
elseif ($catable.$row['post_author'] == wp_posts.'1') {
print "Blogger 5"; }
else {
print "Blogger 6"; }

print "</strong></font><br>";


echo substr(strip_tags($row['post_content'], '<br><p></p></center>'), 0, 400);

echo "...<a href={$row['guid']}><font color=red><i>Continue reading</i></font></a>";
echo "<br><font size=1>{$row['comment_count']} comments</font>";
print "<center><img src=line.jpg></center>";
}

在我的网站上工作。现在只是为了摆脱奇怪的字符,只出现在首页,而不是脚本页面。(是的,我将meta设置为UTF-8,但我使用粗体�和"") grrr

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20546976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档