Cómo integrar la plantilla de WordPress con CodeIgniter
¿Cómo se pueden integrar CodeIgniter y WordPress de tal manera que la apariencia / plantilla de el blog de WordPress se lleva a las páginas creadas por CodeIgniter?
5 answers
El primer paso es mover CodeIgniter y los archivos de WordPress en su propio directorio.
Después de eso, coloque la siguiente línea en la parte superior del archivo index.php
de su CodeIgniter. Cambie la ruta a wp-blog-header.php
según sea necesario para apuntar al directorio raíz de su WordPress.
<?php
require('../wp-blog-header.php');
Luego, puede usar las siguientes funciones dentro de sus vistas:
<?php
get_header();
get_sidebar();
get_footer();
?>
Otras funciones auxiliares también se pueden encontrar en la documentación de WordPress que puede ayudarle a integrar el diseño.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-28 00:56:21
Cuando incluí el archivo wp-blog-header.php en el índice de Codeigniter.página php, tengo un problema que site_url() está definida en codeigniter URL helper y WordPress. Resolví esto usando el siguiente código:
require('blog/wp-blog-header.php');
add_filter('site_url', 'ci_site_url', 1);
function ci_site_url() {
include(BASEPATH.'application/config/config.php');
return $config['base_url'];
}
header("HTTP/1.0 200 OK");
Se debe agregar la última línea ya que el archivo de WordPress estaba agregando un encabezado de respuesta HTTP 'HTTP/1.0 404 Page not found' al encabezado.
Ahora está bien usar funciones de WordPress para llamar a CodeIgntier.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-28 00:56:55
Aquí hay otra forma de usar plantillas de WordPress en su proyecto codeigniter. Esto funciona mejor para mí, así que quería compartirlo. Probado con WordPress 3.3.1 y Codeigniter 2.1.
Estructura del directorio:
/ - WordPress
/ci/ - codeigniter
/ci/index.php (Parte superior del archivo de índice de CI)
$wp_did_header = true;
if ( defined('E_RECOVERABLE_ERROR') )
error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
else
error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
require_once("../wp-config.php");
Trate la colisión de la función site_url anulando la versión predeterminada de codeigniter. Tendrá que cambiar cualquier lugar que utilizó site_url()
en codeigniter para usar ci_site_url()
en su lugar.
/ci/application/helpers/MY_url_helper.php
<?php
function anchor($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
if ( ! is_array($uri))
{
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? ci_site_url($uri) : $uri;
}
else
{
$site_url = ci_site_url($uri);
}
if ($title == '')
{
$title = $site_url;
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}
if ( ! function_exists('ci_site_url'))
{
function ci_site_url($uri = '')
{
$CI =& get_instance();
return $CI->config->site_url($uri);
}
}
function current_url()
{
$CI =& get_instance();
return $CI->config->ci_site_url($CI->uri->uri_string());
}
function anchor_popup($uri = '', $title = '', $attributes = FALSE)
{
$title = (string) $title;
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? ci_site_url($uri) : $uri;
if ($title == '')
{
$title = $site_url;
}
if ($attributes === FALSE)
{
return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
}
if ( ! is_array($attributes))
{
$attributes = array();
}
foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
{
$atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
unset($attributes[$key]);
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"$attributes>".$title."</a>";
}
function redirect($uri = '', $method = 'location', $http_response_code = 302)
{
if ( ! preg_match('#^https?://#i', $uri))
{
$uri = ci_site_url($uri);
}
switch($method)
{
case 'refresh' : header("Refresh:0;url=".$uri);
break;
default : header("Location: ".$uri, TRUE, $http_response_code);
break;
}
exit;
}
Ahora puede usar las funciones de WordPress get_header()
y/o get_footer()
para dibujar la plantilla en su proyecto CI.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-24 13:31:35
Estoy usando Wordpress para administrar artículos en un sitio web de comercio electrónico CI personalizado. CI es mi sitio principal. La estructura de directorios es la siguiente:
/application (CI)
/... (directories like javascript, stylesheets ...)
/system (CI)
/wordpress
/.htaccess
/index.php (CI)
Puedo usar funciones de Wordpress en mis controladores de CI sin que mis URL se estropeen al agregar el siguiente código a la parte superior del índice de CI .php :
require_once './wordpress/wp-blog-header.php';
add_filter('site_url', 'ci_site_url', 1);
function ci_site_url($uri = '') {
$CI =& get_instance();
$uri = ltrim(str_replace($CI->config->base_url('wordpress/'), '', $uri),'/'); // "wordpress/" is in my case the name of the directory where I installed Wordpress. See directory structure above.
return $CI->config->site_url($uri);
}
Funciona también cuando se usa la biblioteca CI i18n de Jérôme Jaglale ( http://jeromejaglale.com/doc/php/codeigniter_i18n).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-11 21:08:45
Si está planeando usar la función code ignitor site_url en su código, o si está haciendo una fusión de un sitio CI existente y WP... esto podría ser útil:
En la parte superior del índice IC.php:
require_once '../wp-blog-header.php';
add_filter('site_url', 'ci_site_url', 4);
function ci_site_url($url, $path, $orig_scheme, $blog_id) {
$CI =& get_instance();
$new_path = str_replace("YOURSITEURLGOESHERE", "", $url);
return $CI->config->site_url($new_path);
}
Efectivamente, esto le permite usar site_url en CI, por lo que si ya ha agregado un montón de enlaces y contenido a su proyecto, podría ayudarlo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-07-23 18:07:21