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.
Related
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.
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(); ?>
I'm teaching myself Wordpress, and my current goal is to display 4 thumbnails of images posted in a particular category.
I've already got the posts being pulled in by category, however I cannot pull ONLY the images. It's either the images and post text, or none at all.
My code is posted here: http://pastebin.com/NZ7fyyPA
I've tried simply replacing
<?php the_content(); ?>
with:
<?php the_post_thumbnail(); ?>
but that didn't work at all. Nothing came back at all!
I've even tried simply removing:
<?php the_content(); ?>
and same as above! I was thinking that because I have
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
That would pull the thumbnail in only, so I thought removing the content would help but nope!
I've read through the Codex here: http://codex.wordpress.org/Function_Reference/the_post_thumbnail
and the only question I have from that, is that immediately the Codex says:
"Use get_the_post_thumbnail($id, $size, $attr ) instead to get the featured image for any post."
Which I don't think I'm doing, because I haven't setup anything related to a 'featured image' in my theme...or is what I'm trying to do considered using a featured image? I'm only uploading images and posting them inside of the blog posts.
Sorry for the long write up, I'm sure it's something simple!
Thanks!
One more thing you can set a featured image from admin and call that image with this code the_post_thumbnail( $size, $attr ); and when you want to show anything from content part then you can call with this code simply. the_content();
you can also use excerpt for this as the_excerpt();
Thanks
This is a bit of a hack; however, it works.
While viewing your Wordpress website, use the browsers developer tools to target the 'post text'. You'll be able to see the id that is associated with that data-set.
Then, in your CSS. Target that id and use display:none;
Example:
#posttext {
display:none;
}
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'); ?>
We have a Wordpress News Blog on our website (http://www.litepanels.com/news/) that is separate from the rest of the static html website. I just want to take the latest story (the featured post) and display it on our home page. The Blog and our website are on the same server. I found I can grab post titles like this:
<?php
require('../news/wp-blog-header.php');
?>
<?php query_posts('showposts=3'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_title(); ?><br />
<?php endwhile;?>
but I do not know PHP well, how do I grab just the featured post (which has a title, image and text as you can see in the link above)
I am testing it here: http://www.litepanels.com/newwebsite/blog_test2.php
If that works for you, it means you've got all you need except for some way to display your information. For this, Wordpress provides some template tags that can be used within the while loop. the_content is the one you need. Others can be found in the Codex.