• https://test.noahdamaren.com

    I’m trying to only display one picture (of a multi picture post) on the index page. I’m wanting to link that image to the SINGLE POST page, then, have those images open up using FancyBox For WordPress plugin.

    Does anyone know my best option or multiple options for me to do this? The theme i am using is Modularity from Graph Paper Press.

    Thank you.

    -ndamaren

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

    (@ndamaren)

    one more thing…

    i need a boarder of 5px solid white to auto go around the picture, and have it align centered.

    Thanks again…

    -ndamaren

    Thread Starter ndamaren

    (@ndamaren)

    I am in despirate needs of this help. anyone out there?

    first step:
    this snippet would get the url of the image that would show closest to the top of a post:

    // kudos to: https://www.livexp.net/wordpress/get-the-first-image-from-the-wordpress-post-and-display-it.html
    $first_img = '';
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    $first_img = $matches [1] [0];

    (there are other ways to get an attachment image from a post; you should get results using the forum search.)

    the linking to single.php (this code has to be in a wordpress loop):
    <a href="<?php echo the_permalink() ?>" title="link to <?php the_title(); ?>"><img src="<?php echo $first_img; ?>" alt="image of: <?php the_title(); ?>" class="first_image aligncenter" /></a>

    you can use the css class .first_image to style your 5px white border:

    img.first_image { padding: 5px;
    background-color: #fff; }

    the alignment should work if your theme has the ‘normal’ styles for image alignment.

    third step:
    look for instructions with the plugin?

    Thread Starter ndamaren

    (@ndamaren)

    where am i posting all of this code to? ??

    into the template file that displays the page that shows the single images within the loop.
    (probably index.php, but could be home.php or whatever you or your theme has set)
    the first bit of code (getting the image url) comes directly before the second bit (linking to single display).

    Thread Starter ndamaren

    (@ndamaren)

    ok, now im having some issues trying to keep some other plugins working. I have the FAST TUBE plugin which allows me to post you tube videos easily. that wont work. this is what im getting

    https://test.noahdamaren.com

    also, im not sure how to get the css to work to get the borders.

    thanks for all your help, it is greatly appreciated!!!!!

    Thread Starter ndamaren

    (@ndamaren)

    any way of working around still showing the youtube videos still on the index page?

    with the code you have used, try to add these styles to the end of style.css of your theme (or into custom.css)
    (no guarantee, as this is only tested in firefox developer add-on)

    .home .entry a img.alignnone {padding:5px; background: #fff; }
    .home .container-inner { margin: 0px 15px; }

    the second line was neccessary, because your theme has an offset center space for the image.

    Thread Starter ndamaren

    (@ndamaren)

    by the way, THANK YOU SO MUCH! for all your help!!!! it is greatly appreciated!!!!

    you are welcome ??

    if it is working, please mark this thread as resolved (there is a field or button somewhere)

    Thread Starter ndamaren

    (@ndamaren)

    i will – but there are still a few more kinks i need to figure out. that code that displays the one image on the index page only displays images. if i write just a post with type, or use another plugin to attatch youtube videos, none of that content is displayed on the index page. and i cant figure out a solution.

    you could past the code of index.php into a https://wordpress.pastebin.com/ and post the link to it here.

    someone might have a look at it and might be able to make a suggestion.

    Thread Starter ndamaren

    (@ndamaren)

    ok, thank you very much!!! i thank you again for all your help – you have no idea!!!!!

    Thread Starter ndamaren

    (@ndamaren)

    need some help with this code:

    https://wordpress.pastebin.com/vZDe7qsX

    the get first image code is removing ALL conent from the index page. say the posts have no images but videos, the videos will not be displayed. any fix around this?

    in a way, <?php the_content(); ?> is missing from the loop;
    complication is that the_content() would also show all images;

    to strip images from posts:
    https://bavotasan.com/tutorials/removing-images-from-a-wordpress-post/
    instead of <?php the_content(); ?>
    use this

    <?php
    $content = get_the_content();
    $postOutput = preg_replace('/<img[^>]+./','', $content);
    echo apply_filters('the_content',$postOutput);
    ?>

    (imperfection: it leaves an empty html link tag behind in case of linked images)

    below is in the context of your existing code:

    <?php getImage('1'); ?>
    <?php
    // insert here to show the content without images;
    $content = get_the_content();
    $postOutput = preg_replace('/<img[^>]+./','', $content);
    echo apply_filters('the_content',$postOutput); ?>
    
    		<?php if ($blog_counter == 1) { ?>
    		<?php include (TEMPLATEPATH . '/apps/ad-main.php'); ?>
    		<?php  } ?>

    hope this is understandable; you could try it out and see how it works for you.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘How To Display One Image on Home Page…’ is closed to new replies.