I have a simple html structure like this.
<div class="ideaPost">
<a href="<?php echo get_permalink($post->ID); ?>">
<div class="ideaPost__Info">
<?php
$attachments = get_children(array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_parent' => $post->ID
));
if(count($attachments) > 0) {
echo '<span class="glyphicon glyphicon-paperclip"></span>';
}
?>
</div>
<h3><?php echo the_title(); ?></h3>
<h4>by </h4>
<?php echo the_excerpt(); ?>
</a>
</div>
I'm using this on a number of pages so I want to add it to functions.php and call the function on the page.
How do I add this as a function to generate this structure. I tried this.
function ideas(id){
echo '<div class="ideaPost">';
echo '<a href="'. get_permalink(id); .'">';
echo '<div class="ideaPost__Info">';
$attachments = get_children(array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_parent' => $post->ID
));
if(count($attachments) > 0) {
echo '<span class="glyphicon glyphicon-paperclip"></span>';
}
echo '</div>';
echo '<h3>'.the_title(); .'</h3>';
echo '<h4>by </h4>';
echo the_excerpt();
echo '</a>';
echo '</div>';
}
and in the page
if(function_exists('idea')){
idea();
}