简体   繁体   English

从WordPress的模板发布中获取图像

[英]get image from template post in wordpress

I use a crowdfunding-plugin for wordpress called personal fundraiser which you can see here . 我使用一种称为个人筹款活动的Wordpress众筹插件,您可以在此处看到。 It uses one post-type called cause and another called campaign. 它使用一种称为“原因”的帖子类型,另一种称为“活动”。 The campaign posts uses the cause posts as a template. 活动帖子使用原因帖子作为模板。 The reason why i ask here is that the plugin-developer answer questions every second month or so. 我在这里问的原因是,插件开发人员每隔两个月左右回答一次问题。

There are one shortcode which i want to change the content of. 我想更改其中一个内容的简码。 The first thing i want is to get the campaing-image. 我想做的第一件事是获取露营形象。 I probably need a code to get it from the asociated cause (the template). 我可能需要一个代码来从相关原因(模板)中获取代码。 The second thing i want is to echo shortcodes in the $list_content you see below. 我想要的第二件事是在下面看到的$list_content回显简码。 How do i add shortcodes there? 如何在其中添加简码? If i use $list_content .= '<?php echo do_shortcode( $content ) ?>' i get php-error. 如果我使用$list_content .= '<?php echo do_shortcode( $content ) ?>'我会得到php错误。 The code i want to change looks like this: 我要更改的代码如下所示:

`function pfund_campaign_list() {
global $wp_query;
wp_enqueue_style( 'pfund-user', pfund_determine_file_location('user','css'),
array(), PFUND_VERSION );
$post_query = array(
'post_type' => 'pfund_campaign',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1
);

if ( isset( $wp_query->query_vars['pfund_cause_id'] ) ) {
$post_query['meta_query'] = array(
array(
'key' => '_pfund_cause_id',
'value' => $wp_query->query_vars['pfund_cause_id']
)
);
}
$campaigns = get_posts($post_query);
$list_content = '<ul class="pfund-list">';
foreach ($campaigns as $campaign) {
$list_content .= '<li>';
$list_content .= ' <h2>';
$list_content .= ' <a href="'.get_permalink($campaign->ID).'">'.$campaign->post_title.'</a></h2>';
$list_content .= '</li>';

}
$list_content .= '</ul>';
return $list_content;
}`

In another function to list the causes, this code is used to get the cause-image, but when i use it in the campaign_list nothing happens: 在另一个列出原因的函数中,此代码用于获取原因图像,但是当我在campaign_list中使用它时,什么也没发生:

`$cause_img = get_post_meta($cause->ID, '_pfund_cause_image', true);
if ( $cause_img ) {
$list_content .= '<img class="pfund-image" width="100%" src="'.wp_get_attachment_url( $cause_img ).'"/>';
}`

You can see the whole .php-file here 您可以在此处看到整个.php文件

Any help is very much apreciated. 非常感谢您的帮助。

To get a shortcode in your theme do this 要获得主题的简码,请执行以下操作

$list_content .= do_shortcode($content);

then you can change in your $list_content, you cant echo in a predefined variable. 那么您可以更改$ list_content,不能在预定义变量中回显。

In-place of 就地

$list_content .= '<?php echo do_shortcode( $content ) ?>'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM