wordpress custom pre-fixed templates - wordpress

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(); ?>

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: Implement basic HTML form functionality to retrieve data and visualize the results

I have experience in HMTL/PHP but I cannot understand how someone could implement this basic functionality in Wordpress. I could not find an article or web page on their website or by searching through the internet.
I want to create a basic html form, pass some data as select queries in a database and visualize back the results paginated.
In traditional PHP we are using "action" in order to send the form data through POST or GET to the action page and then with some PHP code we can fetch the data and visualize it with tables etc.
I cannot understand how to do such a thing in a wordpress page. Where the action parameter should point to? How could I implement this basic functionality in WordPress?
Please could someone help?
This is the mode to develop a separated .php file which uses your wordpress theme and can access to almost all wordpress functions:
<?php include(’wp-blog-header.php’); ?>
<?php get_header(); ?>
<!– Your code here –>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Then you can use all WordPress functions cited here: http://codex.wordpress.org/Function_Reference
You can save this file anywhere, but be sure to insert correct path to wp-blog-header and there must not be any prohibiting .htaccess
This is the way to insert php code into a wordpress post:
You have to use this plugin http://wordpress.org/plugins/allow-php-in-posts-and-pages/
Then create a post and use [php] [/php] to insert your php code and open it. Look at the address bar. This it the URL to access this post. Use it as action parameter in your form. Then control $_REQUEST[] in your php code to extract parameters received from your form.
Now you can control this post as any other normal wordpress post from the wordpress admin panel.
You need to create custom wordpress templates for pages in your theme. Here i use templates
1.form-page.php --- with template name "Form-page-template" and
2.form-page-action.php ---with template name "Form-page-action-template"
form-page.php
<?php
/*
Template Name: Form-page-template
*/
?>
<?php get_header(); ?>
<form method="post" action="http://yourdomain.com/form-page-action/" name="input-form"/>
<!-- form contents -->
</form>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You just save this template inside your theme : location => like wp-contents/themes/your-theme/form-page.php . and this will add Form-page-template in your theme .Now create a page inside from wordpress dashboard through pages->addnew ,here i give page name "form-page" and select template for page from right pannel,here we need to select "Form-page-template" that we created early.
Now we have the page url :: http://yourdomain.com/form-page/ where we can see our form,now create form-action-page.
2.form-page-action.php
<?php
/*
Template Name: Form-page-action-template
*/
?>
<?php get_header(); ?>
<!-- Your action page contents goes here -->
<?php
//getting input etc.. you need to do
$input = $post['input'];
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Now you need to save this template inside your theme as above, Create a new page for this template as said above here i creating a page "form-page-action" with template "Form-page-action-template" so here i get a page url for our
action page like :: http://yourdomain.com/form-page-action/ , and you need to use this url as the action url in your form page.and this way you can add your form action page inside wordpress theme.
You can edit the contents of these page inside from wordpress like=> Appreance -> Editor , select the templates to edit.

How do I create different editable sections within a WordPress page?

I have been building my first theme on WordPress and have run into problem while adding content into different sections.
My HTML is somewhat like this,
<div id="maintext">
<-- Text -->
</div>
<div id="products">
<-- Text and Images -->
</div>
<div id="about_company">
<-- Text boxes -->
</div>
How do I make sure the content added via the WordPress editor falls under the respective divs ? For the "maintext" div I'll load the content from the page itself but how do I add content to the other 2 divs dynamically ?
I searched on a couple of forums and many suggested to add content using widgets, is there any way it can be done without using widgets ?
Any help will be gladly appreciated.
Unfortunately adding multiple editable fields in a single page is not particularly easy using WordPress by itself.
Many WP devs I know (myself included) rely on the Advanced Custom Fields Plugin for additional content fields.
The steps to make this happen:
1) Install the ACF the plug.
2) In the settings area for ACF create some new fields.
3) Assign the new fields to appear for a specific page or set of pages.
4) Update your page-template for the given page(s) so that the new fields are displayed.
For instance you might create a set of standard wysiwyg fields and then assign them to the 'overview' page. Let's call these fields: main_text, products_info and about_company. Once the fields have been created and assigned to a page, when you edit that page the additional fields will be available to edit.
For these new fields to be seen by visitors, they must be added to the page-template you use for your overview page. The code could be something like this:
<div id="maintext">
<!-- Text -->
<?php if(get_field('main_text')){ //if the field is not empty
echo '<p>' . get_field('main_text') . '</p>'; //display it
} ?>
</div>
<div id="products">
<!-- Text and Images -->
<?php if(get_field('products_info')){ //if the field is not empty
echo '<p>' . get_field('products_info') . '</p>'; //display it
} ?>
</div>
<div id="about_company">
<!-- Text boxes -->
<?php if(get_field('about_company')){ //if the field is not empty
echo '<p>' . get_field('about_company') . '</p>'; //display it
} ?>
</div>
There are lots of good examples here. If you are feeling really ambitious, rather than install the plugin you could even include ACF directly in your theme.
You've got three options I believe:
Create a widget area where you can then display the content in a text widget: http://codex.wordpress.org/Function_Reference/register_sidebar
Create a template where you then get the content of a different page: http://codex.wordpress.org/Page_Templates#File_Folders
Create a new meta box for all your pages: http://codex.wordpress.org/Function_Reference/add_meta_box
I believe that the thing you are looking for is option 2. The others are more full-site oriented, if you want the extra content to show up on every single page.
If you are writing the theme, maybe you would like to consider using a WordPress Framework so you don't have to start from scratch.
If that is not the case, think of the end user. How will they add sections to pages and posts? Will they have to move across places within the WordPress UI, or would they rather user short codes?
My recommendation is to build a plugin that render the section within the document content. Or widget content if that is the case.
I wrote a little piece of code to illustrate how you can accomplish such a thing, and also because I kind of need it right now :D. You can find it on github here https://github.com/lionpage/Front-Office-Document-Sections
Hope this helps
<div id="maintext">
<?php the_content(); ?>
</div>
<div id="products">
<?php // echo wp function to get product data; ?>
</div>
<div id="about_company">
<?php // echo wp function to get about companydata; ?>
</div>
I've run into this issue several times now, and while the question is 3 years old, I think it's still rather current. I've succesfully used the Multiple Content Blocks plugin sometimes now:
https://ltz.wordpress.org/plugins/multiple-content-blocks/
After installing the plugin, you can just include the_block in your template:
<div id="maintext">
<?php the_content(); ?>
</div>
<div id="products">
<?php the_block('products') ?>
</div>
<div id="about_company">
<?php the_block('company') ?>
</div>
hi im currently developing a theme with that set up.
there are two ways to achieve this:
widgetized and fixed admin panel (customizer options)
i am using the two in my themes
if widgets
create a .php file that includes the widgets sections
create a widget for that section
if fixed in admin panel
you have to include the .php section in your functions.php
edit * advantage of widgetized is you can arrange them just like in a regular sidebar
Was struggling with this, and did not want to use a plugin. The only WordPress native option I found was to use Custom Fields. This works, but only for text, and is rather cumbersome.
The other non-plugin option is to simply use HTML in the WordPress editor, but this is of course far from ideal either.
Finally I gave up, and opted for the Advanced Custom Fields plugin as well.

Wordpress ignoring page template from drop down

I am struggling with something that appears to be easy, page templates. I have read plently posts on this, people seem to forget to put the comment at the top of the page and can't get it to show up in the drop down menu on pages. I can do this, my problem is the next stage.
I have written the most basic template (custom-page.php):
<?php
/*
Template Name: Test template
*/
?>
<?php get_header(); ?>
<h1>Teams!</h1>
<?php get_footer(); ?>
It shows up and I can select it on the new page sidebar. However when I visit that new page it seems to have defaulted the archive page using the content template include.
Thanks in advance.
If you put the following in your footer, you should be able to grok some further information about how your template is being selected (and know exactly what might be happening).
<?php global $template;
echo(basename($template)); ?>
Then look for the template name in your footer. It's possible (like #adomnom said) that you have a slug conflict. There are a handful of other strange scenarios that could be caused by plugins, custom functions, or other factors as well.
By the sounds of things, it could be conflicting with another template.
For example, if your page has the slug 'category' and is set to use the custom template 'custom-template.php', it would conflict with (and be overridden by) category.php, which is the default template for showing posts for a specific category.
I recommend changing the slug to see if that's the problem.

Wordpress : Multiple Columns on Homepage

I am trying to create a Wordpress site. The design is Here
I have created most of the outline of the site, barring the 3 regions "Follow Us", "Self Employment" & "Into Work Consortium".
The client has told me he would like to make those 3 regions editable.
My template contains an Index file, Header & Footer File as well as the obvious CSS files.
I am using the "Multi Edit Plugin" Multi Edit Plugin but that guide, does it so that you create a CustomPage. I guess I could do that but what I want is my index.php file to be added to the admin side of the site and then point the template there or similar.
As it's getting a little frustrating working with multiple WP plugins that just don't seem to do the job correctly.
There are many ways to go about this: one being what was mentioned by Pekka and the other using Custom Page templates.
The above mentioned methods are, in theory, quite similar with subtle differences in terms of execution and inclusion.
Perhaps to better answer your question, I will provide a very brief sample outline below on Custom Post Templates. You may probably need to do a little more digging at Wordpress' Codex if you choose to further enhance anything else:
Custom Post Template Method
Referring to the wireframe provided in your image link, I propose that you use category filters to filter the associated posts to the right columns. So first up, you will need to create 4 categories for the method that I'm suggesting, namely: WELCOME, FOLLOW, SELF-EMPLOYMENT and CONSORTIUM.
After doing so, your index.php should look something like this:
INDEX.PHP
<?php get_header();?>
<!--container-->
<div id="container">
<?php query_posts('category_name=welcome&showposts=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<!--top-content-->
<div class="top-content">
<h2><?php the_title();?></h2>
<p><?php the_content();?></p>
</div>
<!--top-content-->
<?php endwhile;?>
<!--bottom-content-->
<div class="bottom-content">
<!--follow-->
<div class="follow">
<?php include(TEMPLATEPATH . '/follow.php');?>
</div>
<!--follow-->
<!--self-employment-->
<div class="self-employment">
<?php include(TEMPLATEPATH . '/self-employment.php');?>
</div>
<!--self-employment-->
<!--consortium-->
<div class="consortium">
<?php include(TEMPLATEPATH . '/consortium.php');?>
</div>
<!--consortium-->
</div>
<!--bottom-content-->
</div>
<!--container-->
<?php get_footer();?>
What is happening here is that I'm doing a post query for posts tagged to the category "WELCOME" and filter the posts into the top-content DIV. Note that my loop starts right before of the top-content DIV and ends immediately after it. This will means that the loop will only affect that particular DIV. I have also set the post limit to "1", thereby restricting the display of posts to just the latest post.
Following on from there, you will notice that in the bottom-content DIV, I have included 3 different files for each column. These 3 files will be your custom post templates that you will need to create and have a post query to filter in the right post. An example of the custom post template will look something like this below:
FOLLOW.PHP
<?php query_posts('category_name=follow&showposts=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<h2><?php the_title();?></h2>
<?php the_post_thumbnail('bottom-content-thumb');?> <!--you will have to enable featured image thumbs in your functions.php file before you can do this-->
<span class="read-more">Continue Reading</span> <!--there are other ways to do the read more link, but I'm just giving an example now so yeah-->
<?php endwhile;?>
The rest of the custom post templates for the bottom 3 columns should look something like the above. If there is any variation of style and all, you will probably have to shift things around and play around with the CSS.
I want to stress that this is not the one and only way to do what you hope to achieve, but rather, that it is one of the many. What I've suggested is only an example that hopes to provide some insights on how you can utilize Custom Post templates for developing Wordpress based sites.
My advice at the end of the day is to delve deeper into Codex and find out more about Custom Post/Page templates because eventually, they will come in very handy if you choose to make custom Wordpress templates.
Hope my post had made things a little clearer for you =)

Resources