/* Выборка тегов для замены, начиная с картинки */
function replace_text($text) {
global $wpdb;
preg_match_all('/<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>/', $text, $matches);
if (empty($matches[1])) return;
//print_r($matches[1]);
$id = $matches[1];
$line_img = $result;
$result = $wpdb->get_results('SELECT * FROM `Images` WHERE `id`='.(int)$id[0], OBJECT_K);
//var_dump($line_image);
//var_dump($id[0]);
var_dump($result);
// Замена картинок (ббкод на картинку из БД)
$text = preg_replace('/<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>/', '<img scr="'.$line_img.'">', $text);
// Замена ссылок на человекопонятные (ббкод на обычные ссылки-урл)
$text = preg_replace('/<#link#(.*)#URL:(.*)#>/', ' <a href="$2">$1</a>', $text);
// Замена лишнего кода на NULL
$text = preg_replace('/<#pcat#(.*)#>/', '', $text);
return $text;
}
add_filter('the_content', 'replace_text');
$result
, то будет так:array(1) { [0]=> object(stdClass)#9296 (6) { ["id"]=> string(4) "3483" ["Name"]=> string(19) "С днем ВМФ!" ["smallURL"]=> string(45) "images/data/gallery/0_big_1501594830_5999.jpg" ["Description"]=> string(0) "" ["bigURL"]=> string(45) "images/data/gallery/0_big_1501594830_5999.jpg" ["Keywords"]=> NULL } }
/* Выборка тегов для замены, начиная с картинки */
function replace_text($text) {
global $wpdb;
preg_match_all('/<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>/', $text, $matches);
if (empty($matches[1])) return;
//print_r($matches[1]);
$id = $id[0] = $matches[1];
$line_img = $result;
$result = $wpdb->get_results('SELECT * FROM `Images` WHERE `id`='.(int)$id[0]);
//var_dump($line_image);
var_dump($id[0]);
// Замена картинок (ббкод на картинку из БД)
$text = preg_replace('/<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>/', '<img scr="'.$line_img.'">', $text);
// Замена ссылок на человекопонятные (ббкод на обычные ссылки-урл)
$text = preg_replace('/<#link#(.*)#URL:(.*)#>/', ' <a href="$2">$1</a>', $text);
// Замена лишнего кода на NULL
$text = preg_replace('/<#pcat#(.*)#>/', '', $text);
return $text;
}
add_filter('the_content', 'replace_text');
string(4) "3483"
<p><img scr=""></p>
print_r($matches[0]); - Array ( [0] => #pic#3483#0#0#0## )
var_dump($line_image); - NULL
function replace_text($text) {
global $wpdb;
preg_match_all('<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>', $text, $matches);
if (empty($matches[1])) return;
//print_r($matches[1]);
$id = $matches[1];
$line_img = $result = $wpdb->get_results('select smallURL from Images where id = ' .(int) $id);
var_dump($var);
// Замена картинок (ббкод на картинку из БД)
$text = preg_replace('<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>', '<img scr="'.$line_img.'">', $text);
// Замена ссылок на человекопонятные (ббкод на обычные ссылки-урл)
$text = preg_replace('/<#link#(.*)#URL:(.*)#>/', ' <a href="$2">$1</a>', $text);
// Замена лишнего кода на NULL
$text = preg_replace('/<#pcat#(.*)#>/', '', $text);
return ['text' => $text, 'text_image' => $text_image];
mysqli_close($link);
}
add_filter('the_content', 'replace_text');
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if ( ! have_posts() ) : ?>
<article id="post-0" class="post error404 not-found">
<h1 class="posttitle"><?php _e( 'Not Found', 'klasik' ); ?></h1>
<div class="entry">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'klasik' ); ?></p>
<?php get_search_form(); ?>
</div>
</article>
<?php endif; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php /* How to display all posts. */
get_template_part( 'content', get_post_format() );
?>
<?php comments_template( '', true ); ?>
<?php endwhile; // End the loop. Whew. ?>
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<?php if(function_exists('wp_pagenavi')) { ?>
<?php wp_pagenavi(); ?>
<?php }else{ ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Previous', 'klasik' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Next <span class="meta-nav">→</span>', 'klasik' ) ); ?></div>
<div class="clear"></div>
</div><!-- #nav-below -->
<?php }?>
<?php endif; ?>
/* Выборка тегов для замены, начиная с картинки */
function replace_text($text) {
$line_img = 'тут код запроса или функция?';
mysqli_close($link);
// Замена картинок (ббкод на картинку из БД)
$text = preg_replace('<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>', $line_img, $text);
// Замена ссылок на человекопонятные (ббкод на обычные ссылки-урл)
$text = preg_replace('/<#link#(.*)#URL:(.*)#>/', ' <a href="$2">$1</a>', $text);
// Замена лишнего кода на NULL
$text = preg_replace('/<#pcat#(.*)#>/', '', $text);
return $text;
}
add_filter('the_content', 'replace_text');
Код сейчас выглядит так: