Our Wordpress site suddenly stopped showing all 'featured' images. They're just blank. When we look at the source code it shows url(896). We have tried selecting the image again (which shows fine in the backend) but on the frontend it's still blank with an invalid URL. Any idea how to fix that and what may have happened? TIA!
To update: this below code is what's being used to pull the featured images (with the incorrect URL):
<div class="hero homepage relative-block" style="background-image:url(<?php the_field('hero_background_image'); ?>);<?php $hero_aspect_ratio = get_field('hero_aspect_ratio'); if( $hero_aspect_ratio ) { echo "padding-top:".$hero_aspect_ratio."%;"; } ?>"></div>
EDIT:-
The following also isn't grabbing any content. Any ideas?
<div class="page-content">
<?php get_template_part('content-block-loop'); ?>
</div>
Your field hero_background_image returns attachment ID instead of the URL of the image. Use wp_get_attachment_url($id) with get_field() that returns the id, instead of the_field() that outputs the value to get the URL of the attachment/image:
<div class="hero homepage relative-block" style="background-image:url(<?php echo wp_get_attachment_url(get_field('hero_background_image')); ?>);<?php $hero_aspect_ratio = get_field('hero_aspect_ratio'); if( $hero_aspect_ratio ) { echo "padding-top:".$hero_aspect_ratio."%;"; } ?>"></div>
Possible cause: if you use some metabox/custom fields plugin as MetaBox, Toolset Types or the ACF, someone has probably changed the settings for the field, to return the ID of the attachment instead of the URL. So that might also solve the issue.
Related
I m working on a website in wordpress.
I searched for a problem that i want a different logo in one page of my site using any plugin but i didn't find a satisfactory solution.
Kindly someone tell me how can i do this that main logo should be appear on the whole site but secondary logo should appear on one page of my site
if you know wordpress developement, you can use conditional tags. ref
You can use the is_page() method to check which page you are in and change the logo accordingly.
So, in the header or where ever your logo is displayed, you will do it like this:
<?php
//Returns true when the Pages displayed is either post ID = 42, or post_name is "about-me", or post_title is "About Me And Joe".
if(is_page( array( 42, 'about-me', 'About Me And Joe' ) ) )
{
//display the secondary logo
}
else
{
//display the main logo
}
Of course I'm assuming here that the page you want it to be different is a WordPress page
If it's a listing page or a single post page then you can use different methods of checking. All of which are described here.
Please insert this code to your header.php file.
$ss = $wp_query->post->post_title;
if($ss == 'your page name'){
echo '<img src="/your-new-logo.png" />';
}
else{
echo '<img src="/your-current-logo.png" />';
}
I am trying to add a waitlist button functionality to a page on my wordpress website. Basically I need to autopopulate the source key in the query string in a url with the page title.
More Details:
I have the button linking to a general waitlist form but I want the product information from the page title go into a text field. I can do this by using a source key in the url.
We have our product listed on a portfolio post here with a waitlist button: http://www.inventivewebdesign.com/renohifi/listings_portfolio/pass-labs-xa-160-8-monoblock-power-amps/
The button goes to a form here with a text field that auto populates with the source key in the url.
So if I use the link: http://www.inventivewebdesign.com/renohifi/waitlist-request/?source=Pass%20Labs%20XA-160.8%20Monoblock%20Power%20Amps, The source key will populate the the product text field with "Pass Labs XA-160.8 Monoblock Power Amps". This all works great!
Now, I want to automate the code for the button so it always pulls the Page title as the source key so we don't have to manually enter in code for each button.
How can I get the page title to auto-populate the query string in the link url so that the link will be http://www.inventivewebdesign.com/renohifi/waitlist-request/?source={PAGE_TITLE}?
FYI - I am using the Visual Composer plugin for page layout and button creation.
UPDATE:
I am trying to use code like this:
<div class="vc_btn3-container vc_btn3-center">
<a title="Waitlist - <?php the_title_attribute(); ?>" href="http://www.inventivewebdesign.com/renohifi/waitlist-request/?source=<?php echo get_the_title(); ?>">
Add Me to the Waitlist
</a>
</div>
It is in the Wordpress editor so the code is not showing up as anything other than code. I want the title to show (I am trying two different wordpress calls for the page title). You can see this in the 2nd "Add Me to the Wishlist" Button on the first link above.
In JavaScript you can get the page title from the DOM using document.title, the value is encoded using the encodeURIComponent() function.
Your URL as a JavaScript string:
var url = "http://www.inventivewebdesign.com/renohifi/waitlist-request/?source=" + encodeURIComponent(document.title);
I couldn't find any reference to the URL on the page to which you linked.
EDIT: To encode the title string using PHP you need to use the urlencode() function.
Template code:
<div class="vc_btn3-container vc_btn3-center">
<a title="Waitlist - <?php the_title_attribute(); ?>" href="http://www.inventivewebdesign.com/renohifi/waitlist-request/?source=<?php echo urlencode(get_the_title()); ?>">
Add Me to the Waitlist
</a>
</div>
I did it by adding a shortcode instead:
function shortcode_waitlist( $atts ){
$pagetitle = get_the_title();
$link = '<div class="vc_btn3-container vc_btn3-center"><a class="vc_general vc_btn3 vc_btn3-size-lg vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-block vc_btn3-color-primary" href="http://www.inventivewebdesign.com/renohifi/waitlist-request/?source='.$pagetitle.'" title="Waitlist - '.$pagetitle.'">Add Me to the Waitlist</a></div>';
return $link;
}
add_shortcode( 'waitlist_button', 'shortcode_waitlist' );
Then just used [waitlist_button] in the page.
Thanks for your suggestions, they helped me get to where I needed to go.
I am using a Portfolio Plugin. And it asks me to add the following shortcode in to the page where i want to show the content
[nimble-portfolio template="2colmosaic" types="3,4,5" items_per_page="3"]
When i do the following
$view = get_page_by_title('View');
echo $view->post_content;
It displays
[nimble-portfolio template="2colmosaic" types="3,4,5" items_per_page="3"]
as text when rendered
Edit
I tried to do the following
echo apply_filter('the_content', $view->post_content);
But it doesn't Render the full page now. And stops upto that point.
Try this following code and let me know the case then -
<?php echo do_shortcode($view->post_content); ?>
I'm developing a wordpress theme, and in my header.php I believe I have valid code, but for some reason, the thumbnail image is always shown in the code below.
The logic I'm trying to achieve is:
if this is the homepage, and the s3slider plugin has been installed
show the slider
else if this page has a featured image (the_post_thumbnail)
show the thumbnail
else
show a default image
My code block is:
if (is_front_page() && function_exists(s3slider_show()) ) {
//we're on the homepage, and s3Slider exists
s3slider_show();
} elseif ( has_post_thumbnail() ) {
//there is a featured image / thumbnail
the_post_thumbnail();
} else {
// the current post lacks a thumbnail
?><img alt="alt text" src="image.jpg" />
<?php
}
I can't for the life of me work it out, even though on the homepage the slider is shown, so is the_post_thumbnail() output.
Is it too late, and I've forgotten something fundamental?
I don't see why the_post_thumbnail will even be executed on the homepage if I've already entered the first if for the home / s3Slider combination.
function_exists() expects a string:
function_exists( 's3slider_show' )
Since your function s3slider_show doesn't return a string the first condition evaluates always to false.
I am trying to get the index-page of a Wordpress-blog show some very specific posts. As far as I understand i need to use a standard loop in order to make sticky posts work, so custom queries is out of the question. (Correct me if this is wrong.)
All posts are put in a main category (Eg. "Make-Up") In addition, posts that should show on the front page gets an additional category "Frontpage".
The current loop outputs all posts, regardless of category. And styles certain categories differently. An example would be the video-category which is only shown by getting an embed code from a custom field in the post.
<?php elseif (in_category('20')) : ?>
<div class="post element grid_4">
<?php echo get_post_meta($post->ID, 'Embed', true) ?>
</div>
I need to remove all posts not in the category "Frontpage" while still being able to control how posts are being shown.
Earlier i used a filter to control the main loop:
function exclude_category($query) {
if ( $query->is_home ) {
$query->set('cat', '20 27');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
However this would cause my geomashup-plugin to break as it probably uses the same loop?
My current proposal for a solution would be to do something like this, plus functioning code:
<?php elseif (the post is in BOTH category 20 and 27)) : ?>
<div class="post element grid_4">
<?php echo get_post_meta($post->ID, 'Embed', true) ?>
</div>
<?php else : ?>
<div style: display: none;></div>
However i am unsure about how make a condition demanding the post to be in two categories, and i realise this is a terribly dirty fix.
Any tips or pointers as to how i could solve this would be greatly appreciated :)
Front page can be seen here: http://parfymelle.brandbase.no
For anyone wondering i solved it by including the geotagged posts-category (the shop locations) in the filter for the main loop, and then using a php if in the index.php to hide posts from that category. Dirty, but works, i guess.