I'm working on a custom template part that includes an h2 with the classes "sectionmarker" and "bodycontent", like this:
<h2 class="sectionmarker bodycontent">Title</h2>
When I call get_template_part() on a page, the output I'm getting is:
<h2 class="bodycontent">Title</h2>
For some reason, it seems not to like "sectionmarker". I even switched the order of the two classes, like this:
<h2 class="bodycontent sectionmarker">Title</h2>
And I get the same output with only the bodycontent class applied. What's going on here?
Full template content:
<?php
$abstract=get_post_field('post_content',224);
$news=get_posts(array(
'post_type'=> 'news'
));
$newsdata=array();
foreach ($news as $n) {
$item=new stdClass();
$item->title=get_the_title($n->ID);
$item->date=get_the_date("",$n->ID);
$item->content=get_field('more_info',$n->ID);
array_push($newsdata,$item);
}
$newsdata_json=json_encode($newsdata);
?>
<script type="text/javascript">
console.log(<?php echo $newsdata_json ?>);
</script>
<?php
echo $abstract;
if(count($newsdata)>0){
?>
<h2 class="sectionmarker bodycontent" >News</h2>
<?php foreach ($newsdata as $newsitem) { ?>
<h4 class='datemarker bodycontent'><?php echo $newsitem->date ?></h4>
<p class='newstext bodycontent'><?php echo $newsitem->title ?></p>
<?php } } ?>
and here's the call I'm making (in home.php):
get_template_part('custom-home-template',null,array());
Nevermind! I just remembered I have some JavaScript that's changing the h2 classes on load.
Related
Maybe it's duplicate but I don't know how it calls and cannot find. I need to load a php-file (template of my block) and set content into it.
For example, template file:
<?php include_once 'boot.inc' ?>
<div class="widget">
<div class="widget-title">I need to put title here</div>
<div class="widget-body">I need to put content here</div>
</div>
And php function to insert new block with this template:
function nm_new_block($title, $content) {};
Can I do it in php?
1° Solution: You need to change you code into:
<?php include_once 'boot.inc' ?>
<?php include_once 'template.php' ?>
<div class="widget">
<div class="widget-title"><?php echo $title; ?></div>
<div class="widget-body"><?php echo $content; ?></div>
</div>
In template.php file you must have something like this:
<?php
$title="My Title";
$content="My Content";
?>
And you don't need function for this cause variables are stored in template.php
2° Solution: You need to implement a function to retrieve variables from external source:
<?php include_once 'boot.inc' ?>
<?php include 'functions.php' ?>
<div class="widget">
<div class="widget-title"><?php echoTitle(); ?></div>
<div class="widget-body"><?php echoContent(); ?></div>
</div>
In functions.php
<?php
function echoTitle(){
$title = 'Add code to get title here';
echo $title;
}
function echoContent(){
$content = 'Add code to get content here';
echo $content;
}
Replace Add code to get title here and Add code to get content here with code to get contents ex:
$title = $_POST['title']; supposing you want get title by a submission form
I do not have enough details to tell you more.
I have an opencart category page that I am trying to hide the title DIV for. Out of all the categories and sub cats there is (for now) only one that I am trying to hide.
The following code I have used does not work:
<?php if ($categories && $heading_title!="HEADING TITLE HERE") { ?>
<?php elseif : ?>
<div id="headerhide" style="width:800px;">
<h1><?php echo $heading_title; ?></h1>
</div>
<?php } ?>
<?php endif ?>
<?php if ($categories && $heading_title!="HEADING TITLE HERE") { ?>
<?php }
else {
?>
<div id="headerhide" style="width:800px;">
<h1><?php echo $heading_title; ?></h1>
</div>
<?php } ?>
<?php if ($categories && $heading_title!="HEADING TITLE HERE") { } else { ?>
<div id="headerhide" style="width:800px;">
<h1><?=$heading_title?></h1>
</div>
<?php } ?>
I have this setup on my OpenCart information.tpl page:
<?
// If FAQs page or content show AJAX
// We check for case sensitive titles - the title is case sensitive
if($heading_title=="FAQs" || $heading_title=="Faqs") { ?>
<script type="text/javascript">
$(document).ready(function(){
// ETC
});
</script>
<?
// Not the FAQs page so do nothing
}
?>
I've recently made a commercial vQmod that will be of use to you for this. It's called Custom Templates and will allow you to assign it to as many individual category pages as you want. It works for more than just categories too (manufacturer, product and info pages). While it may be a bit overkill for one page, if you plan on using it for multiple pages in the future it will be better in the long run in my opinion
I have a main view with a menu which helps me display another view. It's similar to this:
<div id="page">
<div id="menu">
Page1
Page2
</div>
<div id="content">
<!-- Page1 or Page2 are displayed here -->
</div>
</div>
I'm using php's Yii framework. Which makes me not to use <?php include("menuview.php"); ?>. So I'm looking for a different solution. I can do this with Ajax, but I would also like the link to change to mypage/controller/Page2. With Ajax I can only get it to this: mypage/controller/index#Page2
in main view, instead of include do
<?php echo $this->renderPartial('_page1', array('model'=>$model)); ?>
UPDATE:
protected/views/controller/page1.php and protected/views/controller/page2.php content at your liking
protected/views/layouts/custom.php:
<?php $this->beginContent('//layouts/main'); ?>
<div id="page">
<div id="menu">
<?php echo CHtml::ajaxLink('Page1', array('controller/page1'), array('update' => '#content')); ?>
<?php echo CHtml::ajaxLink('Page2', array('controller/page2'), array('update' => '#content')); ?>
</div>
<div id="content">
<?php echo $content; ?>
</div>
</div>
<?php $this->endContent(); ?>
protected/controllers/ControllerController.php:
class ControllerController extends Controller {
/**
* #var string the default layout for the views.
*/
public $layout = '//layouts/custom';
public function actionPage1() {
if (Yii::app()->request->isAjaxRequest)
$this->renderPartial('page1');
else
$this->render('page1');
}
public function actionPage2() {
if (Yii::app()->request->isAjaxRequest)
$this->renderPartial('page2');
else
$this->render('page2');
}
}
UPDATE2:
If you need the link in address bar to change too then your only option is to use regular link and not ajax <?php echo CHtml::link('Page1', array('controller/page1')); ?>
using ajax the preferred way is using hash like you mentioned.
I created a conditional statement for my custom theme in Concrete5. My codes goal is to toggle layout. If the current page has a child pages under it, it will display an additional sidebar (<div class="grid_3">) to list the subpages items. If there's no child page it would display a full layout (<div class="grid_13">).
Unfortunately I get a different result. there's something I probably had missed on my condition statement. Instead of just display one layout, It is rendering the two layout.
Below is what my code look like:
<? if($c->getNumChildren()) { ?>
<div class="grid_3">
<?php
$bt_sidenav = BlockType::getByHandle('autonav');
$bt_sidenav->controller->orderBy = 'display_asc';
$bt_sidenav->controller->displayPages = 'below';
$bt_sidenav->controller->displaySubPages = 'all';
$bt_sidenav->render('view');
?>
</div>
<div id="main-content-container" class="grid_10">
<div id="main-content-inner">
<?php
$a = new Area('Main');
$a->display($c);
?>
</div>
</div>
<? } else { ?>
<div id="main-content-container" class="grid_13">
<div id="main-content-inner">
<?php
$a = new Area('Main');
$a->display($c);
?>
</div>
</div>
<? } ?>
While your content generation portions of PHP use proper PHP tags (<?php … ?>), your if/else statements use short tags (<? … ?>) which are often disabled.
Use <?php instead.
try to do like this may this will solve the issue
<?php if($c->getNumChildren()!='') { ?>
...
<?php } else { ?>
...
<?php } ?>
I'm using Drupal 7 and my theme is Omega. I have got a class "mask" and its css code:
.mask {
background:url("../img/header_mask.png") repeat-x scroll 0 0 transparent;
height:200px;
position:absolute;
top:0;
width:100%!important;
z-index:101
}
I'm create a class on Omega theme options for show content top but my div show every page. So, I want show this class only node pages.
This is my node.tpl.php:
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<?php print $user_picture; ?>
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
<?php if ($display_submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
<div class="content"<?php print $content_attributes; ?>>
<?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
</div>
<?php print render($content['links']); ?>
<?php print render($content['comments']); ?>
</div>
Where add my "mask" class in this code?
If you only want this rule to apply ONLY to node types then change it to:
.node .mask {
...
}
Drupal adds information about the specific node being viewed as well as the node type in a div in the html. You can use Firebug or just viewing the page html to figure out how you may want to restrict your rule based on the classes present for different content types.
If the content type you want this rule to apply to has a machine name of 'event', for example, you'll see that Drupal adds the class 'node-event' to each node of that type, and you can use that to restrict your rule even further:
.node-event .mask {
...
}
Hope that puts you in the right direction!