wordpress custom page template based on a specific <div> - wordpress

I want to know how to set up a custom page template. My website is based on many different widths. example for some pages I use a div called <div class="content-wrap ninecol clearfix"> but for another page I use <div class="text-centered twelvecol clearfix">.
I need to create a template so that I can easy create new pages based on those templates.
Below is my static html code that Ive done in dreamweaver.
<div class="content-wrap ninecol clearfix"> <!--I want to make a template based on this div so I can just add new text in the future-->
<div class="content">
<h1 class="title">Om oss</h1>
<hr>
<div class="entry-content">
<h4>Vilka är Unified Sweden?</h4>
<p>Vi värnar starkt om vår unika företagskultur och ser den som vårt kraftfullaste
konkurrensmedel. Inom företaget har vi alltid arbetat hårt för att skapa den
stabila grund som vår företagskultur är byggd på. </p>
<p>All personal på Unified Sweden har många års erfarenhet av webbutveckling,
programmering, design och kundservice vilket gör oss unika då alla led inom kundbemötandet
vet exakt vad ni som företag behöver hjälp med.</p>
</div>
</div>
</div>
and this is what I came up with.
<?php
/*
Template Name: Test
*/
?>
<?php get_header(temp); ?>
<?php
// get_template_part( 'loop', 'index' );
?>
<div class="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div><!-- content-wrap -->
</div><!-- #content -->
</div>
</div><!-- .main -->
<?php get_footer(); ?>
Thank you for any kind of help or support.

Are you saying that for each template you want a different style? If yes you need to give different name at div id and then you should edit your style.css
#namediv{ }

to setup custom page template (if i understand your question correctly)
you create your page template in the theme directory which is active
and use the header the way you did
<?php
/*
Template Name: Test
*/
?>
you replace Test by whatever you want to use for the name (this name can have space)
then in the admin, you can select the template to use for the page by going to Admin > Page Attributes > Templates
Your new custom template should appear here
edit (following op comment)
then you could check which template is being use with
is_page_template()
http://codex.wordpress.org/Function_Reference/is_page_template
from within the header.php that would then load a specific css file
side note: you might also want to check the codex page: http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates as well as the dedicated wordpress stackexchange https://wordpress.stackexchange.com/

Template Name : Your page name
*/
you replace Test by whatever you want to use for the name (this name can have space) then in the admin, you can select the template to use for the page by going to Admin > Page Attributes > Templates Your new custom template should appear here

Related

template management with wordpress (underscore boilerplate)

I am using underscore to develop a wordpress theme.
I have a custom post type name project, thus I have, for instance, this url: http://a.site.local/projects/a-beauty/.
I have in my template-parts/ directory the file content-projects.
$ cat template-parts/content-projects.php
<h1>Project</h1>
When I browse http://a.site.local/projects/a-beauty/, I have my title but also the sidebar and the footer (even if they do not appear in my content-project.php nor in index.php).
Where are those widgets coming from / loaded ?
Add conditions to the header, footer and sidebar.
For whole custom post archive:
<?php if( !is_post_type_archive( 'project' ) ) : ?>
// wrap the code you don't want to show on that archive
<?php endif; ?>
For custom post only:
<?php if( !is_singular( 'project' ) ) : ?>
// wrap the code you don't want to show on the post
<?php endif; ?>
If you want to put the code you WANT to show, remove the '!' before condition.
P.S.
You can put the whole content in a condition, but keep the
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
otherwise the page will break :)
Please share some more code from your project so we can easy to understand the real problem.

Bootstrap collapse stops working when switching field type to WYSIWYG

I'm creating a FAQ page on my wordpress site. I am using bootstrap 4.0's collapse component and ACF Pro to build the page.
On the back end, an admin can add questions and answers. The answers are to be hidden on the front end until a user clicks on the question to toggle the answer. Originally the answer field was a text area. All was working great! But when I changed the answer field type to be a WYSIWYG editor, the collapse functionality stopped working altoghether and the answers are not hidden or collapsible. Does anyone know how to solve this issue?
Thanks in advance, code snippet below.
<?php while( have_rows('topic_information') ): the_row();
$question = get_sub_field('question');
$answer = get_sub_field('answer');
$counter++;
?>
<div class="question-btn collapsed" data-toggle="collapse" data-target="#<?php echo $counter; ?>" aria-expanded="false" aria-controls="<?php echo $counter; ?>">
<div class="question">
<p class="question-text">
<?php echo $question; ?>
</p>
<div class="toggle-status"></div>
</div>
<div class="answer">
<p id="<?php echo $counter; ?>" class="collapse" aria-labelledby="headingOne" data-parent="#accordion"><?php echo $answer; ?>
</p>
</div> <!--.answer-->
</div> <!--.question-btn-->
<?php endwhile; ?> <!-- WHILE ( have_rows('topic_information') -->
I've experienced this with bootstrap when the bootstrap.js, bootstrapcdn or bootstrap.min.js is referenced more than once on a page. For me the plugin I was using was also importing or referencing its own bootstrap.js or bootstrap.min.js file which it why it was happening to me.
I would try removing the bootstrap.js or bootstrap.min.js reference from the ACF Pro plugin if possible or try removing it from your project (since your plugin is already referencing it) to see if works.
If that doesn't work you might want to try doing it from javascript since it sounds like the faq is dynamically generated:
bootstrap collapse not working when creating dyanmically
Good luck

wordpress apply_filter values are not coming inline

I am using follwing code in my wordpress custom theme template
<p id="news"> <?php echo apply_filters('the_content',$myNews)?></p>;
And the desired output should be like this
<p id="news"> Herer goes my news content from $myNewsvariable </p>
But i am getting output like this
<p id="news"></p>Here goes my news content from $myNewsvariable
Please tell me how i can fix this
the_content function prints out content by default. So there is no need to do a duplicate echo before apply_filters.
Also you can apply your filter to get_the_content:
<?php echo apply_filters('get_the_content', $myNews); ?>

Drupal search block customizing

I have my block template block.tpl.php
<div class="block">
<?php print $content ?>
</div>
And I want to change block wrapper for search form
<div class="block search">
<?php print $content ?>
</div>
I'm trying to use block-search.tpl.php but it doesn't work
There is a feature in Drupal - you can override specific template(block-search.tpl.php) in theme when you override general template(block.tpl.php).
Other thing is that probably your cache is not cleared - try
And here you have some nice description how to check other things that could failed.

Adding a static text on top of view when it is not filtered

I want to add a static text (some sort of explanation/welcome text) on the very top of a view (over the filter) in Drupal 6.x with Views "2". I want this text appear only when the view is not filtered (i.e. on initial load of the page).
My problem is that the only place I figure out to make it work partially is in the views-exposed-form--MYVIEW.tpl.php. The problem is that when I place the code in this template, I don't know if the view is filtered or not, so the text appear on every single page! I don't have access to this info in that template so the only place this is available ($rows or $empty variables for example) is in views-view--MYVIEW.tpl.php.
But there I got an another problem. The order in witch it seams the variables are output are not the same as the order in witch they appeared in the file. For example, the $exposed variable content is render always on top, then $admin_links, $header and so forth.
<?php if ($header): ?>
<div class="view-header">
<?php print $header; ?>
</div>
<?php endif; ?>
<?php if (!$rows): ?>
<h3>This static text appear AFTER $exposed !!!</h3>
<?php endif; ?>
<?php if ($exposed): ?>
<div class="view-filters">
<?php print $exposed; ?>
</div>
<?php endif; ?>
<?php if ($attachment_before): ?>
<div class="attachment attachment-before">
<?php print $attachment_before; ?>
</div>
<?php endif; ?>
So even if I place my static content before this code, the filter form always appear on top!
I found the reason why is doing this: the exposed filter form is rendered as a part of the content-top <div></div>, but not the result (and $header, $footer, etc).
So is this by design? Do I miss something? How can I get my static text on the very top of the content-top!?
Well, after some tweaking and lecture on preprocess function in the theming system, I found a solution to my problem. I share it with you and if you find a more elegante approach; let me know!
What I did is this...
1) In the template.php file of the theme, I add two fonctions:
function YOURTHEME_preprocess_views_view__MYVIEW(&$variables) {
if ($variables['rows'] || $variables['empty']) {
$GLOBALS['dont_show_static_text'] = TRUE;
}
}
function YOURTHEME_preprocess_views_exposed_form__MYVIEW(&$variables) {
if ($GLOBALS['dont_show_static_text']) {
$variables['custom_flag1'] = TRUE;
}
}
So, if my views is showing some results ($row) or a blank result ($empty), then I set a flag to be use in the template file....
2) In my views-exposed-form--MYVIEW.tpl.php
...
<?php if (!$custom_flag1): ?>
<h2>Some static text here</h2>
<?php endif; ?>
...
And voilà! My static text is showing up only on the initial load of the view and it shows on TOP of the filter (not under!).
Hope this help someone else!

Resources