Drupal front page - two columns for most recent news - drupal

I have graphical project of three-column Drupal front page which has first column for one piece of custom content and two other colums designed for most recent news (one content type) as it is shown on image below:
I am quite new to Drupal and so far I created my own page.front.tpl.php in my PHPTemplate theme with regions like header, footer, menu, search_box etc and content of course. Now I have problem with $content region, in which there should be columns as I described above. My question is: How do I style them (CSS? somewhere in Drupal's admin? use separate blocks? Some module?) to look like in project?
page.front.tpl.php fragment:
<?php if ($content): ?><div class="content-middle"><?php print $content; ?></div><?php endif; ?>
Output simplified HTML structure (so far only two most recent news), I want to style this somehow:
<div class="content-middle">
<div class="node">
<h2 class="title">
<div class="content">
<div class="node">
<h2 class="title">
<div class="content">

You can create 3 new sections in your theme. Modify your .info file (for example MyThemeName.info) and write the following :
regions[content_center_left] = Left Sidebar
regions[content_center_middle] = Middle Sidebar
regions[content_center_right] = Right Sidebar
The next step is to modify your page.tpl.php or if you want these sections to be available only in front page you can modify page-front.tpl.php. Write the following where you want the sections to be displayed:
<?php if ($content_center_left): ?>
<div class="content-left">
<?php print $content_center_left?>
</div><!-- /content_center_left -->
<?php endif; ?>
<?php if ($content_center_middle): ?>
<div class="content-middle">
<?php print $content_center_middle?>
</div><!-- /content_center_middle -->
<?php endif; ?>
<?php if ($content_center_right): ?>
<div class="content-right">
<?php print $content_center_right?>
</div><!-- /content_center_right -->
<?php endif; ?>
Now you can create your views (as blocks) and display them in these sections.

I recommend using the Panels module.
From the project page:
The Panels module allows a site administrator to create customized
layouts for multiple uses. At its core it is a drag and drop content
manager that lets you visually design a layout and place content
within that layout. Integration with other systems allows you to
create nodes that use this, landing pages that use this, and even
override system pages such as taxonomy and the node page so that you
can customize the layout of your site with very fine grained
permissions.

Agreed with Laxman 13 , Panels is definitely the way to go, you could double it with the Views module , which would allow you to retrieve the most recent news or whatever query you may have for you content display.

Related

Include Advanced Custom Fields (ACF) in Wordpress the_content()

I've inherited a project structure that uses front-page.php to render the home page. Most of the site uses the Wordpress content field, but we've switched to building new features with Advanced Custom Fields. the_content() is used throughout the codebase to render content, and I'm wondering if there is a way to include ACF layouts in the_content().
An example workaround I've had to use for the homepage is below, if I don't call the layout in this way content won't render on the page. I'm new to ACF, so if what I'm describing is a fundamental misunderstanding of how to bring ACF into an ecosystem I'd appreciate any guidance on better file structures and calling content.
<?php get_header(); ?>
<?php
if (is_page('Home')) {
?>
<div class="container">
<div class="row">
<?php
get_template_part('/layouts/home');
?>
</div>
</div>
<?php
} else {
the_content();
}
?>
<?php get_footer(); ?>
You can use ACF in addition to the original "the_content()" or "get_the_content()" functions. That content comes from the default block or WYSIWYG editor. ACF comes from additional fields that you add to your pages or posts.
<?php get_header(); ?>
<?php
if (is_page('Home')) {
$home_acf_field = get_field('field_name_from_home_acf');//this assumes that the ACF field has been added to the home page, because I'm not using the second parameter
?>
<div class="container">
<div class="row">
<?php
get_template_part('/layouts/home');
echo $home_acf_field;//this could also be placed in "layouts/home"
?>
</div>
</div>
<?php
} else {
$acf_field_from_page = get_field('field_name_from_page_acf');
the_content();
echo '<div>'.$acf_field_from_page.'</div>';//an example of where this can go
}
?>
<?php get_footer(); ?>
You can incorporate ACF in the template part, or in the page itself. You need to have the ACF field set up in the CMS to be on home or wherever, but then it's as simple as what I showed you to pull it in (my examples were assuming text fields).
You aren't asking this question, but if you are using "front-page.php" as your home page, then why do you need the if statements to show content? You can use "the_content()" in addition to your ACF fields, especially if it's the content editor from the home page. Or, you can just hide it (it's an ACF setting).
Note: I wrote this from memory, and didn't test anything, so please excuse any potential typo. :)

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.

create a different index.php for post in wordpress

I'm working on a wordpress that has, among other things, a Front Page and a Post Page for showing news.
From what I understand, the template that the Post Page uses, is the index.php, but the index.php is also used by other pages.
The thing is that I want to create a special page for post, with a header that says news, etc., but I don't want other pages to use that template.
Is there a way to create an alternative index.php (index_news.php) that is only used to show posts?
That way I can use index_news.php for the post and index.php for everything else.
Thanks
EDIT //////////
My first option was to create a new page-template (news.php) with the loop inside, and then, in the the wordpress options, targeted the post to that new page (news.php).
But when I do that, it loads the index.php not the news.php template. Maybe is something wrong with the loop. Here is the loop I'm using:
<!-- Start the Loop. -->
<div class="post">
<!-- Display the Title as a link to the Post's permalink. -->
<h2><?php the_title(); ?></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<!-- Display the Post's content in a div box. -->
<div class="entry">
<?php the_content(); ?>
</div>
<!-- Display a comma separated list of the Post's Categories. -->
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</div> <!-- closes the first div box -->
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else: ?>
<!-- The very first "if" tested to see if there were any Posts to -->
<!-- display. This "else" part tells what do if there weren't any. -->
<p>Sorry, no posts matched your criteria.</p>
<!-- REALLY stop The Loop. -->
single.php - is for one post view, but if You wolud like to modify blog index, than you could also create a custom template (page-news.php) with a header that allows it to be separated as page template:
<?php
/*
* Template Name: News Page
* #package WordPress
*/
?>
and then use loop inside of it.
But for this case what I think is even better, You can modify header.php and use wordpress conditional tags such as:
is_front_page(), is_page() or any that will work for You: http://codex.wordpress.org/Conditional_Tags
There are many ways to do same ;).

Wordpress - Post Page Associator Issues

For a client site that I am working on, the client wants to be able to associate certain custom post types to a given page. my supervisor has pointed me to the website of a previous client that did something similar. They used the Post Page Associator plugin (which seems to have been removed from the plugins list).
Here is a link to the plugin I am using: http://www.mediafire.com/?2dpbxac73rsn8l6
I've tried my best to modify the code inside the plugin to handle the custom post types I wanted to use (which the changes are included in the download). The main conflict comes from this piece of code (from the previous client's page.php file)
<?php
$sidebar = new WP_Query( $args ); //queries for posts
$sidebar = wp_plugin_post_page_associator::get_associated_posts ($post->ID); //looks for associated posts via the plugin, the main offending line of code
if ($sidebar!="") : while ( $sidebar->have_posts() ) : $sidebar->the_post();
?>
<div id="sidebar-content"> <!-- sidebar area -->
<h1 class="blue-text"><?php the_title(); ?></h1> <!-- the title of the associated post -->
<div class="divider"></div>
<?php the_content(); ?> <!-- the content of the associated post-->
<br/><br/>
</div>
<?php endwhile; else:?>
<br/><br/>
<?php endif; ?>
I was wondering if there was a way to determine what kind of post type the associated content is so I can change the WP_Query settings accordingly. If I comment out the second line of code with $sidebar, then all posts gets displayed in the sidebar. Is there a solution to this problem, or is there a better plugin for this?
I found a replacement plugin that does exactly what I need and shows me how to do it: http://www.cssigniter.com/ignite/custom-post-types-relationships/

Same editable region/content same on all pages

I'm working on this website in WordPress and I want the content with the title "Featured Business" that's on the sidebar to appear on all pages. I created a template for it but it doesn't display when called. The code is as shown below.
<div id="ftb">
The content
</div>
<!-- End FTP -->
and I called it with <?php get_ftb(); ?> But it doesn't show.
If you want to display a chunk of html that's part of the sidebar (but not the entire sidebar), I recommend to place it on functions.php, like this:
<?php
function get_ftb() {
?>
<div id="ftb">
The content
</div>
<!-- End FTP -->
<?php } ?>
After that you'll be free to call it with get_ftb();
If you just need to call the entire sidebar, use get_sidebar() instead.

Resources