How to name different footer files which can be selected in wp-admin's page editors - wordpress

Seen this done before in other templates, just wondering if anyone here knows how to do this.
I have one template I have created, and two hard coded footer files. footer.php and footer-1.php.
I want to be able to select between using either footer.php or footer-1.php in wp-admin via the pages editor.
So far all I have found so far is adding something like this to the top of the file:
Template Name: footer_1
However, this requires that a secondary header and other files are also included, it won't allow just a change of footer alone.
Can anyone tell me how I can name different footer files so that wordpress detects them in wp-admin and allows me to switch between them.
I do not require adding widgets to these, there is simply two styles of footer and they have no correlation to page or category to hard code, they have to be selected in the admin area manually.

To dynamically change your footer with a admin editor option, do the following:
Open the page you want to customize in editor
Locate Custom Fields meta box in editor (If it is not visible tick the box Custom Fields in the Screen options dropdown at top right)
Select Add Custom Field in Custom Fields meta box
Enter footer_template in Name field and an arbitrary id in the Value field
Select Update to save your settings
Open your theme folder and locate page.php file
Open page.php file and locate the very last line <?php get_footer(); ?>
Delete the line in step 7 and add the following:
<?php
$scriptonomy_footer_meta = get_post_meta(get_the_ID(), 'footer_template', true);
get_footer($scriptonomy_footer_meta); ?>
Save and close page.php file
Make a duplicate of footer.php and name it footer- plus any arbitrary id you chose in step 4, ie: footer-1.php or footer-two.php
Now you can assign any custom footer to any page. You can do the same for the header as well using this technique.

Related

Is there a way to find the theme file in Wordpress using the name?

In the wordpress admin dashboard, on the pages tab, when you edit the page, there's a section called "Page Attributes". One of the options is "Templates", which opens a drop-down list of templates available.
Is it actually possible to find which template name corresponds to which file in the theme editor without looking through every single file in the theme editor?
Shortest way to achieve this is, if you want to get the file name then you can add in the template name directly
<?php /* Template Name: Example Template (example_template.php) */ ?>
So you will see the Example Template (example_template.php) in template dropdown

How to customise HTML structure in Drupal view block

I am currently developing a website in Drupal. I have a load of news articles which are of content type 'news'. I want to create a widget to show at the bottom of several pages listing the latest articles. I have managed to achieve thus far by creating the view with the fields I want and then making the view available as a block.
The problem is the format in which the articles are being listed in the view. Ideally I would like to customise the HTML. I understand that I can create a custom template to target views/blocks but I haven't quite got a full understanding of it yet, and find the Drupal documentation to be quite dry and therefore hard to find what I need from.
Any pointers would be helpful.
Go to your view edit page and select "table" as your view mode.
Go to "Theme information" and look for the desired (style output) template name.
Copy this name and create a new file in your theme folder using this name. I.e.: views-view-table--view-name-block.tpl.php.
In this file you can use the following structure (as an example) to get the values of the fields:
<?php foreach($rows as $row):?>
<div>
<h2><?php print $row['title'];?></h2>
<p><?php print $row['field_custom'];?></p>
</div>
<?php endforeach;?>
Don't forget press rescan theme files after you saved the file in the view theme section.
You can get as specific as you want. Create a block view next to the default or page view and you will see specific file names in the "Theme information" section.

wordpress. error creating content for custom templates with twentytwelve theme

i'm using the twentytwelve theme and i have to write custom content into my example template.
I want to maintain my header content so the main structure is the following
header = id page, wrapper
ex.page = primary, content
footer = close wrapper, close id page
If i have understood correctly, if i want to insert content into the middle of my page i have to do it into my template page (that is a copy of the main page.php), that is in the middle between my header and my footer
For example i want to insert a div into which insert the loop of such category.
The problem is that it displays me nothing, like i've wrote nothing. I can only see the contents if i erase all the originary div, but it's not what i want to do, just because the only div is the page which is my container.
I can't catch what i have to do.
Can you tell me what i forgot to do?
Thanks,
Alex
page.php is a "master" document. header.php, footer.php and (if it exists) sidebar.php are all imported into page.php. Twenty Twelve also uses atomized content templates. You may need to add your div to content-page.php, which is also imported into page.php. content-page.php is used inside the wordpress loop, and encapsulates the code that pulls in the actual article elements from the wordpress database.
If you are trying to add straight HTML to the templates, ensure that you are not adding code between the php brackets:
<?php // don't add html here ?>
<div>do add html here</div>
Depending upon the type of wordpress page you are trying to display, you may need to consult the Wordpress Template hierarchy to determine the proper Wordpress naming convention for your template file (the copy of page.php).
Technically speaking, everything in content-page.php can be put into page.php replacing the get_template_part function. All the 'content' pages are totally not required and can be combined into one file if you want simplicity.
In my opinion, it's easier to start from scratch when learning Wordpress rather than try and re-work something. The default wordpress themes don't lend themselves to be beginner friendly.

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.

Wordpress template question

I set a template and my default template is 2 columns and i have a page that i want to have a 1 column. How can I make that in wordpress? is it a code for the functions.php?
Please suggest and thanks in advance.
You have different options and you could choose the one you prefer :)
If your theme already supports a one-column page you should have on the right side of your edit page screen a box "Page attributes" with a select box named "Templates" when you could choose a different template (in default Wordpress theme "TwentyTen" is it called "One column, no sidebar").
If your theme doesn't support a one-column page you could create a custom page template by yourself:
copy and rename "page.php" that you could find inside your theme
in the top comments add this line: * Template Name: The name you want for your template
at the bottom of page.php remove the line <?php get_sidebar(); ?>
now you should have the new template in the side panel "Page attributes".
If you don't like the "new template + select box" way you could directly add a "IF" on your "page.php" to comment-out the get_sidebar() when needed, based on $post->ID or similar checks.
After this probably you'll have to edit your .css (adjusting width) and new-page.php (like adding a class "one-column" to the div container) to fit the dimensions.
Go to the edit page area of the page you want to have single column. Under templates (in the right hand side bar) look for "single column" or "full width" page.
90% of themes have this. If yours does not, you would have to take page.php, download it. Duplicate it and rename it to fullwidth-page.php and reupload. Make sure the comment area at the top is right according to the "page template codex" in wordpress.org. Then, delete out wehre it calls the sidebar() code. Add a bit more inline CSS to the main content area to make the inline style width the full width then.

Resources