Layout for wp_list_bookmarks - php

A few people have touched on it, but no-one appears to have outright asked it. I'm trying to provide custom application of the link list in the sidebar of a template for a client. There seems to be very little customisation of the layout of the link list element. For instance, I'd like to show the title before the image and wrap the whole lot (title, image and description) in the anchor.
I've just started playing with the functions.php file, but can't seem to work this one out. Anyone have a sample function I could use for this?
Cheers,
T

If you mean the bookmark list?
You call into the filter with e.g.:
add_filter($this->_filter, array($this,'ReplaceAll'), 9); (in a class)
or
add_filter('some_filter', 'ReplaceAll', 9); (not in a class)
Where $this-filter is your filter e.g. 'bookmark_list' and 'ReplaceAll' is the function you will write. See: http://codex.wordpress.org/Plugin_API/Filter_Reference and check the chapter "blogroll filters" for most available filters.
you can then write your function 'ReplaceAll' like usual e.g.
function ReplaceAll($something_that_comes_in_from_the_filter)
{
// do stuff e.g. $something_that_comes_in_from_the_filter =
$something_that_comes_in_from_the_filter . ' hello world';
return $something_that_comes_in_from_the_filter;
}
In terms of functionality inside that function you can define e.g. a regular expression:
const HTML_REF_REGEX2 = '/<a(.*?)href=[\'"](.*?)[\'"](.*?)>(.*?)<\\/a>/i';
and then reshuffle the parts with the matches e.g.:
return '<a' . $arrUrlMatches[1] . 'href="' . $arrUrlMatches[2]
. '"' . $arrUrlMatches[3] .'>' . 'hello world'. $arrUrlMatches[4] . '</a>';
(See: http://php.net/manual/en/function.preg-match.php for how that works)
So in that way you can make it look any way you want.

Related

giving custom argument vlue in 'q' variable

**also posted on druapl.stackexchange
https://drupal.stackexchange.com/questions/150500/giving-custom-argument-vlue-in-q-variable
**
apologies if question is ambiguous . the scenario is as follows:
in drupal 7 , we want to use a custom template page when a specific value is given for the q variable in url .
for example if we give http://localhost/drupal/?q=xyz/123 , we want to use a custom template page say page-xyz.tpl.php ..
have a hunch that hooks and template.php file may be the key components here but not sure what to exactly do..
any help appreciated.
you could implement theme_preproccess_page() (or node, or html) to control this in your template.php
function YOURTHEME_preproccess_page(&$vars) {
if (isset($_GET['q']) && $_GET['q'] == 'xyz/123') {
$vars['theme_hook_suggestions'][] = 'page_xyz';
}
}
that should work, but I would like to recommend not use the '?q=xyz' solution, but do an preproccess that should work to all your pages, like this.
function YOURTHEME_preproccess_page(&$vars) {
$title = strreplace(' ','_', $vars['node']->title);
//if you use the transliteration module, instead of strreplace
//use transliteration_get($vars['node']->title);
$vars['theme_hook_suggestions'][] = 'page_'.$title;
}
now that should work for every page that you want to make a custom template. Just add the file and clear the chaches. If you don't have the page template to the specific page, it's ok, drupal will use the default.

Why would using the `send()` function of Magento's `Mage_Core_Model_Email_Template` model affect styling?

For some odd reason, when I use the Mage_Core_Model_Email_Template model, I cannot actually send an email without it affecting the page's styling.
Granted, I haven't set up the styling. There is only one design picked under System->Design in the admin section, and it is set as polar/retail.
What happens, is that the design, just for the confirmation page of the order, is switched to the "default" style, e.g. polar/default.
I exported the database and did a text search for a possible offending column in some table that was set to polar/default polar-default, or polar_default, but there was nothing.
The rest of the site is good.
This is quite literally what my code is:
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate->loadDefault('order_nobpid_email');
$emailTemplate->setTemplateSubject('No BP ID Set for Customer ' . $order->getCustomerEmail() . '. Order: ' . $order->getIncrementId());
$emailTemplate->setSenderEmail($sender['email']);
$emailTemplate->setSenderName($sender['name']);
$result = $emailTemplate->send($recipient['email'], $recipient['name']);
When I comment out the send() function, the confirmation page has the correct styling and design. When I allow the function, the design gets messed up.
What does the email have to do with the page's design? I tried to follow the function calls, but I couldn't find anything useful.
To give some visuals of the issue:
When enabling the send() function, I get this.
When commenting out the send() function, I get this, which is correct.

opencart get the product seo url from within admin

I am extending the newsletter area so that I can send out an email with a list of products but I can't find out how to get the seo url for each product?
When I do this I actually end up with the admin URL.
$this->url->link('product/product', 'product_id=' . $row['product_id'])
This same code in the store front works fine and returns the seo url if it exists.
The only way I can get it to work is if I manually build the URL, obviously no seo url.
HTTP_CATALOG .'index.php?route=product/product&product_id='.$row['product_id']
Looking into this further I see that the admin area is missing the following code but I can't figure out how this actually works and ties in with $this->url->link so that I can modify it to work for me.
$controller->addPreAction(new Action('common/seo_url'));
UPDATE - in the end the easiest solution was to add my own method like this:
public function getUrl($route, $key, $value){
$url = "index.php?route={$route}&{$key}={$value}";
if($this->config->get('config_seo_url')){
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
if($query->row['keyword']){
$url = $query->row['keyword'];
}
}
return $url;
}
Front-end links
The best way to make a front-end link from the Admin area without modifying core files is to create your own URL object:
$url = new Url(HTTP_CATALOG, $this->config->get('config_secure') ? HTTP_CATALOG : HTTPS_CATALOG);
To create URLs you then use $url instead of $this->url, so your example would be:
$url->link('product/product', 'product_id=' . $row['product_id']);
SEO URLs
Getting SEO URLs is a bit harder and unfortunately requires copying some code or a bit of bodging.
Copied Code
Basically, copy the entire rewrite($link) function from catalog/controller/common/seo_url.php and add it to the controller class that you're creating. Then add the following line after the new $url line mentioned above:
$url->addRewrite($this);
The current controller is then used as a rewriter and all URLs get rewritten. You might be able to use a separate class, but then there are dependencies to get the database access. This seemed the most direct way of doing it, even if it is ugly.
Your code should then be:
<?php
class ControllerMyController extends Controller {
public function index() {
...
$url = new Url(HTTP_CATALOG, $this->config->get('config_secure') ? HTTP_CATALOG : HTTPS_CATALOG);
if ($this->config->get('config_seo_url')) {
$url->addRewrite($this);
}
$url->link('product/product', 'product_id=' . $row['product_id']);
...
}
public function rewrite($link) {
... [stuff from seo_url.php] ...
}
}
and you'll get SEO'd URLs from the admin area.
Bodging
If you're happy with an arbitrary require statement, then you can alternatively do the following and use the existing SEO code (which means that it'll stay up-to-date if it changes, but will fail if the file moves).
To create SEO URLs this way your code needs to be:
$url = new Url(HTTP_CATALOG, $this->config->get('config_secure') ? HTTP_CATALOG : HTTPS_CATALOG);
if ($this->config->get('config_seo_url')) {
// Require the SEO file directly - path is relative to /admin/index.php
require_once('../catalog/controller/common/seo_url.php');
$rewriter = new ControllerCommonSeoUrl($this->registry);
$url->addRewrite($rewriter);
}
$url->link('product/product', 'product_id=' . $row['product_id']);
Administration part do not need the preAction for SEO, as there are no SEO links in administration.
The problem You are getting is because on frontend the constant HTTP[S]_SERVER points to http[s]://mydomain.com/ while in administration the same constant points to http[s]://mydomain.com/admin/.
What are You looking for is maybe an edit of url class (system/library/url.php) and adding a new method frontend_link by copying link method and replacing HTTP[S]_SERVER constant in the method body by HTTP[S]_CATALOG constant that is present only in administration...
Expanding a little on #IBBoard's very informative answer: in Opencart 3.0.2 and above, seo_url.php is no longer in the catalog/common folder. It was moved to catalog/startup.
Also, it is highly recommended to run the filename in the require_once statement through opencart's modification function, like:
require_once modification(DIR_CATALOG . 'controller/startup/seo_url.php');

Display page content using multiple templates - WordPress

Is it possible to have a page like: www.site.com/page/
and show different templated versions using, say:
www.site.com/page/?template=default
www.site.com/page/?template=archive
...?
So it retrieves the same page content but displays it differently.
Is this possible with WordPress? Is it standard or would need some tomhackery to do this?
Thank you
I answered a similar question a moment ago.
Manually set template using PHP in WordPress
The answer above should work, but the use of TEMPLATEPATH, I think is not ideal, it also seems to not take advantage of what WordPress is already doing to select a template.
function filter_page_template($template){
/* Lets see if 'template is set' */
if( isset($_GET['template']) ) {
/* If so, lets try to find the custom template passed as in the query string. */
$custom_template = locate_template( $_GET['template'] . '.php');
/* If the custom template was not found, keep the original template. */
$template = ( !empty($custom_template) ) ? $custom_template : $template;
}
return $template;
}
add_filter('page_template', 'filter_page_template');
Doing it this way, you don't need to add a new line for every template you want to be able to specify. Also, you take advantage of the existing template hierarchy, and account for the possibility that a non-existant template was entered.
I would point out that you should do some validation against the $_GET['template'] value before using it, but also that you might want to keep a running list to check against, so that they cant simply use any old template.
Create a 'master' template and assign it to your page. The master template doesn't contain any layout information—just a set of conditional include statements that selects the 'real' template based on the GET variable. The master template might look something like this:
<?php
switch ($_GET["template"]) {
case "foo":
include(TEMPLATEPATH . "/foo.php");
break;
case "bar":
include(TEMPLATEPATH . "/bar.php");
break;
case "baz":
include(TEMPLATEPATH . "/baz.php");
break;
default:
include(TEMPLATEPATH . "/default_template.php");
break;
}
?>

Drupal 7 - What is the variable in template.php that dictates which page template is used?

Ok, here's the deal: I am constructing a Drupal website that has several different sections. Each section is a view that displays a content type. (Each section has it's own content type) For example, I have a view that points to ?q=blog which displays content type blog.
All the sections look a little different than each other. Not like 'website-within-a-website' different but different enough that they can't all use the same template file and each be modified with CSS. Each section needs it's own page.tpl.php.
Unfortunately, AFAIK Drupal theme's .info files can only either assign one page.tpl.php for the entire theme or assign a page-node-####.tpl.php for each node. There is going to be lots of content on this website so setting Drupal to make a new identical page-node-####.tpl.php for every created node would get unmanagable very fast.
To solve this problem, I am going to use pathauto to create an alias for each content type. For example, all nodes of content type blog are given an alias ?q=blog/[post title]. Modify template.php to use page-blog.tpl.php for any page who's alias starts with the word 'blog'.
Other people have tried doing this sort of thing and have created functions such as the one described. Unfortunately, all the ones I have seen are for Drupal 6 or below. I have tried modifying existing ones with no success. So far, though, I think this is on the right track:
function basic_preprocess_page(&$vars, $hook) {
...
if( module_exists('path') ) {
$alias = drupal_get_path_alias( $_GET['q'] );
$site_section = "blog";
if( strpos( $alias, $site_section ) === 0 ) {
$VARIABLE_THAT_TELLS_THE_PAGE_WHAT_TEMPLATE_TO_USE = "/path/to/page-blog.php";
}
}
}
I cannot find $VARIABLE_THAT_TELLS_THE_PAGE_WHAT_TEMPLATE_TO_USE does anyone know what it is?
Maybe my site is structured badly. If anyone knows how to restructure my site so I can more easily make a theme with seperate sections please share how!
Thanks a million! (c:
EDIT: Perhaps I need to use template suggestions instead. Does anyone know the function or variable to use to set this?
They changed the name of this array key in D7 and I haven't seen it documented anywhere. I finally figured this out after a good bit of debugging. You can override the theme template in template.php with a hook_preprocess_page() like so:
function myTheme_preprocess_page(&$vars) {
global $node;
if ($node->type == 'blog') {
$vars['theme_hook_suggestions'] = array('my__blog_template'); // use my--blog-template.tpl.php, note '-' = '_'
}
elseif ($node->type == 'articles') {
$vars['theme_hook_suggestions'] = array('article__node_template'); // use article--node-template.tpl.php
}
}
Oh and don't forget to flush the Drupal caches after making changes to your template.php.
Ok, I found it:
http://drupal.org/node/223440#comment-991840
$alias = drupal_get_path_alias($_GET['q']);
if ($alias != $_GET['q']) {
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '-' . $path_part;
$variables['template_files'][] = $template_filename;
}
}
Credit to this function goes to user mfb.
I had a lot of trouble with this so I will explain it here in case anyone finds it useful.
This function goes in your template.php. It needs to be part of the <theme name>_preprocess_page function. What it does is it takes the alias and then explodes it into a bunch of different components. For example if you are on a page with the alias ?q=blog/blog-post-title it would be exploded into blog and blog-post-title. It then turns each component into a name for a template suggestion. It puts each template suggestion into the template_files[] array (inside the $variables[] array) so that the page now has two new template suggestions:
page-blog, and page-blog-blog-post-title
Template suggestions are alternate template files. In this case they are for pages, but they don't necessarily have to be. You can have template suggestions for anything you can think of including blocks, nodes and the like. Don't let the name 'template suggestion' fool you. Template suggestions will be used over default templates as long as they exist. I don't know why it was named like that. I think it should be renamed.
What you do, then, now that you've set up Drupal to look for a template suggestion that points to your alias, is create a new template file where all the rest are in your theme. In this case, let's say I want to theme my entire blog section. In the templates folder I should create a file named page--blog.tpl.php (note the --double hyphens--) with the layout I want.
Drupal will use the most specific template suggestion it can find so if you wanted you could make one blog post to look completely different than the rest of the site long as you make a template for it named page--blog--blog-post-title and put it in your theme's templates directory. (again, note the double hyphens.)

Categories