Forum Replies Created

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter md84

    (@md84)

    This is what I needed! Great plugin ??

    $args = array(
    	post_type => attachment,
    	numberposts => -1,
    	category => $cat_ID
    );
    $attachments = get_posts($args);
    if($attachments){
    	foreach($attachments as $attachment){
    		$image_attributes = wp_get_attachment_image_src($attachment->ID, 'full');
    		echo '<img src="'.$image_attributes[0].'">';
    	}
    }

    Same problem here. For posts it works though, not for pages.

    Thread Starter md84

    (@md84)

    Tried it, didn’t work! The problem remained.

    It’s still the same as explained above. All attachments are shown when using ‘null’ as value for argument ‘post_parent’, but when using ‘$post->ID’ or argument ‘include’ with as value a number of a specified post, it doesn’t work and shows nothing.

    Thread Starter md84

    (@md84)

    Hey, thanks for the reply. Let me rephrase it.

    In my code, when I use ‘null’ as value for argument ‘post_parent’, it shows all attachments (as thumbnails), so that works. But what I actually want is only showing attachments from certain posts. The value ‘$post->ID’ should provide me with the attachments of its parent, but it doesn’t work (no attachments show).

    I also tried using global $wp_query, $post; but it didn’t solve it.

    Thread Starter md84

    (@md84)

    Cannot get it to work, bleh!
    Below my complete code. Question above remains the same.

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query = new WP_Query();
    $wp_query -> query('category_name=photo&posts_per_page=1&order=ASC&paged=' . $paged);
    ?>
    
    <?php while($wp_query -> have_posts()) : $wp_query -> the_post(); ?>
    
    <?php if(is_paged()){ ?>
    
    <?php
    $args = array(
    'post_type' => 'attachment',
    'numberposts' => 25,
    'post_parent' => $post->ID,
    'order' => 'ASC'
    );
    
    $attachments = get_posts($args);
    if($attachments){
    foreach($attachments as $attachment){
    $atturl = wp_get_attachment_thumb_url($attachment->ID);
    $attlink = get_attachment_link($attachment->ID) . '&paged=' . $paged;
    echo '<a href="' . $attlink . '"><img src="' . $atturl . '"></a>';
    }
    };
    ?>
    
    <?php } else { ?>
    <?php the_content(); ?>
    <?php }; ?>
    
    <?php endwhile; ?>
    Thread Starter md84

    (@md84)

    I solved it! Instead of using the wp_get_attachment_link() function I used two new variables ($atturl and $attlink) which I combined later on with some simple HTML.

    Problem now is that the post_parent argument doesn’t work correctly. When ‘null’ it does show my attachments (multiple thumbnails), but when I use $post->ID (or the ‘include’ argument with as value the numeric post ID), it shows blank. What is the problem?

    Can anybody help?

    <?php
    $args = array(
    'post_type' => 'attachment',
    'numberposts' => 25,
    'post_parent' => $post->ID,
    'order' => 'ASC'
    );
    
    $attachments = get_posts($args);
    if($attachments){
    foreach($attachments as $attachment){
    $atturl = wp_get_attachment_thumb_url($attachment->ID);
    $attlink = get_attachment_link($attachment->ID) . '&paged=' . $paged;
    
    echo '<a href="' . $attlink . '"><img src="' . $atturl . '"></a>';
    
    }
    };
    ?>
    Thread Starter md84

    (@md84)

    I now have this, but it doesn’t work. Can somebody help me?

    <?php if(is_paged()){ ?>
    
    <?php
    $args = array('order'=>'ASC', 'post_type'=>'attachment', 'post_parent'=>$post->ID, 'post_mime_type'=>'image', 'post_status'=>null, 'numberposts'=>-1,);
    $attachments = get_posts($args);
    if($attachments){
    foreach($attachments as $attachment){
    echo wp_get_attachment_link($attachment->ID . '&paged=' . $paged, 'thumbnail', true, false);
    }
    };
    the_content();
    ?>
    
    <?php } else { ?>
    <?php the_content(); ?>
    <?php }; ?>
    Thread Starter md84

    (@md84)

    Solved!

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query = new WP_Query();
    $wp_query -> query('category_name=film&posts_per_page=15&paged=' . $paged);
    ?>
    
    <ul style="list-style:none;">
    <?php while($wp_query -> have_posts()) : $wp_query -> the_post(); ?>
    <li>
    <?php if(is_paged()){ ?>
    <a href="<?php echo 'https://xxx/your_theme_name/?p=' . $post -> ID . '&paged=' . $paged; ?>"><?php the_title(); ?></a>
    <?php } else { ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php }; ?>
    </li>
    <?php endwhile; ?>
    <p><?php posts_nav_link(); ?></p>
    </ul>
    Thread Starter md84

    (@md84)

    I now have this, but it still does not work. The code under else is incorrect. Can somebody help me?

    <?php if(!is_paged($paged)){
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("category_name=film&posts_per_page=15&paged=$paged");
    } else {
    query_posts("category_name=film&posts_per_page=15&paged=$paged");
    } ?>
    <ul style="list-style:none;">
    <?php while(have_posts()) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>
    <p><?php wp_pagenavi(); ?></p>
    </ul>
    Thread Starter md84

    (@md84)

    This worked for me!

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("category_name=film&posts_per_page=15&paged=$paged"); ?>
    <ul style="list-style:none;">
    <?php while(have_posts()) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>
    <p><?php wp_pagenavi(); ?></p>
    </ul>

    I used a plugin to alter the appearance of my page nav. You can also use:

    <?php posts_nav_link(); ?> instead of <?php wp_pagenavi(); ?>
    Thread Starter md84

    (@md84)

    I found the solution in the ‘Single Post Template’ plugin, which let you use a template file for posts.

    Thread Starter md84

    (@md84)

    Additional information:
    – The above mentioned website is the static version, I am working on the WordPress version from a local server (XAMPP).

    Thread Starter md84

    (@md84)

    I found the solution!

    – As a plugin I used ‘Lightbox-2’ (it also worked with ‘Lightbox Plus’).
    – When adding an image make sure that the image’s hyperlink is linked to the file itself instead of the post.
    – Make sure that <?php wp_head(); ?> is added to your header.php file (for the specific location look at the default theme).
    – Make sure that <?php wp_footer(); ?> is added to your footer.php file (for the specific location look at the default theme).
    – Sometimes it is necessary to select certain options within the plugin itself.

    This worked for me, yes!

    Thread Starter md84

    (@md84)

    I am still having problems with this, can somebody help me please…

    Thread Starter md84

    (@md84)

    Can somebody please help me?

    (Also duplicating the page.php and turning it into the single.php does not the trick for me. So I’m still stuck.)

Viewing 15 replies - 1 through 15 (of 20 total)