php logo call in block - Drupal 7 - drupal

I am building out a site in drupal 7 and running into a ton of problems... very new to drupal here.
I pulled the php call for the logo out of the page.tpl file and put into the header block to be added to all pages. I understand I should probably just leave it in the page.tpl file but thought it made sense to utilize the header block but it is no longer working. can someone explain why this is not working?
here is the code
<div id="logo"><?php if ($logo): ?>
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
<?php endif; ?></div>

It's because the variable $logo is not available in block.tpl.php, it is provided only to page.tpl.php.
You can actually grab the values yourself like this:
$theme_name = 'name_of_theme';
$settings = variable_get('theme_' . $theme_name . '_settings', array());
if (isset($settings['logo_path'])) {
$logo = file_create_url($settings['logo_path']);
}

all what you need, it's additions in template.php this code
function hook_preprocess_region(&$variables) {
$variables['logo'] = theme_get_setting('logo');
$variables['front_page'] = variable_get('site_frontpage', 'node');
}
clear cache
and $logo and $front_page will works good.

Related

Wrong media files url on WordPress site

I have met a problem on WordPress site:
None images uploaded as media files are showing. I see they have wrong url like this
<a class="thumbLink" href="http:///wp-content/uploads/2014/10/Joseph-Angharad-11.7.2014-271.jpg" rel="prettyPhoto[gallery1]" title=""><i class="icon-search"></i></a>
I've tried to upload new media files and they get similar url and don't displayed.
In the database it seems ok. I don't see such url in it.
Have you met such a problem? Where to look resolving?
As far as I know it happened before removing a plugin (which was inactive).
I get images via the following code:
// instantiate the controller
if (!function_exists("peTheme")) {
$peThemeClassName = apply_filters('pe_theme_controller_classname','PeTheme'.PE_THEME_NAME);
PeGlobal::$controller =& new $peThemeClassName();
function &peTheme() {
return PeGlobal::$controller;
}
peTheme()->boot();
}
<?php $t =& peTheme(); ?>
<section class="thumbImage">
<img src="<?php echo $t->image->resizedImgUrl($content->get_origImage(),350,0); ?>" alt="" class="fullwidth">
<div class="thumbTextWrap">
<div class="thumbText">
<h3 class="sectionTitle"><?php $content->title(); ?></h3>
<?php
$text = get_the_excerpt();
if (strlen($text) > 40)
$text = substr($text, 0, 40) . '...';
echo '<p>' . $text . '</p>';
?>
<?php while ($slide =& $slider->next()): ?>
<?php $img = $slide->img; ?>
<?php
if ( $first ) {
?>
<a class="thumbLink" href="<?php echo $img; ?>" rel="prettyPhoto['<?php $content->slug(); ?>']" title=""><i class="icon-search"></i></a>
<?php
$first = false;
} else {
?>
<?php
}
<?php endwhile; ?>
</div>
</div>
</section>
It quite silly of me but I didn't disable plugins to check.
The problem was in a Parallelize plugin. It has been disabled and from now media files have right url.
This post may be a little outdated, but I had a similar recent issue so in case it proves useful to anyone:
To start, I had previously changed the Wordpress upload directory by adding the following to the end of wp-config.php
define( 'UPLOADS', ''.'files' );
So all my files are saved in domain.com/files/ After upgrading to Wordpress 4.5, all media files had very wrong url, (with something crazy like .../wp-content/uploads/rootuser/public_html/wp-content/uploads...) I tried reinstalling Wordpress, changing the directory again, disabling plugins, then I found a few posts about the Search & Replace working for some, but still no luck.
Then I found this plugin, Upload Url and Path Enabler and used the following settings that suited my situation:
Store Files: files
Full File URL: http://www.domain.com/files
And presto! All media URLs magically updated and all is working again!

wordpress advance custom field plugin showing broken image?

I am using wordpress acf plugin to show some custom images with their description and some text. So first I just made the acf plugin fileds like this and assigned the page to the home page with the conditional tags Location-> Rules-> Page->is equal to-> Home
now when I made my content-page.php to show the image code like this
<?php
if( get_field('image') ):
?><img src="<?php the_field('image'); ?>" alt="" /><?php
endif;
?>
I am getting only a broken image. The firebug is showing image source like this
Kindly help me to solve this. I have already wasted one day behind it. So any help and suggestions will be really appreciable. Thanks
Here is the screen shot for my custom fields setup
Here is the firebug html code which is showing the image source
Had this problem too. This is what I came up with that works:
<?php if (get_field('staff_photo')) {
$imgarray = get_field( 'staff_photo' );
?>
<img src="<?php echo $imgarray['url'] ; ?>" alt="" class="staff-photo" />
<?php } ?>
So, what I did was put get_field('field_name') array into a variable, then took a WAG that the key was 'url', which it was. Seems like the ACF people need to update their documentation.
Hah! Discovered another way -- this way you can pick a size:
<?php
if ( get_field('staff_photo') ) {
$imgarray = get_field( 'staff_photo' );
$size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
echo wp_get_attachment_image( $imgarray['id'], $size );
}
?>
For wp_get_attachemnt_image to work, you have to extract the image id, for which the key is, ta-da! 'id'.

Get excerpt and permalink outside loop in wordpress

I'm trying to get the post excerpt and permalink outside a wordpress loop, pulling the thumbnail and the title work fine but when trying to get the excerpt it doesn't work? And how would I get the permalink? My code so far is below.
Thanks!
<div id="featured">
<?php
$ftid = 104;
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ftid) );
?>
<img src="<?php echo $url; ?>" style="float:left;" />
<div class="featured-info">
<h2 class="post-title"><?php echo get_the_title($ftid); ?></h2>
<?php $my_post = get_post($ftid); echo $my_post->post_excerpt; ?>
</div>
</div>
And maybe if there is a better way of doing this you can point me in the right direction? :)
The permalink should work as is:
$permalink = get_permalink($ftid);
The excerpt though, when accessing the page object directly there actually has to be excerpt content (not just post content). If you didn't manually type in an excerpt on the post then nothing will appear. Inside the loop, the_excerpt() will automatically generate from the content if an excerpt hasn't been manually typed. Did you type a separate excerpt in the WP admin?
Look at wp_get_attachment_url() - you left the $ off the name of the $ftid variable.

Drupal - White Screen Of Death

Just changed themes with drupal and I'm left with white screen of death. Default theme which worked was Zen. This is stored under sites/mysite.com/themes
Theme I changed to I think is one of the themes under themes/
Don't have access to the database. Have FTP access.
Is there any way to change themes or install one that will work?
The easiest way to correct your problem is to find what's wrong.
go to index.php and add the following lines after <?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
Then post the error here.
Don't forget to comment/remove when you're done.
EDIT:
If I understood correctly this was what you did before going WSOD.
You were using Zen theme.
You logged into your site with administrator privileges and went to http://yoursite.com/admin
You went to the theme management and changed your theme to another one (henceforth refered as "theme_b")
When refreshed the page (or went to another page in your site) you got the WSOD.
.
If this is true then follow these steps:
Create a blank theme.
In order to do this, create a folder in your computer named "theme_b".
Inside create the following files:
theme_b.info, template.php, style.css and page.tpl.php
Open theme_b.info and paste this:
name = theme_b
description = bla
version = 1
core = 6.x
engine = phptemplate
stylesheets[all][] = style.css
Save.
Open page.tpl.php and paste this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<?php print $head ?>
<title><?php print $head_title ?></title>
<?php print $styles ?>
<?php print $scripts ?>
</head>
<body>
<div><?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?></div>
<div><?php print theme('links', $secondary_links, array('class' => 'links secondary-links')) ?></div>
<div id="sidebar-left" class="sidebar"><?php print $left ?></div>
<div>
<?php if ($tabs): print '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
<?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
<?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
<?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
<?php if ($show_messages && $messages): print $messages; endif; ?>
<?php print $help; ?>
</div>
<div>
<?php print $content; ?>
</div>
</body>
</html>
Save.
Then upload the folder theme_a to sites/yoursite.com/themes replacing existing theme_a folder.
This should enable you to access admin section of drupal.
You won't necessarily see any errors. For me it was a caching issue which stopped the page from loading the right content.
I cleared the cache by inserting the following on the last line of my index.php file (in Drupal root). This solved the issue for me:
db_query("DELETE FROM {cache};");
Remember to remove the line again afterwards.
More information about caching, look here: https://drupal.org/node/42055
It's most probably a PHP silent death because there's not enough memory allocated to scripts in /etc/php.ini
On shared hosting environments, you MAY be able to override this using a .htaccess file.
You more than likely have a PHP error that isn't being shown because error reporting is turned off by default on your host. The easiest way to remedy this is to add the following code at the top of index.php:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
Additionally, you definitely want to locate your php error logs and see if there is any additional information regarding the error there.
Checkout the Drupal help page for this topic: http://drupal.org/node/158043

Views title is blank

I'm using the Drupal views module to create an overview of nodes. In the view i created i configured the Title. But now when the page is rendered the title isn't shown. It is shown in the breadcrumb etc. But not in the grid template, also if i use another template it still doesn't show. Any idea what this can be? I tried looking for it, but my experience with Drupal is very limited.
I checked the drupal_get_title etc. and it is always returning the title, i think something goes wrong in the views module, but i don't know what :s
Kind regards,
Daan
The problem is most likely how you print the page title. If you want it to happen globally, you should print it in the page.tpl.php. Have you inspected the $title variable in the page template? That is what it's usually called.
i idd removed the title from page.tpl.php, but i did this because i thought it should be printed in the views template. When you check views-view-unformatted.tpl.php etc you see this:
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div class="<?php print $classes[$id]; ?>">
<?php print $row; ?>
</div>
<?php endforeach; ?>
so i thought $title would print the title, but it is fixed just by adding it in my page.tpl.php

Resources