Skip Navigation

[Resolved] Post type template width and featured image background

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by Lykke Scavenius 5 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1289521

This is related to my old ticket: https://toolset.com/forums/topic/featured-image-as-background/ but I have tried to add all the information here.

Hi 🙂

There's the problem that I'm not able to make anything on this page full width, the single-psykologhus.php and content-psykologhus.php should be correct. I know I could just remove the CSS that sets the standard content width, but I only need some things to be full width, not all content.

Also, I am trying to create a banner for a post type called "Psykologhuse", and need to display the posts featured image as a background image for a div.
I've been able to make it work correctly in a view of psycologists, so the code works, I'm doing something wrong.

I have it displaying a background image on the post type for "Psykologhuse", but it's not showing the correct featured image.

The posts in "Psykologhuse"
hidden link
hidden link
hidden link

This is the original code that I put in toolset custom code section:

// Add Shortcode
function get_featured_url($atts) {
// Attributes
  $vals=shortcode_atts(
    array(
      'post_id' => '',
    ), $atts );
   
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($vals["post_id"]) );
return "style = 'background-image: url(". esc_url($feat_image).");'";
}
   
add_shortcode( 'get_featured_url', 'get_featured_url' );

I can't get it to work if I insert the code in the content template, so I inserted the following code in a view:

<div class="cover" [get_featured_url post_id="[wpv-post-id id='$psykologhus']"]>
  <h1>[types field='psykologhus-banner-overskrift' item='$current_page'][/types]</h1>
  <br/>
  <a class="findpsykolog" href="#findpsykolog">Find psykolog</a>
</div>

I then inserted the view into the content template for "Psykologhuse":

{!{wpv-view name='psykologhus-banner' limit='1'}!}

But it's a mess, maybe I need to clean up the structure, I have a lot of post relationships, hope you can help.

VIEW ID 13930 "Psykologhus banner"
CONTENT TEMPLATE ID 13733 "Psykologhus"

Thanks
Lykke

#1289621

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To get the parent ID I've changed the shortcode as given under. With Types 3.x you should use the item attribute:

<div class="cover" [get_featured_url post_id="[wpv-post-id item='@psykologhus-psykolog.parent']"]>

When I checked the shortcode I see that backgroun image URL is available with the style element:

<div class="cover" style="background-image: url(<em><u>hidden link</u></em>);">

Can you please tell me which image you want to display?
=> hidden link

#1290331

Hi Minesh,

This is the featured image of /psykologhus/vesterbro/
hidden link

Is it the wrong post type that's the parent or how come it's getting the wrong featured image? By the way, how come I have to insert a view into the content template, in order to show information, that is from the content templates' own post type?

Hope you can help 🙂

Thanks,
Lykke

#1290373

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now. I've added the "Query filter":
=> hidden link

Post ID filter
Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]

As well as I'm displaying view as given under:

{!{wpv-view name='psykologhus-banner' ids='{!{wpv-post-id}!}'}!}

I also adjusted the View's loop editor content template value as given under:

<div class="cover" [get_featured_url post_id="[wpv-post-id]"]>
  <h1>[types field='psykologhus-banner-overskrift' item='$current_page'][/types]</h1>
  <br/>
  <a class="findpsykolog" href="#findpsykolog">Find psykolog</a>
</div>

Can you please confirm you see now desired image:
=> hidden link

#1292411
wordpress-archive-template.PNG
featured-image-for-post-views-archives-and-templates.PNG
single-psykologhus-php.PNG
content-psykologhus-php.PNG

Hi again 🙂

Thank you so much!! This is working correctly now, you're awesome!

I want to ask again also, if you could help me identify why I can't make an element full width inside this content template.
In short:

  • I'm using full width settings using Visual Composer in the content template
  • I copied the templates like always, single.php > single-psykologhus.php and content-single.php > content-psykologhus.php
  • I removed the standard data, I think I did it correctly, but I've attached images of the files
  • For some reason I can't work in full width. I know it must be the template files but I don't understand. I promise I have tried on my own
  • Can you help?

featured image related problem
I'm having problems displaying the correct blog featured image as a background image in a view loop, it's for sidebars, pages and the blog archive, I need to display information on top of the featured image.

I've tried copying the same method as you used for the custom post type "Psykologhuse", but it's showing the wrong images.
You can see it here, I inserted the view in the bottom of the archive post loop: hidden link

I've attached images, but if you need to log in, the information is still the same.

Thanks
Lykke

#1292525

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I want to ask again also, if you could help me identify why I can't make an element full width inside this content template.
In short:

I'm using full width settings using Visual Composer in the content template
I copied the templates like always, single.php > single-psykologhus.php and content-single.php > content-psykologhus.php
I removed the standard data, I think I did it correctly, but I've attached images of the files
For some reason I can't work in full width. I know it must be the template files but I don't understand. I promise I have tried on my own
Can you help?
== Glad to know that your original issue is resolved. May I kindly ask you to open a new ticket with your every new question you may have. This will help other users searching on the forum as well as help us to write correct problem resolution summary for which ticket originally submitted.

#1292633

Thank you for helping to solve the issue. I will create a new ticket, but I was part of my original question and the other thing should be a similar solution so it would be duplicate issue. So I'll open 2 extra tickets.