【发布时间】:2015-02-18 11:56:20
【问题描述】:
我正在尝试在 WordPress 中添加以下代码,但找不到正确的方法。请有人帮我...
<?php
include("config.php");
$results = $mysqli->query("SELECT COUNT(*) as t_records FROM wp_posts");
$total_records = $results->fetch_object();
$total_groups = ceil($total_records->t_records/$items_per_group);
$results->close();
?>
如果我在 WordPress 之外使用它,效果会非常好。但我不知道如何在我的 WordPress index.php 中实现这一点
我的主题中有很多代码,所以我不能给你索引页的确切代码。但这里是主要的 index.php 文件代码
<?php
$is_filterable_index = is_home() && x_get_option( 'x_ethos_filterable_index_enable', '' ) == '1';
?>
<?php get_header(); ?>
<div class="x-container-fluid max width main">
<?php x_get_view( 'ethos', '_post', 'slider' ); ?>
<div class="offset cf">
<div class="<?php x_main_content_class(); ?>" role="main">
<?php if ( $is_filterable_index ) : ?>
<?php x_get_view( 'ethos', '_index' ); ?>
<?php else : ?>
<?php x_get_view( 'global', '_index' ); ?>
<?php endif; ?>
<?php /*?>
<?php */?> </div>
<?php get_sidebar(); ?>
</div>
</div>
<div id="content"></div>
<?php get_footer(); ?>
【问题讨论】:
-
你在模板里写了什么?
-
你应该通过 Wordpress Codex,在 Wordpress 中你不需要建立自己的数据库连接。 codex.wordpress.org
-
Wordpress 有自己的方法来访问数据库codex.wordpress.org/Class_Reference/wpdb
标签: php database mysqli wordpress