WordPress.org

Forums

How to get post ID in the loop in the custom template for page? (3 posts)

  1. DJManas
    Member
    Posted 2 years ago #

    Hello,

    I can't get current post id in the loop. Its give me the id of the page :( What i do wrong?

    <?php
    /**
     * Template Name: Page of work
     *
     * Selectable from a dropdown menu on the edit page screen.
     */
    define('WP_USE_THEMES', false); get_header(); ?>
    <script src="<?php echo get_home_url(); ?>/wp-content/themes/lowe/js/slides.min.jqueryWork.js"></script>
    <link rel="stylesheet" href="<?php echo get_home_url(); ?>/wp-content/themes/lowe/css/slideW.css">
    
    <?php $thumb_id = get_post_thumbnail_id( $page->ID);?>
    <?php $image = wp_get_attachment_image_src( $thumb_id,'full' ); ?>
    
    <div id="container" style="height: 741px; background-image: url('<?php echo $image[0]; ?>')">
    				<div id="slides">
    					<div class="slides_container">
    
    						<div class="slide">
    
    							<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    								<?php $thumb_ids = get_post_thumbnail_id(  $post->ID );?>
    								<?php $images = wp_get_attachment_image_src( $thumb_ids,'full' ); ?>
    								<div class="item">
    									<div class="ipop"></div>
    									<a href=""><img width="260px" height="137px" class='imgpop' tekst='<?php echo get_post_meta(42, 'caption_lt', true); ?>' src="<?php echo $images[0]; ?>"></a>
    								</div>
    
    							<?php endwhile;  ?>
    							<?php endif; ?>
    						</div>
    
    						<div class="slide">
    
    						</div>
    
    						<div class="slide">
    
    						</div>
    
    					</div>
    				</div>
    			</div>			
    
    <?php get_footer(); ?>
  2. DJManas
    Member
    Posted 2 years ago #

    <?php $thumb_ids = get_post_thumbnail_id( $post->ID );?>

    In this line the loop gives me not the current post ID but the page ID. :(

  3. DJManas
    Member
    Posted 2 years ago #

    <?php global $post; ?>
    						<?php $my_query = get_posts('category=5'); ?>
    
    						<?php foreach($my_query as $post) : ?>
    							<?php $thumb_ids = get_post_thumbnail_id(  $post->ID ); ?>
    							<?php $images = wp_get_attachment_image_src( $thumb_ids,'full' ); ?>
    							<div class="item">
    									<div class="ipop"></div>
    									<a href=""><img width="260px" height="137px" class='imgpop' tekst='<?php echo get_post_meta($post->ID, 'caption_lt', true); ?>' src="<?php echo $images[0]; ?>"></a>
    							</div>
    						<?php endforeach; ?>

    I used this loop instead of this and evrything works now :)

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    								<?php $thumb_ids = get_post_thumbnail_id(  $post->ID );?>
    								<?php $images = wp_get_attachment_image_src( $thumb_ids,'full' ); ?>
    								<div class="item">
    									<div class="ipop"></div>
    									<a href=""><img width="260px" height="137px" class='imgpop' tekst='<?php echo get_post_meta(42, 'caption_lt', true); ?>' src="<?php echo $images[0]; ?>"></a>
    								</div>
    
    							<?php endwhile;  ?>
    							<?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.