[英]Exclude excerpt from wordpress wp_query
大家好! 我正在显示其他wp模板中的帖子博客,并且一切正常,但是我从中获得了某种图库,并且除了图库和标题外,我无需显示任何内容。
内部帖子我有这个:
[gallery ids="1618,...,1634"]
<h2>...</h2>
<p>...</p>
text without format, etc.
如您所见,我正在使用画廊简码。 我需要显示它,但所有其他内容都应从循环中排除。
非常感谢您在这个问题上的帮助...
我的模板代码:
<?php
/*
* Template name: Блог
*/
$current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 9,
'paged' => $current_page,
'cat' => 8
);
query_posts( $args );
$wp_query->is_archive = true;
$wp_query->is_home = false;
while(have_posts()): the_post();
?>
<div class="foto_posts">
<?php the_content() ?>
<?php echo '<a href="' . get_permalink() . '" class="foto_title" target="_blank">' . get_the_title() . '</a>';?>
</div>
<?php
endwhile;
if(function_exists('page_navi_slider')) page_navi_slider();
尝试将<?php the_content() ?>
替换为<?php the_title() ?>
如果您只想显示图库简码,请尝试此
更换
<?php the_content() ?>
至
$pattern = get_shortcode_regex();
preg_match('/'.$pattern.'/s', $post->post_content, $matches);
if (is_array($matches) && $matches[2] == 'gallery') {
$shortcode = $matches[0];
echo do_shortcode($shortcode);
}
尝试使用get_post_meta_key()
获取画廊和视频
<?php get_post_meta($post_id,'key_name',1);?>
如果返回数组,则遍历该数组以获取图像链接和视频链接
add_shortcode('gallery', 'gallery_shortcode_fancybox');
function gallery_shortcode_fancybox($attr) {
$attachment_ids = explode(',',$attr['ids']);
$args = array(
'post__in' => $attachment_ids,
//'cat' => 8 if category needs to be shown pass it in shortcode , same as ids
);
$gallery_posts = query_posts( $args );
foreach ($gallery_posts as $key => $value) {
//do the stuff here
echo '<h2>'. $value->post_title;'</h2>';
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($value->ID);
echo '<p><img src="'.$feat_image.'" ></p>';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.