I’m using advancd-custom-fields plugin and I’m about to modifiy my acrhive content page that is shown frontend. I use the file personnel-archive.php (because the custom post type used is personnel) in my theme in that works ok:
Beginning of this file looks like:
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h1 class="personnel"><?php the_title(); ?></h1>
<div class="entry">
<?php echo image_personnel(get_the_ID());?>
<?php the_content('<p class="serif">Läs resten »</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Sidor:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
I my functions.php I have made this function:
function image_personnel($post_ID) {
$post_type = get_post_type( $post_ID );
$content = '';
//If custom type for shown post is personnel, then show image first
if ($post_type == 'personnel') {
$picture_personnel = get_post_custom_values('picture_personnel', $post_ID);
if ($picture_personnel) {
$image_fields = get_field('picture_personnel');
$url_image = $image_fields['url'];
$alt_image = $image_fields['alt'];
$title_image = $image_fields['title'];
if (strlen($alt_image)>0) {
$title_image = $alt_image;
}
else {
$alt_image = $title_image;
}
$content = '<img src="' . $url_image . '" alt="' . $alt_image . '" title="' . $title_image . '" />';
}
}
return $content;
}
I’ve basically just added a field “picture_personnel” to each personnel post and I want to show it in the content. Is it better to use filter for the_content? Or is it just a matter of taste?