• allancole

    (@allancole)


    Is there a way to set up a custom loop or conditional tag that tests for a specific attachment type? I am trying to set up a situation where a number of posts with varying types of attachments, pull a specific template based on their attachment type within a Loop.

    Currently, I am using categories to distinguish between attachment types, and using category-based conditional tags to pull the templates for each type. However, doing it this way is proving to be tedious when it’s time to move the template files to another WP install.

    It seems like some sort of custom conditional function (like has_attachment) would do the trick IE:

    //Mp3 Post
    if (has_attachment(type=mp3) {
    <div id="mp3-post"><a href="song.mp3">Song Title</a></div>
    
    //Image Post
    elseif (has_attachment(type=jpg,gif,png) {
    <div id="image-post"><a href="image.jpg"><img src="image.jpg"></a></div>

    I know that there is an “is_attachment” conditional tag as well. Maybe another way to do it would be:

    if (child-of-post (is_attachment(type=jpg,gif,png)) { …etc.

    I am not sure where to begin here. Any help with this would be greatly appreciated!

Viewing 1 replies (of 1 total)
  • I’m very interesting about this query type.

    I need a query to put in the loop as following:

    if post have attachment type (image or video or other) then display only post with attachment type.

    Anyone can help me?

    Thanks in advanced.

    Phoenix1977

Viewing 1 replies (of 1 total)
  • The topic ‘Custom conditional tag: if (has_attachment)?’ is closed to new replies.