[resolved] Image caption (5 posts)

  1. stoiko
    Posted 3 years ago #

    I want a text caption over the image when you hover with the mouse, but I am not sure how to do it in wordpress. I have this code:

    <?php while (have_posts()) : the_post(); ?>
    "> <?php echo inkthemes_main_image(); ?> " rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?>
    <?php endwhile; ?>

    And let's say I want to use one of these captions:
    How? I tried putting the style.css in the theme's style, but still didn't work...

  2. Michael
    Forum Moderator
    Posted 3 years ago #

    please re-post the code, and mark the code according to the forum guidelines http://codex.wordpress.org/Forum_Welcome#Posting_Code

    inkthemes_main_image(); seems to be a custom function of your used theme;

    what theme are you using?

    what is the code behind this function?

    you might need to post a link to your site to illustrate the image and text html in the context of the existing css.

    for pure formatting or css questions, please ask at a css forum like http://csscreator.com/forum

  3. stoiko
    Posted 3 years ago #

    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink(); ?>"> <?php echo inkthemes_main_image(); ?> </a></a>
    <?php endwhile; ?>

    Themia Lite, inkthemes main image is a function that calls the posts's main image.

    function inkthemes_main_image() {
        global $post, $posts;
        //This is required to set to Null
        $id = '';
        $the_title = '';
        // Till Here
        $permalink = get_permalink($id);
        $homeLink = get_template_directory_uri();
        $first_img = '';
        $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
        if (isset($matches [1] [0])) {
            $first_img = $matches [1] [0];
        if (empty($first_img)) { //Defines a default image
        } else {
            print "<a href='$permalink'><img src='$first_img' width='140px' height='208px' class='postimg wp-post-image' alt='$the_title' /></a>";
  4. Michael
    Forum Moderator
    Posted 3 years ago #

    the posted code simply pulls the first image tag from the post's content, which makes it virtually impossible to get the corresponding image caption.

    however, the theme also seems to use the 'featured image' if it is used;
    this would make it easier to show the image caption.

    then you will need to replicate the html and css structure from your example site.

  5. stoiko
    Posted 3 years ago #

    I used other css caption and it worked!

Topic Closed

This topic has been closed to new replies.

About this Topic