gpt4 book ai didi

WordPress 3.5 : own gallery with included images doesn't work

转载 作者:行者123 更新时间:2023-12-02 22:39:10 26 4
gpt4 key购买 nike

我刚刚更新到 Wordpress 3.5,但这使我的代码的一小部分崩溃了:有一个 php 文件,它通过 AJAX 加载特定帖子及其图库。

代码如下:

<?php

// Include WordPress
define('WP_USE_THEMES', false);
require('../../../../wp-load.php');

$id = $_POST['id'];

// query post with this identifier
query_posts('meta_key=identifier&meta_value='.$id);
if (have_posts()) :
while (have_posts()) : the_post();

// add content
$content = apply_filters('the_content', get_the_content());
echo '<div class="content-inner">'.$content.'</div>';
endwhile;
endif;
?>

该帖子包含一个[图库]短代码。我使用以下代码构建了自己的 Wordpress 画廊:

remove_shortcode('gallery');
add_shortcode('gallery', 'parse_gallery_shortcode');

function parse_gallery_shortcode($atts) {

global $post;

extract(shortcode_atts(array(
'orderby' => 'menu_order ASC, ID ASC',
'id' => $post->ID,
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'full',
'link' => 'file'
), $atts));

$args = array(
'post_type' => 'attachment',
'post_parent' => $id,
'numberposts' => -1,
'orderby' => $orderby
);

$images = get_posts($args);
print_r($images);
}

这适用于我网站上的所有其他画廊,但不适用于 ajax 加载的画廊。它可以与 WordPress 3.4 配合使用。

Wordpress 3.5 中是否有我忽略的更改?

最佳答案

我想通了:如果您使用带有已上传到媒体库的图像的图库,则图库短代码看起来像 [gallery ids=1,2,3],这意味着什么,图像仅链接(而不是附加)到图库,因此 post_type=attachment 不起作用。

现在我使用正则表达式来获取图像 ID:

$post_content = $post->post_content;
preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
$array_id = explode(",", $ids[1]);

关于WordPress 3.5 : own gallery with included images doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14277794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com