Home Forums Front-end Issues Display Image URL on Archive.php do'nt Work


Display Image URL on Archive.php do'nt Work

  • Hello Community,

    i try to display in Image URL on the Archive Page. But i don’t get anything.

    On Page Template it works great.

    Here is my Snippet:

    <div class="page-header" style="background-image:url(<?php the_field('titelbild2'); ?>); background-repeat: no-repeat; background-size:cover; background-position:center;">
    	<div class="container">
    					<?php if (is_category()) { ?>
    						<h1 class="archive_title h2">
    							<span><?php _e("Posts Categorized:", "wpbootstrap"); ?></span> <?php single_cat_title(); ?>
    					<?php } elseif (is_tag()) { ?> 
    						<h1 class="archive_title h2">
    							<span><?php _e("Posts Tagged:", "wpbootstrap"); ?></span> <?php single_tag_title(); ?>
    					<?php } elseif (is_author()) { ?>
    						<h1 class="archive_title h2">
    							<span><?php _e("Posts By:", "wpbootstrap"); ?></span> <?php get_the_author_meta('display_name'); ?>
    					<?php } elseif (is_day()) { ?>
    						<h1 class="archive_title h2">
    							<span><?php _e("Daily Archives:", "wpbootstrap"); ?></span> <?php the_time('l, F j, Y'); ?>
    					<?php } elseif (is_month()) { ?>
    					    <h1 class="archive_title h2">
    					    	<span><?php _e("Monthly Archives:", "wpbootstrap"); ?>:</span> <?php the_time('F Y'); ?>
    					<?php } elseif (is_year()) { ?>
    					    <h1 class="archive_title h2">
    					    	<span><?php _e("Yearly Archives:", "wpbootstrap"); ?>:</span> <?php the_time('Y'); ?>
    					<?php } ?>
  • in this part of the code
"background-image:url(<?php the_field('titelbild2'); ?>);...

    You are not inside of the loop so you need to provide the post id. Is this image on an options page? A post? A term? somewhere else?

    Assuming that it’s on an options page then it would be the_field('titelbild2', 'option'). If it’s somewhere else the you need to us the correct post id for that location. This is explained here under “Get a value from other places”

  • I try to give the Archive Page an background image for the h1-title.
    That’s why i give the Categorys an Image Field. If i upload an image, it must be display in the category/archive page.

    In the single page template it works great.


  • So, the field group and the field is edited when when editing a category.

    Do you also have this field on tag pages?

    Do you also have the images set up on the author page?

    If not, what image do you want to show on the tag and author archive pages?

    What image will you display on a date archive page? (year, month, day)

    You’re editing a generic archive page that can show any of these things.

    For all of the other types of pages should it show the image from the first post that’s displayed?

    As I said in my first post, the link I referenced above gives information on how to get values from different places.

    For a category or tag: the_field('field_name', $taxonomy.'_'.$term_id)

    For an author: the_field('field_name1', 'user_'.$user_id);

    I could tell you how to show the image on a category page, but that would not show an image for all of the other cases that can be displayed by your archive template. For example, this will work on a category page but would not work on an author or date archive page.

    $post_id = 0;
    $queried_object = get_queried_object();
    if (isset($queried_object->term_id)) {
      $post_id = $queried_object->taxonomy.'_'.$queried_object->term_id;
    <div class="page-header"
                the_field('titelbild2', $post_id); ?>); 
                background-repeat: no-repeat;
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Display Image URL on Archive.php do'nt Work’ is closed to new replies.