How to differentiate Front page and other pages in Wordpress? - wordpress

I have created a front page (i.e index.php) with my own design. This page will contain
header got from <?php get_header(); ?> [has navigation bar code]
Then some content. Here I'm showing three thumbnails of posts. [has slider, thumbnail posts etc]
And a footer from <?php get_footer(); ?>[has footer links]
The problem is, I see index.php loaded correctly as a front page. But when I navigate to other pages like About or Contact, the respective content from these pages is not showing up. Instead what getting loaded there is, same what Index page has. I don't want slider or thumbnail appearing on these pages.
So how to tell wp that, this is my front page, and this is my About page, don't load a slider and stuff on About page!?

use is_front_page() to determine the home page. like you only want slider on the home page then edit your header.php file that consist the slider part and do something like this
if( is_front_page() ):
// Front Page stuff like slider and
// whatever you want
endif;

Try this ,
if( is_home() || is_front_page() ){
//your home page content
}
else{
//other pages
}
For more here
Hope its works..

Make another template and set this template for your single pages. And then from backhand set it.

I usually create a front-page.php file, Wordpress will use that instead of index.php (which you can use as a generic template from then on).

Related

Content written in the Page edit box not showing in the published page in Wordpress

I am not sure what I am missing. Please guide me and I apologize if my knowledge is too less.
I have a home template file i.e. template-home.php which actually contains nothing for now and is only containing the following lines ->
<?php
/**
* This is the front page code
* Template Name: HomePage
*/
get_header();
get_footer();
?>
I have created a page from wp admin and given the page title "Home" then I selected template "Homepage" for this page I have created from wp admin. Hence I have set the static front page to display "Home". Its perfectly showing the Home page as front page. But when I am giving any content in the edit box of the page "Home" from wp-admin and updating, those contents are not displaying in frontend. But if I put any content in the "Homepage" template , only then its getting displayed. I am giving an example what I tried below-
When I am giving the following in the page edit box then nothing is displayed in real.
[rev_slider_vc alias="homebanner" title="Home Slideshow"]
For your information the above is shortcode of revolution slider which is working perfectly , if I use it in any post. So the shortcode has no error for sure. Another thing whatever I write in the content box is actually not getting displayed in real.
Now the slider code, if I am putting directly into the Home template i.e. template-home.php then slider is getting displayed. The code is as follows ->
<?php
/**
* This is the front page code
* Template Name: HomePage
*/
get_header();
// Revolution Slider
putRevSlider('homebanner', 'homepage');
get_footer();
?>
Though my purpose is getting served well by putting code into the template file directly. But I want that the content I put in the edit box of the page from wp admin can get displayed in real. So what I need to do for that ?
Read https://codex.wordpress.org/The_Loop and https://developer.wordpress.org/reference/functions/the_content/
You need a loop and you need the_content to grab the content from the text editor.
A very basic example:
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
the_content();
//
} // end while
} // end if
?>
Work with that first with some plain text to test the loop.
Then add your shortcode for the slider [rev_slider_vc alias="homebanner" title="Home Slideshow"] in the text editor. And, look at the docs for the slider on how to place the function putRevSlider('homebanner', 'homepage'); directly in the page template file, if you want to do that rather than using the shortcode in the editor.
See https://codex.wordpress.org/Theme_Development for how WordPress themes are structured and the types of basic files you need in each theme, i.e. index.php, style.css, etc.

Archive displayed on a custom page to be used in menu structure

I would like to direct users to appropriate archive pages from within the menu. If I want this I need a page that I can attach to the menu.
How would I display the exact same stuff as on the archive page (archive.php) on another page so that pagination and functionalities remain the same, but some stuff will be taken from the actual page ? (can create custom page template of course)
I'll still have to show a sidebar for the page that you visited and not archive's sidebar
Breadcrumbs path will still have to show current menu item position and not archive page path
To show sidebar from the actual page is of most importance here.
EDIT
What I want to achieve is this actually:
Lets say I have a page
http://my.page/subpage/something/notifications/
I want that on this page, I can display exactly the same stuff as on the certain archive page which is here:
http://my.page/subpage/notification/
('notification' is a custom post type here)
I already have a solution that displays all archive stuff on another page (created a page template for that), but its a bit complicated to display title, breadcrumbs and sidebar properly for each page, since some of these should stay the same as they would be, but some should take the value of another site.
You can create a custom page template and assign it to a page. On that page you can use get_posts() to query the posts you want, like this:
global $post;
$posts = query_posts( /* Your args here*/ );
foreach($posts as $post) {
setup_postdata($post);
// Do your stuff as in archive.php
}
wp_reset_postdata();

Make another content list as content file of wordpress

I have page I want to display the page in different style (not as the content.php file ) so now I made copy the content.php file and just modified it. I want to display only for one page and other pages should display like content.php . So how can I change the index page to display the particular as new content-list page. My page name is News and it should be display like content-list.php.
For display indiviual page you have to make a Template for that page and from
Dashboard-->Pages open the page where you want to display that template, on right hand side you have seen TAMPLATE-->DEFAULT TEMPLATE, select template you have created...
Syntax for new template
<?php
/*Template Name:abc
*/
?>
<?php get_header();?>
<!--------------------------------------->
CONTENT FOR PAGE
<!--------------------------------------->
<?php get_Footer();?>
I don't know about which file you're referring to as content.php
I have page i want display the page in different style
So, if you want to display a page with a different style, you should have a look at WordPress Template Hierarchy.
You can create another page template, use custom files like header-{name}.php and footer-{name}.php and use get_header() and get_footer() with the appropriate arguments(the {name} you mentionned to call these files.

sidebar in wordpress

I want to display different dynamic sidebar on different pages, how do I access multiple sidebar on my pages.
Place some form of hook on different pages.
Open sidebar.php in your themes and check for presence of hook.
You should create files like sidebar-xxxx.php and include it, using get_sidebar(xxxx) in the different templates and souhld register them on the functions.php. If you do not wanna create these files you can register the sidebars on functions.php and in the sidebar.php use:
global $wp_query;
$page_name = $wp_query->post->post_name;
<ul>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-'.$page_name) ) : ?>
<?php endif; ?>
</ul>
create a new sidebar
and you can link them inc with is page
if(is_page(5)) {
include('new-sidebar.php')
}
is page id is 5 lets say thats the id for your home page
just check the ids of your pages and seperate them
if you want them tho show in the page childs to
just write
if(is_page(5) || $post->post_parent) {
include('new-sidebar.php')
}
zou can even write a function either
For different sidebars, i thing you have to do is to create the sidebar which you want as many as you want and save those sidebars as sidebar1.php, sidebar2.php and so on.
And,just include it in the different pages where you want it to display like this:
<?php include('sidebar1.php'); ?>
And, like wise for other sidebars of other pages.

Wordpress function is_front_page() not working

I have a "static" page set up as my front page for Wordpress.
I have this in the index.php file:
<?php
if (is_front_page() || is_home()) {
?><p>TEST FRONT PAGE</p>
<?php
} ?>
For some reason, the "TEST FRONT PAGE" does not show up on the front page, but does show up on the posts page (as it should, for these purposes only)...I'm using Wordpress 3.0, and I tested this on the twentyten template itself!
Anyone know why?
Thanks,
Amit
Because the front page is loading from front-page.php not index.php.
EDIT
It's loading from page.php. You can read more about the template hierarchy here:
http://codex.wordpress.org/Template_Hierarchy
The is_home() tag actually looks for the page where all your recent posts are shown. If you are on the homepage and you are showing recent posts there, is_home() will return true. And if your front page is set static or template, is_home() will return false but will return true for any inner page where your recent posts are being shown.
The is_front_page()
It returns TRUE when the main blog page is being displayed and the Settings->Reading->Front page displays is set to "Your latest posts",
or when is set to "A static page" and the "Front Page" value is the current Page being displayed.
References
Here's Difference between is_home() and is_front_page()! And a reference to Codex Conditional Tags
Putting <?php wp_reset_query(); ?> before the if(is_front_page() || is_home()){}
worked witht he same issue i was having

Resources