Reputation: 83
I need to write filter data of my custom post type in custom function placed in functions.php
:
The majority are corrected, but I cannot process these lines:
<div class="cpt-studies-block-image picture">
<?php $thumb_img=wp_get_attachment_image_src(get_field('image'),'custom-crop-studien'); ?>
<img class="img" src="<?php print($thumb_img[0]); ?>">
</div>
and:
<a href="<?php the_permalink()?>" class="cpt-studies-block-link link-read-more"> <?php
include get_stylesheet_directory() . '/img/svg/icon_arrow.svg';
?>
<?php if (get_field('button_text')):
the_field('button_text');
else : echo __('More', 'dw');?>
<?php endif;?>
</a>
Code in folder for writing Custom Post Type data:
if($query->have_posts()):
while($query->have_posts()) : $query->the_post();?>
<div class="col-md-6">
<div class="cpt-studies-block">
<div class="row">
<div class="col-md-6">
<a class="zoom-picture-hover" href="<?php the_permalink()?>">
<div class="cpt-studies-block-image picture">
<?php $thumb_img=wp_get_attachment_image_src(get_field('image'),'custom-crop-studien'); ?>
<img class="img" src="<?php print($thumb_img[0]); ?>">
</div>
</a>
</div>
<div class="col-md-6">
<span><?php the_field('date')?></span>
<h3>
<a href="<?php the_permalink()?>">
<?php the_title()?>
</a>
</h3>
<p class="cpt-studies-block-text"><?php the_field('text')?></p>
<a href="<?php the_permalink()?>" class="cpt-studies-block-link link-read-more"> <?php
include get_stylesheet_directory() . '/img/svg/icon_arrow.svg';
?>
<?php if (get_field('button_text')):
the_field('button_text');
else : echo __('More', 'dw');?>
<?php endif;?>
</a>
</div>
</div>
</div>
</div>
<?php endwhile;
endif;
?>
Code in Custom function in functions.php
:
if(have_posts($wp_query))
{
while(have_posts($wp_query))
{
the_post();
echo '<div class="col-md-6">'
.'<div class="cpt-studies-block">'.
'<div class="row">'.
'<div class="col-md-6">'
.'<a class="zoom-picture-hover" href="'.get_permalink().'">'
.'<div class="cpt-studies-block-image picture">'
.$thumb_img=wp_get_attachment_image_src(get_field('image'),'custom-crop-studien').
'<img class="img" src=".print($thumb_img[0]).">'
.'</div>'
.'</a>'
.'</div>'
.'<div class="col-md-6">'
.'<span>'.get_field('date').'</span>'
.'<h3>'
.'<a href="'.get_permalink().'">'
.get_the_title().
'</a>'
.'</h3>'
.'<p class="cpt-studies-block-text">'.get_field('text').'</p>'.
'<a href="'.get_permalink().'" class="cpt-studies-block-link link-read-more">'
include get_stylesheet_directory() . '/img/svg/icon_arrow.svg';
'</a>'.
'</div>'.
'</div>'.
'</div>'.
'</div>';
}
}
Please can someone give me advice, or do I need to change method on writing these lines?
Upvotes: 1
Views: 62
Reputation: 8181
You got a syntax error:
.'<div class="cpt-studies-block-image picture">' // Add semicolon.
.$thumb_img = wp_get_attachment_image_src(
get_field('image'),'custom-crop-studien'). // Assignement can't be concatenated
// and missing parenthesis
'<img class="img" src=".print($thumb_img[0]).">' // Resume echo.
So:
// Ommited
.'<div class="cpt-studies-block-image picture">';
$thumb_img = wp_get_attachment_image_src(
get_field('image'), 'custom-crop-studien'));
echo '<img class="img" src=".print($thumb_img[0]).">'
Or better yet, use templates (as I explained in this other question of yours)
Upvotes: 1