show post thumbnail navigation link in in multiply pages - php

I have created a navigation for my WordPress, the navigation gets the title of the pages and display them by title.
Now I want to change the contact title to an image(mail icon of course).
I have add a feature image in the contact page.
I can call the thumbnail with
<?php echo get_the_post_thumbnail(); ?>
The problem is that the thumbnail image only shows when I'm inside the contact page where the thumbnail is added.
I could add the image in every page that I create, but it must be another better way to do it.
This is my navigation code.
<ul id="nav">
<?php wp_list_pages('exclude=19&title_li=', 'sort_column=menu_order'); ?>
<?php echo get_the_post_thumbnail(); ?>
</ul>
As you see I am excluding page 19, so it wont show in the navigation.
But i can call the image with the get_the_post_thumbnail.

After some searching i found out that i wasn't that hard at all.
If i want to use the thumbnail from page 19 I just write
<?php echo get_the_post_thumbnail('19'); ?>

Related

ACF and sidebar(WordPress)

I use ACF-plugin: https://wordpress.org/plugins/advanced-custom-fields/
There is a simple HTML file called sidebar.php.
This sidebar.php file has a place to display the image via ACF:
<figure class="Sidebar_Block">
<img class="ACF_Img" src=" <?php the_field('sidebar-latest') ?> "> // ****** place to display a picture ******
</figure>
In other files (home.php, category.php) i call sidebar.php via command
get_sidebar();
Image display only works on the home page (home.php)
And in the category.php file, displaying the image through ACF does not work.
The question is:
How to connect ACF to category.php and display image via WordPress admin?
The problem is that you saved sidebar-latest field only for your home page. I mean, it's attached to the home page. When you call the_field and you don't pass the page/post ID in the second argument, it will take the current one.
So for the homepage works because the sidebar image is saved for the home_page but not when you change page, in order to make it work, pass the home page's post ID to the second parameter:
<img class="ACF_Img" src="<?php the_field('sidebar-latest', $home_page_id); ?>">
So it will work on all page, also, remember to remove any extra space like my example.

Home.php using for blog content can't retrieve page title - Wordpress

Hi I want to do the blog part in my wordpress theme, I set up using static front page et blog page to display latest post.
So in my home.php I have :
<?php get_header(); ?>
<section class="header--page">
<div class="header--img">
<?php the_post_thumbnail() ?>
</div>
<div class="container">
<h1><?php the_title() ?></h1>
</div>
</section>
<?php get_footer(); ?>
But instead of getting title from page and featured image from page, It display those from the first posts, any idea ?
I try on my page.php and front-page.php, both are returning correct title and image
So things like the Posts page function a little differently than a standard page. Most likely, your the_title() function is returning the title of the first post to be displayed.
What you'll need to do is this instead:
<h1><?php echo get_the_title(get_option('page_for_posts')) ?></h1>
What needs to happen is you need to grab the ID of the Posts page, and use that ID to find its title.
So you'll want to use get_the_title() instead, because the_title() doesn't allow you to pass an ID of a page or post. get_the_title() accepts an ID as a parameter.
The page's ID that you specified as your Posts Page in the WP Settings > Reading can be grabbed by using get_option('page_for_posts').
So putting it all together, the code snippet above will get the title of the Posts Page, and echo it on-screen. (get_the_title() doesn't automatically echo it's returned value like the_title() does, hence the addition of the echo.

how link several pages, and adding a plugin to a new custom WordPress theme

I've created my own WordPress custom theme for a website that I'm working on. It's my first time building a theme from scratch! I'm having a difficulty 1st: to link several pages to the fron-page, or home page. For example lets say that I want to link "Who we are", page + "Contact us", page, etc.. How can I make WordPress understands that each page is different, and link to it? here is what I did so far:
in page.php I placed this code:
<?php get_header(); ?>
<div class="container">
<?php
if (have_post()) {
while(have_post()) {
the_post();
get_template_part( 'template-parts/content', 'page');
}}
?>
</div>
<?php get_footer(); ?>
I also created a content-page.php where I've placed my HTML code. (I'm building the whole thing with an HTML and CSS code that's just like building a website from scratch).
I also want to know when using a plugin, how can I connect that into the pages that I'm adding. For example, if I'm installing a form such as WpForms for a page like "Contact us" how can I link that?
Please let me know if my questions need more details
If I understand this correctly...
You want to be able to display (link) a couple of pages to your home page?
Ex:
[home page content here]
[Connect page content here] [Blurb page here]
If so, you need to pull in the page content into the home page.
Something like:
<?php
$postid = 0 /*Need to get page id, that's the key */;
//Pull in the page data
$featured_page = get_post($postid);
$thumbnail = get_the_post_thumbnail( $featured_page->ID );
//Only show the excerpt in this case
$content = apply_filters( 'the_content', $featured_page->post_excerpt );
?>
<article id="post-<?php echo $featured_page->ID ?>">
<header class="entry-header">
<h1><?php echo $featured_page->post_title ?></h1>
</header>
<div class="entry-content">
<div class="thumbnail">
<?php echo $thumbnail; ?>
</div>
<div>
<?php echo $content; ?>
</div>
</div>
Important! You'll need to get the page id from somewhere. You can hard-code it in, but that's risky if something changes. You can set up an Customizer option that lets the user select what page to use.
https://codex.wordpress.org/Theme_Customization_API
As for the contact form etc. I'd suggest putting it on a page as a shortcode, then displaying the full page, not the excerpt.
I use this code for a theme I built myself. If you need anymore help, let me know, I can show you where to find it.

My single.php page does not show the related data to the post which is clicked

I have a post for my site's logo and I have inserted its thumbnail in my header.php using the code below and it works fine:
<div id="logo">
<?php
$my_query = new WP_Query('showposts=1&cat=12');
while ($my_query->have_posts()):
$my_query->the_post();
$do_not_duplicate = $post->ID;?>
<?php the_post_thumbnail( 'site-logo'); ?>
<?php endwhile; ?>
</div>
Beside this I have a single.php file where I show the details of a post using Advanced Custom Fields plugin's codes and my problem is when I click on a post and I get redirected to single.php instead of seeing its thumbnail and details I see the site's logo and the details are empty.
This happened right after I added my logo as a post and used that post's thumbnail. Before that my single.php page was functioning very well.
How can I fix this without removing the logo? (Or if this problem is because of inserting logo this way recommend me a better way.)
Thanks.
I got my answer here. Thanks to WebElaine. All I need to do
is:
This probably has to do with the custom query - it's preventing other queries from working properly.
Setting a logo as a post seems an odd approach. Media attachments are already posts in and of themselves. Additionally, WP has a nice logo feature - custom-logo. I would add the logo that way and then just call the theme mod for the logo. That way you're not adding an extra query that throws off other queries.
In theme's functions.php:
<?php add_theme_support('custom-logo'); ?>
In theme's header.php:
<?php the_custom_logo(); ?>

Wordpress Featured Image only on overview

I'm using a template called 'expression' for Wordpress which works fine.
I'd just like to tweak it a little.
I have a page that shows all my blog posts, and ofcourse each blog post has an own overview if you click on it.
on each blog post you make, you can set a featured image. This image is shown on the overview page, and on each individual detailed view of 1 blog post.
I'm trying to find a way to only show this featured image on the overview page of all blogs, and not on the detailed view of a blog post.
Is there a way to do this?
I tried to edit the code in post-template.php by adding:
ispage('blog')
full code:
if(has_post_thumbnail() && !$hide_thumbnail && !is_page('blog')){ ?>
<div class="blog-post-img">
<?php if(!is_single()){?>
<a href="<?php the_permalink(); ?>">
<?php }
$img_id=$pex_page->layout=='full'?'post_box_img_full':'post_box_img';
the_post_thumbnail($img_id);
if(!is_single()){
?>
</a>
<?php } ?>
</div>
<?php
}
this works, but both featured images will be gone. which is not what I wanted.
Thanks for your help!
Got it eventually,
you have to use:
is_single();
instead of :
is_page();
Thanks anyway.

Categories