Drupal hiding the title in a node if it's <none> - php

I'm trying to figure out how to hide the title of my nodes in drupal... I don't wanna use another module, I just want to change something in the node.tpl.php...
My attempt was to ask if the title is "" and if not, it should just post the title... I've did it like this:
Damn won't work to show the code here, got it in jsfiddle now: jsfiddle.net/8d6FR/
But it doesn't work. Has someone some suggestions why it won't work?

You code looks almost right, I've changed it slightly just to make it easier to understand:
<?php if($title!="<none>"){ print render($title_prefix); ?>
<h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
<?php print render($title_suffix);} ?>
If that is not working then add the code:
var_dump($title!="<none>")
That will let you know how PHP is evaluating your if statement and will allow you to do some further debugging.

PHP in a JSFiddle, that is not gonna work :)...To hide your node titles you'll have to modify your tpl file indeed, or create one if it you need it for a certain content type or node, or manage the display of your nodes within Drupal admin. You may need Title to replace title field with a regular field in order to hide it with the "Manage display" interface or Display Suite.
Find your node.tpl.php or page.tpl.php (depends on your theme) using Theme Developper, and find something like print $title.

Related

how to get attribs in tags Joomla

For extra data fields used in Joomla:
<?php
$attribs = new JRegistry($this->item->attribs);
echo $attribs->get('extrafield_name');
?>
or
<?php echo $params->get('extrafield_name'); ?>
I tried the same thing, to display extra fields of com_content in com_tags.
as I can fix that. Thank you for your help.
Situation before this change:
I have a couple of custom fields added to my article using the same technique as described here:
https://zunostudios.com/blog/development/203-how-to-add-custom-fields-to-articles-in-joomla
I then made a menu item of the type "tagged items" and tried to override the joomla default template for the tagged items list, which I found under components/com_tags/views/tag/tmpl/default_items.php
However the attribs are not available in $item (line 35 and ongoing)
Situation after this change:
The query which returns the items of the "tagged items" now also returns the attribs. And one can use something like this to use the attribs in the tagged items list:
$attrb = json_decode($item->attribs);
echo $attrb->foo;
I hope I didn't break anything - this is my first patch to the joomla project, so I'm happy to hear your feedback and improve my solution.

Dynamic title depending on page (DRUPAL 7)

Before I made the switch to Drupal (previously just static HTML), I had a div title in my header that changed depending on what page the user was on using the following code:
ABOUT PAGE
<?php
$title = "ABOUT US</span>";
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/header.php";
include_once($path); ?>
The reason this worked, however, was because I was using static HTML... which means I had every page set to use its own Index.PHP, located at (for the About page, for example) public_HTML/about/index.php. Therefore, I could edit each page individually to my liking by editing its respective Index file...
Now, with Drupal.. instead of having so many Index.PHP files like I did before (which was messy IMO...), I want to have every page use the same page.tpl.php (with the exception of the front page, which uses page--front.tpl.php).
Can I somehow modify the above PHP code to display a different title using IF statements depending on what page the user is on?
For example... (I have no idea how to PHP code so this is just to give you experts an idea of what I would want..)
Ifpage=about, $title=About Us;
Ifpage=contact, $title=Contact Us;
Could this code all be in the same page.tpl.php?
Thank you so much!
Drupal 7 has a title field for each content type. Why don't you use that?
It shows by default and you can change it for every node.
It is this code in your template file.
<?php print render($title_prefix); ?>
<?php if ($title): ?>
<h1 class="title" id="page-title">
<?php print $title; ?>
</h1>
<?php endif; ?>
<?php print render($title_suffix); ?>
$title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
$title: The page title, for use in the actual HTML content.
$title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
See https://api.drupal.org/api/drupal/modules!system!page.tpl.php/7 for all the variables available in your page.tpl template file.
If you want to style one part different from the other you could use an extra field for it.
Or if you need to do something with the value (I wouldn't suggest this!!!).
switch ($title) {
case "About Us":
// Do something with the title
break;
case "Contact Us":
// Do something with the title
break;
case 2:
// Do something with the title
break;
}
Here's a simple approach:
Add a new field for the content type
Call it title2
Render the two fields
Use css to inline align them and add styling
Here was my solution since I am unable to position a Drupal-based title block right next to a non-Drupal based logo DIV..
I created a div called .headertitle and positioned/styled it how I want.
My header.php is an PHP include file which is called by each page and the headertitle has a PHP condition..
<?php if(empty($headertitle)) $headertitle = "ASK REAL QUESTIONS, <br><span class='white'>GET FREE ANSWERS.</span>";
echo $headertitle; ?>
That way, if no text is declared for the .headertitle, it takes the default form of "ASK REAL QUESTIONS, GET FREE ANSWERS."
...Now, I had to figure out a way to actually declare text for the .headertitle depending on what page I was on...
I did this by using a custom template for each page (node) by using this file.. "page--node--nodeid.tpl.php".
So, for my ABOUT US page, I created a tpl.php file called "Page--node--7.tpl.php".. for this page, the 7 is the nodeid which is easy to find.
Then, I added the following PHP code to declare text for the .headertitle specifically on the ABOUT US page which looks like this...
<?php $headertitle = "ABOUT<span class='white'>.US</span>"; include('includes/header.php'); ?>
DONE AND DONE.
I'll do that for each page. :)

The description is not prominent by default; however, some themes may show it

I'm using the latest wp version. When I go to edit a category to add descriptions specifically for each category, there is a note that says, "The description is not prominent by default, however some themes may show it."
My theme does not show it. What code do I need to make this visible/prominent? And where would I insert it?
You're looking for category_description().
<?php echo category_description(); ?>
As for where to add it, that's way too broad of a question. We would have no way of knowing without looking at your theme template system.
To display the category, we want to echo it:
<?php echo category_description();?>
And you would basically treat this as if it is text (because that's what it outputs).
So lets say you have a <div> that you want it displayed within in your theme....
<div class="your-container">
<?php echo category_description();?>
</div>
And there ya have it!
Wordpress Codex:
https://codex.wordpress.org/Function_Reference/category_description

Changing woo commerce HTML that gets outputted with do_action

I'm trying to build a webshop with woo commerce which seems like a very nice and easy to use system. But I'm really having some trouble with it. A lot of times there's a function like this in the code: do_action( 'woocommerce_checkout_order_review' ) which outputs some HTML that I really want to change. The documentation that is provided isn't making me any wiser. How can I change this HTML. I would really appreciate any help trying to understand how this works!
The answer to the question, how do I modify the content ouputted in woocommerce_checkout_order_review ?
The answer:
The HTML is located in the template file here:
wp-content/plugins/woocommerce/templates/checkout/review-order.php
You can easily modify this content in a plugin or theme. Read more about that here: http://docs.woothemes.com/document/template-structure/
do_action( 'woocommerce_checkout_order_review' )
this is action declared somewhere, this is done so that whenever you want to add anything for example say "hello there", you dont have to hardcode it .. you can simply do it this way ..
function add_something() {
echo 'hello there';
}
add_action('woocommerce_checkout_order_review','add_something');
Refer here
Add Action
This would add "hello there" in the rendered html page..exactly where you have do_action('woocommerce_checkout_order_review'); in the code . keep this snippet in your functions.php and play with it ;)

How to make PHP code to check if title contains certain word? (Wordpress Shopp)

I'm using the WordPress Shopp plugin to sell products on my WordPress site. So far I love this plugin but I'm trying to do something custom and unfortunately I'm not good enough with PHP to figure this out on my own (I've done tons of research too!).
Here is what I am trying to accomplish...
To display the product title for each individual product Shopp uses the following code to reference the product title...
<?php shopp('product','name'); ?>
What I am trying to do is reference the product name and if for example the product name says something like 'FLIR H-Series Thermal Imaging Camera' I want my code to detect whether or not the product title contains the word 'FLIR' in it and if it DOES contain the word 'FLIR' I want it to echo a FLIR logo image (let's say the URL of the image is http://example.com/images/flir.jpg). Alternatively I would want it to echo a Thermal-Eye logo image anytime the word 'Thermal-Eye' is found in the product title, etc. How could I go about modifying the code to do this?
Hopefully this make sense, thanks for any help!
<?php
$keywords = array('FLIR', 'Thermal-Eye');
foreach($keywords as $word)
{
if(preg_match('/'.$word.'/i', shopp('product','name', 'return=true')))
echo $word;
}
?>
UPDATE: If you want to echo out a unique image based on the word, rather than the word itself, you can do something like:
if(preg_match('/'.$word.'/i', shopp('product','name', 'return=true')))
echo '<img src="'.get_bloginfo('stylesheet_directory').'/images/'.$word.'.jpg" />';
So in the case of FLIR, you just need to make sure FLIR.jpg exists within the images folder in your theme directory.
Best thing to do is to play around with it and see what works for you.

Categories