Nic727
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Comments template questionsHi,
I’m developing my own theme and using the default comments form.
I know my code doesn’t make any sense lol. My problem is that I read this page about has_category() and I can’t find a way to make it works. The problem is that if I unselect all categories from my post, it put “Uncategorize” by default. I can’t choose an empty category.
EDIT: Well, I guess I just have to make sure I always add a relevant category to my post even if it’s a random post about anything…
- This reply was modified 3 years, 6 months ago by Nic727.
Forum: Fixing WordPress
In reply to: Featured images not showing correctlyHi, I finally fixed that by using page-photography.php I had to reinstall WordPress on a new subdomain, because it wasn’t working on the previous one. Now all good.
Forum: Fixing WordPress
In reply to: Featured images not showing correctlyI almost fixed that.
I found that using
$pageID = get_queried_object_id();
can find the current page ID that I can finally work with for featured image, title and excerpt. However, now that my post page is working correctly, it’s not the same for my custom archive page. I have more trouble.First of all, I found this https://wordpress.stackexchange.com/questions/175226/cant-get-post-id-on-page-that-is-a-custom-post-type-archive where it seems that WordPress doesn’t recognize ID on archive and custom archive page. So to use my custom archive page design, I need to change
has_archive
tofalse
in my functions.php for my custom post type.To make it works, it seems that I need to change my archive-photography.php to page-photography.php.
It would work, but for some reasons, page-photography.php is not working since mysite.com/photography is showing the same thing as mysite.com/blog which use home.php template.
EDIT: I revert it back to archive-photography.php to make the page work. Just need to figure out how to get the ID of this page even if it’s an archive template. In my admin panel I see the page is ID 65 and if I use this ID to show thumbnail, it works, but I can’t find a way to retrieve this ID since the code above doesn’t work for this page.
EDIT 2: I tried page-photo instead and it works, but not ideal. I don’t know why page-photography doesn’t work. Maybe because the custom post type is named “photography” and the archive is supposed to be “photography” too, so it just cancel it? Need to find out.
Forum: Fixing WordPress
In reply to: Featured images not showing correctlyI don’t understand why it’s so complicated. I understand that calling a title, featured-image, etc. on a page that has a loop is not ideal, but it’s the way I designed my website. I already have an index page with two loops and it works well (https://pg.nicolas-duclos.com/), but my main blog repository also need an image and title… How do you want people to know which page they are on if there isn’t any informations? https://pg.nicolas-duclos.com/blog/
I found out that
the_title();
andget_the_title()
shouldn’t be used outside of the loop… I’m surprised to see that WordPress, after all those years doesn’t have a way to work outside the loop.I’m trying stuffs with
<div class="page-title"> <?php if (is_page()||is_home()): ?> <h1><?php single_post_title(); ?></h1> <?php endif; if (is_archive()): ?> <h1><?php post_type_archive_title(); ?></h1> <?php endif;?> <?php if ( has_excerpt() ) : ?> <h2><?php echo get_the_excerpt(); ?></h2> <?php endif; ?> </div>
It kinda work to get the page title. Except my archive title is taking the main “archive plural name” instead of the page title or singular name… I also saw the wp_title() in the header is also using the plural name instead of singular. How can I change it?
- This reply was modified 3 years, 6 months ago by Nic727.
Forum: Fixing WordPress
In reply to: Featured images not showing correctlyNot working.
Here is my page
<?php //Blog page template get_header(); get_template_part( 'template-parts/header/navigation' ); get_template_part( 'template-parts/page/page-featured-image' ); ?> <section class="container"> <div class="section-flex"> <div class="title-section"> <h2><?php _e( 'Aper?u', 'aurora' ); ?></h2> <h3><?php _e( 'Articles récents', 'aurora' ); ?></h3> </div> <div class="section-right"> <?php get_template_part( 'template-parts/page/filter' );?> </div> </div> <?php //Rewind index rewind_posts(); $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 15, 'orderby' => 'date', 'order' => 'DESC', ); $loop = new WP_Query( $args ); if ( $loop->have_posts() ){ //Blog container echo '<div class="flex-container">'; // Start loop while ( $loop->have_posts() ) { $loop->the_post(); PG_Helper::rememberShownPost(); get_template_part( 'template-parts/page/blog-post' ); } wp_reset_postdata(); echo '</div>'; }else{ _e( 'Sorry, no posts matched your criteria.', 'aurora' ); } ?> </section> <?php get_footer(); ?>
and my code for my page-featured-image template
<?php //Variables $page_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); ?> <!-- PAGE FEATURED IMAGE --> <section class="page-header"> <div class="featured-image-container"> <div class="featured-image" style="background-image:url(<?php echo $page_image[0] ?>)"></div> <div class="img-overlay"></div> <div class="page-title"> <?php the_title('<h1>', '</h1>'); ?> <?php if ( has_excerpt() ) : ?> <h2><?php echo get_the_excerpt(); ?></h2> <?php endif; ?> </div> </div> </section>
I’m trying to find some info on Google, but no luck yet.
I triedwp_reset_postdata();
, but this function is used if you have multiple loop… I actually use it on my homepage (front-page) where I have two different loops.
I even triedwp_reset_query();
, but not working.Forum: Fixing WordPress
In reply to: Featured images not showing correctlyAfter looking at the TwentyTwentyOne theme, I have no idea where I get it wrong. I tried with the_title() for my current page title and get_the_title() for the posts showing in the loop, but it still showing the last post from the loop as a main title of the page and featured image…
Initially it’ll be the page’s object, but when you make a post query on a page template, it very likely becomes the WP_Post object for the current post in the loop instead of the page’s object. It’s current value is contextual. It sounds like your trouble is because this still hasn’t been properly resolved.
I’m a noob, so I don’t know what you mean. As I understand, you need to separate the loop info from the page info, but I’m not sure to understand how since I can’t find that in the developer index.
Forum: Fixing WordPress
In reply to: Featured images not showing correctlyAlright… I think the problem was because I was calling my variable globally instead of inside my loop which was messing the stuffs. It was returning bool(false). Now the image are showing correctly, but still have a problem with my header on my blog and photographie page.
My page header is
<?php //Variables $page_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); ?> <!-- PAGE FEATURED IMAGE --> <section class="page-header"> <div class="featured-image-container"> <div class="featured-image" style="background-image:url(<?php echo $page_image[0] ?>)"></div> <div class="img-overlay"></div> <div class="page-title"> <?php the_title('<h1>', '</h1>'); ?> <?php if ( has_excerpt() ) : ?> <h2><?php echo get_the_excerpt(); ?></h2> <?php endif; ?> </div> </div> </section>
Not sure why it doesn’t take the page featured image and title if it has posts on the page. For example, it works on that page, but it doesn’t have posts. https://pg.nicolas-duclos.com/a-propos/
—-
There are two things I have problems with;
1. When and when not to use global variables?
2. Most of the code on the developer website is using if: and endif;. Should I re-write my code using if{} instead?- This reply was modified 3 years, 6 months ago by Nic727.
Forum: Fixing WordPress
In reply to: Featured images not showing correctlyI added the semicolon and I still have the issue. I checked all my code for missing semicolon, but didn’t found anymore.
Here are some links I have problems with:
https://pg.nicolas-duclos.com/
https://pg.nicolas-duclos.com/blog/ (no idea why it’s only repeating itself everywhere and the page featured-image is the post featured-image instead).
https://pg.nicolas-duclos.com/photographie/I’ve tried to use get_the_post_thumbnail_url() instead of the long code, but it’s just not working. I don’t know why. If I enter echo “T” as background-image it work, but if I use my variable or even paste the full code there, it’s just empty.
- This reply was modified 3 years, 6 months ago by Nic727.
Forum: Developing with WordPress
In reply to: echo get_theme_mod not showing on live websiteNevermind… In fact the default text is just not showing, so I needed to cut and paste the text already there… Go figure.
Forum: Fixing WordPress
In reply to: Custom form vs plugin?Thank you. However, I feel like with plugin you have less customization options than doing it yourself.
For example:
My own contact form
https://i.postimg.cc/MK3K67t0/contact2.pngContact Form 7
https://i.postimg.cc/Pr55n3br/contact1.pngOr maybe I can customize, but I didn’t find how?
Forum: Developing with WordPress
In reply to: Custom page template – slug and titleSorry for my confusing question.
It was more about which one should I use between page-about.php and page_about.php. However, your answer is helping me a bit to understand the difference.
As I underdand, the slug is the URL after .com/slug so page-about.php would be .com/about or .com/page-about ?
So if I create a page called “Part 1 of my adventure” for example, and decide to use the slug “about”, it would use the page-about.php template right? But it can only be used one time…
If I need to translate my page and use a plugin, would I need to use another template page since slug would be different? Would be better to use a global template then…
Thank you
Forum: Everything else WordPress
In reply to: Gutenberg as a page builder? When?Interesting. Can’t wait to see how it will looks like.
Just hope it will not be like Elementor or some themes where there are 10 divs for a single text. Need optimisation and clean code editor with the block editor.
- This reply was modified 3 years, 6 months ago by Nic727.
Forum: Developing with WordPress
In reply to: Best markup for WordPress?I want to add dynamic page title in this code
<section class="page-header"> <div class="featured-image-container"> <div class="featured-image" style="<?php if($page_image) echo 'background-image:url(\''.$page_image[0].'\')' ?>"></div> <div class="img-overlay"></div> <div class="page-title"> <h1>TITLE HERE</h1> </div> </div> </section>
I know for category.php it’s
<?php echo single_cat_title(); ?>
, so I thought that the_title() was doing the same thing for posts and pages…Forum: Developing with WordPress
In reply to: Different stylesheet for each pagesOk nevermind, I found out you can do something similar to that
function aurora_scripts(){ wp_enqueue_script('aurora_jquery', "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.1.min.js", array(), '3.5.1', true); wp_enqueue_script('aurora_js', get_template_directory_uri(). "/assets/js/scripts.js", array('aurora_jquery'), '1.0', true); if(is_home()){ wp_enqueue_script('swiper_js',"https://unpkg.com/swiper/swiper-bundle.min.js", array(), '1.0', true); } }