External sidebars in WordPress - wordpress

I need to display several sidebars with custom context.
I suppose that I need to add several additional blogs to be displayed as sidebars. That is for every sidebar I am going to create a little specialized blog.
The question: How to make sidebars from a different blog to be displayed in a blog sidebar?

If you want to add more than one sidebar, you need to create sidebar for each blog and name it. E.g., want to create sidebar for aboutus.php (created as template page). Create sidebar as sidebar_aboutus.php and add what you want in sidebar to it.
Then include that sidebar_aboutus.php in your aboutus.php like this:
<?php
/**
* Template Name: About us
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<?php get_header(); ?>
<?php include ('sidebar_aboutus.php'); ?>
<?php get_footer(); ?>
Likewise, you can create and include as many sidebars as you need for your different blog pages.

Related

Convert one page website to multiple wordpress pages

I have a working one page website I like to convert into multiple pages in wordpress.
I already successfully created a theme, converted the header, footer, css, js into wordpress, header.php, footer.php, and functions.php by following a tutorial.
Now I'm left with all my html content between the header and footer and want to cut that content up into multiple wordpress pages.
I can do "the_title(); wrapped in php" and make the content while loop to get the first page into a wordpress page, but from then I dont know what to do, to split the next lines of html into other wordpress pages.
You will need create some page templates for your theme. They will look something like this:
page-about.php
<?php
/* Template Name: About Page */
get_header(); ?>
... about page content
<?php get_footer(); ?>
page-contact.php
<?php
/* Template Name: Contact Page */
get_header(); ?>
... contact page content
<?php get_footer(); ?>
Then assign the template in the Wordpress admin, on Edit Page view to the corresponding templates you want to use. You select the template by the name you give it in the comments.
The actual file name of your templates matter. Some views in wordpress are assigned to templates simply by the name of the file. So you will want to use certain naming conventions like page-about.php. More info about templates: https://developer.wordpress.org/themes/basics/template-hierarchy/

wordpress custom pre-fixed templates

I want to create a page template that has a pre-fixed css. Lets say I name it page-sevencol.php then I know that the content will have a fixed width and a specific style and so on. My pages have different layouts thats why I need to create these kind of templates.
Is it possible? if so how? Ive looked in the wp codex and it does not seem to have the answer. Please take a minute to help me.
Thank you!
you seem to need just a limited set of templates. The question is: do you want to apply them automatically? Basically, there are two techniques to apply a template to a page (or post or custom post, etc.) in WordPress.
First method: using the template naming convention to get the template automatically applied to a page (or post) with the same name.
In this case, you create a page page-mynewpage.php and this template will automatically get applied to your page named /mynewpage/.
Second method: you create a template by creating a page (let's say : template1.php) and declaring it as a template with a comment at the top of the page:
/**
* Template Name: Template1
*
*/
This template will now be selectable inside the admin of WordPress to be applied to any page:
So if A) you only need a limited set of templates & B) are ok to select them on a per-page basis in the admin, this is your solution. You would just need to create as many pages as you need templates, not forgetting to include the comments that declare them as templates and using a different name each time.
If you need your templates to be applied dynamically, then we need more info about the logic to use for select each template...
EDIT : That is it, Abel (just read your comment). Your page is mainly generated with 4 elements: header.php, sidebar.php, footer.php and another page to produce the content, but this page is different depending on where you are in the site. If you are on a page, it will be, by default, page.php. If you are reading a post, WordPress will by default use single.php.
To apply all your different templates, just go and open page.php in your theme folder. Save it under another name, like page-template7cols.php. Insert a comment like I just explained above, so this template will show in your admin next time you create a new page. Adapt it the way you want (changing the HTML / PHP and therefore adapting the way the content of the page will be displayed). Do the same for your other 9 templates.
Then, everytime you create a new page, just start by selecting the proper template in your dropdown (see previous screen capture). And whenever you will make a change to page-template7cols.php, for example, the changes will be reflected on all pages for which you have selected this template.
/**
Template Name: Template1
*/
<?php get_header(); ?>
<div class="content-wrap sevencol clearfix">
<div class="row clearfix">
<div class="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

How to display a different sidebar for all blog posts and on the page where the blogs are listing?

I have a WordPress site which have 4 pages with one page is a blog page.
I have created a page template for the blog page to display all blogs on this page.
On this page template I am displaying the different sidebar from the other pages.
This sidebar displaying the blog archives.
But when I click on an archive the sidebar changes to the that first sidebar which is also on another pages.
How will I remain this second sidebar to be display on every blog post?
In case of custom pages, for example, we are having aboutus.php having body contents like this:
<?php
/**
* Template Name: About us
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<?php get_header(); ?>
//body content for aboutus page
<?php include ('aboutus_sidebar.php'); ?>//separate sidebar for aboutus
<?php get_footer(); ?>
Then, create a file named aboutus_sidebar.php with whatever you want.

How to remove sidebar from certain pages and adjust post width div?

I'm trying to remove the sidebar from certain pages and once it is removed the width of the post div readjusts. How to do this?
For pages you can create different template and use it with a specific pages. For posts you can use a custom field to mark pages that requires no sidebar, then read this custom field in your single.php and make corresponding layout adjustments. Hope you know how to do it.
You can use the simple PHP script in page.php to remove the sidebar from specific page.. Here is the PHP script-
<?php if (is_page('your_page_name')) { ?>
<? } else { ?>
<?php get_sidebar(); ?>
<? } ?>
Here is the complete tutorial on removing the wordpress sidebar from specific page http://masterblogster.com/how-to-hide-sidebar-on-particular-page-in-wordpress/

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.

Resources