• Resolved jlau

    (@jlau)


    This is very basic question, yet I’m having the hardest time trying to figure out how to pull this off.

    I have a side navigation set to a separate template php file called “sidenav.php” and it is this file that is pulling ONLY the sub navigation for the interior pages on my site. This side navgation is prevalent on every page except for the contact and blog section. There is a spot above the nav for ONE image or THUMBNAIL.

    Here are my questions for this dilemma:

    1. How do I go about doing this?
    2. How do I apply the loop to this?
    3. What is the <?php something_image(); ?> or “tag” should I be using?
    4. How do I embed this “tag”. Where should it go?
    5. How should I set up my file structure to have the tags/functions pull images from my images folder?
    6. How should I set up my images folder or how should I name the files?

    If I missed out on anything, please let me know. This is basic stuff I know, but I’ve spend hours already just reading WordPress documentations and it’s not making any sense to me.

    Thanks for reading this post. Hope to hear from you soon!

Viewing 15 replies - 1 through 15 (of 16 total)
  • Try using get_posts if you want a secondary loop in your sidenav. However, you don’t mention where these images are supposed to be pulled from.

    Thread Starter jlau

    (@jlau)

    Thanks for replying back to me so soon!

    I totally agree with you, but that’s exactly what I’d like to know. The images currently reside in the “images” folder, but how do I ask the loop or the function to pull them?

    If this is just a bunch of images sitting in a folder then you don’t ask the Loop to do anything. A WP Loop won’t work unless the image details can be pulled from the database. You just need plain ole PHP to pick a random image and display it. The only WP functions that you’ll need are get_stylesheet_directory and get_stylesheet_directory_uri.

    The former will give you the path to the images folder assuming that it’s placed within your current theme’s folder. And the latter will give you the image url when it’s time to display it. The rest is just down to how you intend to choose a random image.

    Thread Starter jlau

    (@jlau)

    Is there a way to pull the images from the folder, but not in “random” order? The sidebar navi is a template tag piece that lives on every page, but the image/thumbnail above the navi should be dynamic. Meaning the “about” page is one specific image, the “meet us” page has a specific image, and so on….

    Thanks!

    Why not add a featured image to each page and use the_post_thumbnail?

    Thread Starter jlau

    (@jlau)

    This post comment is extremely hacked up. So pardon the confusion.

    I looked into this before. This was the site I was looking at the code: but does all this mean?

    $default_attr = array(
    			'src'	=> $src,
    			'class'	=> "attachment-$size",
    			'alt'	=> trim(strip_tags( $attachment->post_excerpt )),
    			'title'	=> trim(strip_tags( $attachment->post_title )),
    		);

    I would assume I plug the <?php the_post_thumbnail( $size, $attr ); ?> into my <img src=””/> tag? Should I use the ? If so, in the example it asks you to plug in “<?php echo get_the_post_thumbnail($page->ID, ‘thumbnail’); ?>”

    I know what $page->ID means, but how does the code know which page i am specifically in?

    Thanks!

    Thread Starter jlau

    (@jlau)

    Thread Starter jlau

    (@jlau)

    [Code moderated as per the Forum Rules. Please use the pastebin]

    how does the code know which page i am specifically in?

    The page ID is part of the results that are returned by the query – either the standard WP query or a custom query using get_posts or query_posts. Have you tried just using the_post_thumbnail()?

    Thread Starter jlau

    (@jlau)

    I actually have the the_post_thumbnail embedded into my code.

    My only confusion is trying to understand what this code means:

    <?php if ( has_post_thumbnail()) : ?>
       <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
       <?php the_post_thumbnail(); ?>
       </a>
     <?php endif; ?>

    Thanks!

    Thread Starter jlau

    (@jlau)

    I took out the image like you suggested and implemented the only the “the_post_thumbnail().” It’s a blank now, which I guess is a good thing. But how does it know which pic goes with each page?

    Thanks!

    Translation: If this post (or page) has a post_thumbnail (aka featured image), output a link to the post using the featured image thumbnail as the link “text”.

    So the code is using the post thumbnail to create a link to the associated post.

    Thread Starter jlau

    (@jlau)

    Ah ha! Thank you! So…does this mean I need to change the naming scheme of the images themselves? Like for example, “about page” I would need to name the image file about-feature-image.jpg.

    About -> the page
    Feature – > the post
    Image -> image

    This image would reside in the images folder and the ‘src’ => $src would be $images? Assuming “src” is finding only folders.

    I know this is very rudimentary, but am I breaking this down correctly?

    Thanks!

    No – you don’t need to change any image filenames. You just need to have set up a featured image for each page/post. WP stores the association between featured image & post in your database.

    Thread Starter jlau

    (@jlau)

    Thanks! Let me give this a try.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘How to generate different images per page?’ is closed to new replies.