Loading different logo php file using If statement - php

I have a custom page template created. When I load my page, it shows the header logo of the mainpage but what I want to achieve is for each custom template created, I want it to only show its own logo.
This is the bit of the header code that calls the logo.php file:
<?php get_template_part('parts/logo', 'top') ?>
This is what I have tried but not working
<?php if ( is_page('custom-page')) {
get_template_part ('parts/custom-logo', 'top');
} else {
get_template_part('parts/logo', 'top');
} ?>
Any help will be much appreciated.
Thanks

OK I figured it out :). Not sure if this was an error from the owner of the Theme but in the header file, the logo bit was called like this get_template_part('parts/logo', 'top'); but when I checked the folder parts the actual file name was logo.php but I was expecting to see logo-top.php. That was a bit misleading to me but I might be wrong
So what I simply did was rename my custom-logo.php to custom-logo-top.php and that fixed the problem.
In fact I also tried this without renaming the file by replacing top with logo and it still worked:
<?php if ( is_page('custom-page')) {
get_template_part ('parts/custom', 'logo');
} else {
get_template_part('parts/logo', 'top');
} ?>

Related

Wordpress functions not working custom page

I've created a page called "page-myslug".
<?php
/*
Template Name: myslug
*/
I see that in the back-office, but when I go to the page through url (so www.mywp.com/wp-content/themes/site/page-myslug.php?value=4243 => value=4243 because my page is for create PDF, it's not WordPress in the proper way). I have an error message saying that my functions aren't defined (I used them to create url to display PDF thanks to TCPDF). It's working if I add :
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
But it's clearly not recommanded, so what can I do to fix that?
It is not recommended to create pages in that way. Instead do it in a wordpress way....
Your pdf generation link should look like : yoursite.com?create_pdf=1
not in your theme's functions.php write code -
add_action('init', 'create_pdf_file');
function create_pdf_file(){
if(isset($_POST['create_pdf'])){
// Do your pdf printing task
exit;
}
}
Try this below
add_action('init', 'create_pdf_file');
function create_pdf_file(){
if(isset($_REQUEST['create_pdf'])){
// Do your pdf printing task
exit;
}
}
OR
add_action('init', 'create_pdf_file');
function create_pdf_file(){
if(isset($_GET['create_pdf'])){
// Do your pdf printing task
exit;
}
}

Woocommerce (shop) header in product-archives.php file

I read that it is possible to place alternative header into woocommerce pages using get_header('shop'); in product-archives.php template in my custom theme. In order to make it work I need to make copy of header.php file and rename it to header-shop.php. It should be also located in same folder as header.php file.
Unfortunately I can't get this to work.
Anything I am missing if somebody notices that would be great help.
You can have a work around.
Just make a copy of header.php in your current theme with the same name (i.e. header.php).
Create another copy of the header.php with you desired name(i.e. header-shop.php).
Now you just need to add a custom code in header.php at the starting lines to check that whether its a product archive page(using this function http://codex.wordpress.org/Function_Reference/is_post_type_archive), if yes then include the header-shop.php else show the below default code of the file itself.
An Example Snippet:
if ( is_post_type_archive('product')) {
// Load header-shop.php
}else{
// continue with default code
}
Even you can load header-shop.php with the PHP function include_once()
if ( is_post_type_archive('product')) {
include_once 'header-shop.php';
}

Wordpress custom page code

I'm very new to wordpress and was just wondering if anyone
could point me in the direction of a tutorial which will explain
how to add my own code to wordpress pages.
So far all that I've been able to find is that I'm supposed
to copy the page.php from my template and use that as the
template for a page added in wordpress. This however only
gives me control over the body and not the header/nav menu/sidebar.
Am I correct is assuming I must replace the method calls such as
get_header(), etc with the code it would generate and manipulate
it from there? Also is it correct if I change the arguments to
get_template_part( 'content', 'page' ); and add a php page with
the appropriate name for the body?
Way 1 You can do this:
1) add new page
2) add these code to index.php or page.php
<?php
if (is_page('About 3C')) {?>
<div>Display this particular div</div>
<?php }
else { ?>
<div>Display that particular div</div>
<?php }?>
or
<?php
if (is_page('About 3C')) {
<div>Display this particular div</div>
}
else {
<div>Display that particular div</div>
}
?>
assume your added page name is: About 3C
and you can call the database from above code
OR way 2: please refer:
http://line25.com/tutorials/how-to-create-a-wordpress-custom-page-template

Admin tool bar in wordpress

I am developing my own wordpress theme for very first time. I want that when admin login to WordPress, at top admin tool bar must be show on main front end of website.
I tried following things
if (is_user_logged_in())
{
show_admin_bar(true);
}#end if
in functions.php
What I believe that I missed some thing in header.php or index.php, but I am not sure.
The proper way to do this is with a filter in functions.php:
function my_function_admin_bar(){
return is_user_logged_in();
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
The admin bar is called as part of the wp_footer() function, so you need to make sure you call that function in your footer section of the template:
<?php
wp_footer();
?>
A discussion of some specific issues that can cause this to break can be found here:
http://wordpress.org/support/topic/admin-bar-not-displaying
And finally, more details on how to use the show_admin_bar() in the functions.php file can be found here:
http://codex.wordpress.org/Plugin_API/Filter_Reference/show_admin_bar

How to change WordPress Archive Page Title

I would like to change the text (illustrated on the image below) from 'Portfolio Archives' to 'Shop'.
I have archive.php and portfolio.php files, none of which has any obvious indication of how/where to change the text.
screen shot http://damtech.it/screen.png
Your image link is broken...
But the title usually is in your header.php file.
I also come across this problem previous week.I was using a theme.This may help you or may not.But I face same problem ,so I am answering.
If you are using some theme.Then there should be your Theme Setting.
Go to theme setting and there will be Header and footer options.You may change this text from there.My problem was solved from there.
For anyone else who wasted time trying the approved answer, reading the function reference at https://codex.wordpress.org/Function_Reference/get_header and paying attention to this section:
Multiple Headers
Different header for different pages.
<?php
if ( is_home() ) :
get_header( 'home' );
elseif ( is_404() ) :
get_header( '404' );
else :
get_header();
endif;
?>
The file names for the home and 404 headers should be header-home.php and header-404.php respectively.
leads to the following successful approach.
Copy your (yourthemename)/header.php file to (yourthemename)/header-customname.php
Change the get_header() call in the file you are targeting to get_header('customname')
Job done.

Categories