I have a page on my Wordpress website called Blog, this is set to a static page and is the Blog page so it has a list of blog posts. On the blog page I have a featured image set. I want to use this featured image as a background image on the Blog page.
home.php (template for blog page):
At the top of home.php before the Loop that pulls the list of blog posts I have:
<?php
$page_id = get_queried_object_id();
if ( has_post_thumbnail( $page_id ) ) :
$image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $page_id ), 'optional-size' );
$image = $image_array[0];
else :
$image = get_template_directory_uri() . '/images/default-background.jpg';
endif;
echo $image;
?>
<div class="feature" style="background-image: url('<?php echo $image; ?>')"></div>
This works and it sets the featured image. However it seems to have set the featured image on every single page on the website to the featured image from the Blog page. Even after I changed the featured image on the About Us page it still pulls the URL for the Blog page's featured image and sets that as the featured image on the About Us page.
I have the website here: http://www.cqwebdesign.co.uk/Action-Harpenden-Physiotherapy/
As you can see by these screenshots I have set different featured images on the Blog and About page:
http://i.imgur.com/DnU8V9F.jpg
http://i.imgur.com/qshulWT.jpg
Anyone know how I can fix this?
As the home.php template affects only your Blog Page, it would be interesting how your page.php template code looks like (Notice: page.php is the default template for pages like your 'About' Page) and why the featured image isn't shown correctly on this page(s).
Try to debug or echo your id values for the Blog Page and the About Page and verify if the corresponding page id is the same as the one referred by get_queried_object_id();.
I think you're having a page.php template but just in case, if you don't have one please notice Wordpress' Template Hierarchy
Wordpress Codex:
When the static front page feature is configured properly, WordPress will not use a Custom Page Template to display the blog posts index, even if a Custom Page Template is assigned to the page designated as the "Posts page". WordPress will only use either home.php or index.php.
Related
So I have a website where a custom front page needed to be built as a static page, to do this I created front-page.php
I believe the original homepage just showed a list of posts.
The issue that I am having is that I want to link the front-page.php to the original front page of the website. I've had a look at using home.php and setting the URL on the front-page.php file to <?php echo get_permalink( get_option( 'page_for_posts' ) ); ?> but this just seemed to link to a single blog post.
Any ideas how I can resolve this?
Thanks in advance.
Go to Settings > Reading and check off A static page, Below it select Home as the Homepage. That should do the trick.
I want to show the page title in single post page of wordpress theme. I tried to use <?php echo get_the_title() ?> but it return the post title, not the page title.
basically I want to show MY page title, in this case "Blog" below my header area in single.php file. how do I make it?
In order to get page title you need to use WordPress API function use the code below
<?php
$post_7 = get_post($id);
$title = $post_7->post_title;
?>
In wordpress both posts and pages have ids. So same function will work to get title of either post or page.
You have to pass this parameter to get the title of the page.
For reference see this link
http://codex.wordpress.org/Function_Reference/get_post
Wordpress - separate blog page not showing the posts and showing the homepage of the custom theme... (not redirecting to home page just showing in place of blog page with the link http://www.example.com/blog on the addressbar of the browser)
As I have already adjust the setting on wp-admin following as
SETTING>Reading>
A static page
Front page to Home (homepage of the theme) and
posts to blog (separate blog page of the theme)
And Blog page consist the following code
<?php
/*
Template Name: Blog
*/
get_header();
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next post navigation.
next_previous_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
get_footer(); ?>
And the Home page of the theme is almost static page.
Make sure your static home page template is not in a file called index.php or home.php. If WordPress detects any one of those files it will automatically assume it is the template for your posts. Therefore create a front-page.php or similar for your static home page and index.php or home.php for your posts page.
I set my reading section to latest posts in Wordpress. My homepage logs fine but I would like to add a page title above the posts. I have looked in my theme's files and couldn't find the file to edit. As a test, I tried to add an image to my theme's loop.php and it appeared above the post on my homepage. The location was right but the image appeared on every one of my category blog list pages. How do I add a page title to the homepage that only appears on the homepage above the blog list?
Here are some resources for you to use, WordPress: https://codex.wordpress.org/Function_Reference/get_the_title
Eg:
you can use
<?php echo get_the_title(); ?>
or
<?php echo get_the_title($ID); ?>
There is lot of resources on WordPress, best of luck!
I am working on a site with WordPress for a client who wants to showcase her products online, but does not want to sell them over the web. I have a simple photo gallery set up with the NextGEN Gallery plugin. Upon clicking the thumbnails in the gallery view, instead of simply showing them in a lightbox or their own page, I would like to add a "details" page for each photo - kind of like the individual product pages on a shopping site, but without any of the shopping functionality. Would it be possible to do this using NextGEN gallery or another plugin, or do I have to do it from scratch (and how would I do that)?
Because NextGen doesn't actually create a WordPress 'Page' to link the single image to, you may be better off using the built-in WordPress Galleries (You may of seen the [gallery] shortcode). When you upload an image to a page or post, WordPress stores that image as a post in the wp_posts table, alongside all your other posts and pages.. with a post_type of 'attachment', and adds it to a 'Gallery' for the post or page. You can manage the current gallery for any page or post by clicking the 'Add Media' icon above the text editor. While the [gallery] shortcode is quite limited, you can use code in your theme to display the gallery and images anyway you want.
If it was me, I would make a 'Products' page and individual 'Product' pages as child pages of 'Products' (or if you want more flexibility, use a custom post type for the products) and then upload all the product photos into the 'Product' page galleries (creating a gallery per product) - and setting the primary image as the 'Featured Image' for each product page. Then in your 'Products' page template (page-products.php) I would make a loop to display all the individual Product page's featured images.. something like..
<?php
//Add this to your 'Products' page temaplte, page-products.php
$products = new WP_Query(array(
'post_parent' => $post->ID,
'posts_per_page' => -1
));
while ($products->have_posts()) : $products->the_post() ; ?>
<a href="<?php the_permalink() ?>" title="<?php the_title() ?>">
<?php the_post_thumbnail() ?>
</a>
<?php endwhile;
?>
That will create a list of the Product featured images, and you can use CSS to adjust the display - and each featured image will link to the individual product page.
Then in your individual Product pages (you can use a page template to target all of them), you can display the individual product gallery (like detail shots of the product) using get_children() or use the_post_thumbnail() again to display a larger close-up version of the primary photo. And of course, then you can use the post content of your individual product page to display the info text for each photo, like so:
<?php
/* Template Name: Individual Product */
while (have_posts()) : the_post();
the_post_thumbnail();
the_content();
endwhile;
?>
To take it another step further, you could add all sorts of other data about the individual product with custom meta boxes, and display them on the side of the page or something.. like 'Product Size', 'Color', 'Foo', 'Bar'.. anything really. Hope that helps!