• hello there.. currently, I am creating a template that will display the post based on the category..
    this is my way of calling the latest post from the category..

    <article id = "featuredarticle">
    				<?php $my_query = new WP_Query('category_name=featured article&posts_per_page=1');
    				while ($my_query->have_posts()) : $my_query->the_post();
    				$do_not_duplicate = $post->ID; ?>
    				<h2><?php the_category();?><h2>
    				<h3><a STYLE="text-decoration:none"href = "<?php the_permalink();?>"><?php the_title();?></a></h3>
    					<p>
    						<?php the_excerpt();?>
    					</p>
    					<?php endwhile; ?>
    					<a href = "#"><img src="http://localhost/wordpress/wp-content/uploads/2011/10/featuredarticle.png" alt="Featured Article"/></a>
    			</article><!--End of Featured Content-->

    but.. I left something… the attachment.
    the attachment is can be image or video.
    how can I call it?

    thanks in advance..

Viewing 5 replies - 1 through 5 (of 5 total)
  • put this in your functions.php

    [21 lines of code moderated as per the Forum Rules. Please use the pastebin]

    and then, in your template, use it like this:
    <a href="<?php echo getAttach($post->ID,'video'); ?>">download video</a>
    the second parameter is the post_mime_type, and you can change it to ‘image’

    the function only grabs the first attachment of the given type

    hope it helps,
    cheers

    Thread Starter markyeoj

    (@markyeoj)

    hello, I used the code that gave to me yesterday..

    http://pastebin.com/BZ1Rkgby

    and I also added this code
    <a href="<?php echo getAttach($post->ID,'video'); ?>">download video</a>
    on my template in this way..

    http://pastebin.com/uJUAvQ4K

    but there’s an error

    Parse error: syntax error, unexpected ‘;’, expecting T_PAAMAYIM_NEKUDOTAYIM in C:\xampp\htdocs\wordpress\wp-content\themes\livelongcafe\functions.php on line 35

    how can I fix it? I’m not good in php..

    hi,
    i tested the function before posting, but what you’re showing me in the pastebin converted > to html entities & gt;
    and it looks like i’m posting excessive amounts of code in the thread

    let’s do it the right way, replace the function with this one: http://pastebin.com/mAiHt7i2

    Thread Starter markyeoj

    (@markyeoj)

    thank you.. now I can download the attachment.. but the the image is displayed? is it my browser?

    i don’t understand… what’s exactly the code you’re using to call the function?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘grabing the attachment from post’ is closed to new replies.