Problems with the <?php the_ID(); ?>
-
Hello!
First of all, I am trying to make a function in .php which checks if there is a image in a folder on the server. If the criterias match, it will load the image. This is used on my front page.
You can see my function here:
<?php $url = 'https://mydomain.no/wp/'; $filename = 'wp-content/uploads/front/post-'; $filetype = '.jpg'; $end = '" width="500" height="310" /></div>'; $start = '<div class="img-fix"><img src="'; $num = '25-'; for ($i = 1; $i <= 2; $i++) { if (file_exists($filename . $num . $i . $filetype)) { echo $start . $url . $filename . $num . $i . $filetype . $end; } else { echo ''; } } ?>
Okay, if you guys check the “$num = ’25-‘;” out, I want this to be unique in each post. Therefore, I think I need to use the “the_ID” in this case. Isn’t that correct?
So, If I try to change to this: $num = the_ID();, it will print the post number too early. I will maybe end up with the number before the rest of the code, if you guys understand?
So, is it possible to assign the post id to a variable like I am trying to? And it must be working individual in the loop of the index page.
All help is appreciated!
- The topic ‘Problems with the <?php the_ID(); ?>’ is closed to new replies.