multiple htmlspecialchars code on one line - rss

I was setting up an rss feed with a module on joomla (mediarss). I managed to add some custom codes, my question now is, can I use multiple htmlspecialchars codes/fields in one line.
Herunder, the example :
$feed.= " <title>".htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," ")))."</title>\n";
$feed.= " <region>".htmlspecialchars(strip_tags(strtr($this->items[$i]->region,"\n\r"," ")))."</region>\n";
The first feed is showing me the title of a post in the rss feed, the second one is showing off a region. The region field is a custom field we added in the backend of joomla.
in the rss feed, this is showing of like this:
<title>the title of the post</title>
<region>the region filled in, in the custom field 'region'</region>
What I want to achieve is following output
<title>the title of the post **in** the region filled in, in the custom field 'region' </title>
so can I put the 2 codes on one line?
Many thanks,

Related

What is the php I need to show a Custom Field Value from a Drop Down Box, Type (Select2), in Wordpress

Currently I am using this php code to display Text for a custom field with taxonomy 'years' in a theme in wordpress, that works well
php echo get_post_meta($post->ID, 'years', true); (Including the php opening and closing tags)
But the problem I have is that if I want to change this Text, to a Drop Down Box (a select2 type), to let choose different options to the users, I cannot find how to display the values correctly.
Any body has any idea of how to display correctly the value of a custom field froma Drop Down selec2 type ?
Thanks for any help on this
Here's how I would accomplish this.
On your post or page, add the custom field. So if you have a custom field of 'years' we'll add 2013 and 2014 and 2015 as 3 entries. Save your post/page.
This creates an array for this custom field that you can iterate through. see here for code. http://pastebin.com/Ungm3WZW
FYI - I referenced the codex for http://codex.wordpress.org/Function_Reference/get_post_custom_values

Wordpress - How can I create my own template outside of the expected hierarchy of templates and feed a query to it?

BACKGROUND
I have used WordPress custom post types to create a newsletter section for my website. Newsletters consist of Articles (dm_article), which are grouped by the Issues taxonomy (dm_issues).
1) I have created an index of all of my newsletter Articles. I am using a template called taxonomy-dm_issues.php to loop within a selected Issue and display each Article's title, excerpt and a link to the full content, which is managed by single-dm_article.php. This is working great.
2) I would also like to create second taxonomy-based template for Issues. This is going to act as a print-friendly option: "print entire newsletter". I would like the template to loop through and display each Article title, excerpt, and long description. Some of the look and feel will also be different.
For #2, let's assume I've created a template called print-dm_issues.php. It currently looks identical to taxonomy-dm_issues.php, except it has the additional long description data for each Article and contains some different styling.
I want to setup this "print friendly" option without making the WordPress admin have to jump through any hoops when Issues and Articles are created. I also do not want to have to create a new template each time a new Issue is created.
CORE QUESTION:
What I am asking for may boil down to this: How can I create my own WordPress template outside of the expected hierarchy of templates and feed a query to it? Do note I am using the "month and name" common permalink structure, so I'll have to muck with my htaccess.
ALTERNATIVES:
1) My fallback is to have taxonomy-dm_issues.php contain the information for both variations and use style to handle the different view states. I know how to do this. But, I'd rather not do this for sake of load times.
2) Using Ajax to fetch all of the Article long descriptions (the_content()) with a single click is an option, but I don't know how.
3) ???
With or without clean URLs, you can pass variables based on your taxonomies through the links query string if you want to only return a single taxonomy term and style the page differently depending on the term.
$taxonomyTerm = $_GET['dm_issues'];
$args=array(
'post_type' => 'dm_article',
'dm_issues' => $taxonomyTerm,
'post_status' => 'publish',
);
There is reference to this int he Wordpress 'query_posts' documentation by passing variable into your query parameters: http://codex.wordpress.org/Function_Reference/query_posts#Example_4
For instance in the link below, the title is generated based on the sting in the URL.
http://lph.biz/areas-we-serve/service-region/?region=Conestoga
You can set up a parameter that will return a default value if the page is reached without the variable being defined. See below:
if (empty($taxonomyTerm)) {
$taxonomyTerm = 'Default Value';
}
You can create a separate page template. Define the template name at the top of your PHP document:
<?php
/*
Template Name: Printed Page Template
*/
Place your custom query, including all of the content that you need output in this page template... In your WP admin, create a new blank page and assign your new 'Printed Page Template' template to this page. Save it and view the page.

Drupal Multiline Title

At the moment I may have a title like
Welcome to my new Website made using Drupal
This title is splitting onto two lines but I have no control where the break takes place.
I would much rather have:
Welcome to my new Website
made using Drupal
To do this I decided the best thing to do is to create a new CCK field to house the title and insert a into it.
I will leave the normal title there and fill it in as well so it appears in the title bar correctly and in the search results etc.
I can get my custom cck field(text) using the following code in my theme:
<?php print $node->field_page_title[0]['safe'] ?>
The problem is that this is coming across as
<p>Welcome to my new Website<br /> made using Drupal</p>
I need to strip the p tags away. I can do this in the theme layer but to me it would make more sense to do it in a module because there will not be a situation where I would want the tags.
What hook would I need to use to change this. Do you think I am going about this in the best way?
Why don't you insert the <br /> tag in the node title and allow it in your theme.

Conditional link to node within views?

I have two content types, book and chapter. Each chapter node contains a node reference of the book to which it belongs. I have created a view which displays the title of each chapter for a given book. Within the view, the title field has been configured to link to its node.
All works well. I am now interested in updating the view to not display a link to a chapter's node when the chapter's body is empty. Thus this view would display a list of chapter titles for a book and link only to those chapters that have a body.
Can this be accomplished using out of the box Views functionality? If not, how would something like this be accomplished?
Thanks.
I'd use the Views Custom Field module to implement your custom logic. It allows you to grab the data fetched by Views and manipulate it at will with PHP. Very handy.
I'm answering my own question because my response to ceejayoz is poorly formatted.
What I did to accomplish this was to first download and enable views_customfield. Second, I placed Title and Body fields within the view, both excluded from display. Third, within a Customfield: PHP code field I placed the following code:
<?php
if (strlen(trim($data->node_revisions_body)) == 0) {
return $data->node_title;
} else {
return l($data->node_title, drupal_get_path_alias('node/' . $data->nid));
}
?>
There's also this clever workaround which allows you to achieve this very easily:
Add 2 title fields one with link and one with no link, and make both
them exclude from display.
Add body field,
In No result behavior put title with no link replacement token to
it.
In Rewrite results behavior put title with link replacement token to
it.
Tick hide if empty.
Source

Related posts from the blogosphere - dynamic integration of Google Blogsearch RSS on wordpress category pages

I'm looking for a method to put the three latest "news" from Google Blogsearch/Twitter search feeds into the bottom of category Pages. Maybe like this (assuming we're on the archive page for the "Sports" category):
What others say about "Sport":
Instapundit - Michael Jordan Comeback!
Huffington post - Michael Jordan Comeback!
Crazyguy - Michael Jordan Comeback!
So we all know that you can put
<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('pathtofeed.com', 3); ?>
in a template-file and it will list the latest three items of a feed.
I would like to put the path to the feed of a query to Google Blogsearch, e.g. [http://blogsearch.google.com/blogsearch_feeds?hl=en&q=sport&ie=utf-8&num=10&output=rss][1]
Works fine. But I would like to replace the sport query with the template tag for the category title - so it dynamically queries Google for a RSS-feed of sport searches. I've tried this:
<?php
include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('www.blogsearch.google.com/blogsearch_feeds?hl=en&q=<?php single_cat_title() ?>&ie=utf-8&num=10&output=rss', 3);
?>
(omitted 'http' cause I can't post hyperlinks here as a new user).
But all I get is:
There was a problem with the feed, try again later.
(translated from Danish error message).
Is it the syntax?
You've got a couple of issues in that code.
The first is you have a <?php inside an already opened <?php section. Concatenation is the answer to that problem.
The second is the function single_cat_title() displays the category title by default. Meaning it "echo()"s it out. So you need to tell that function to return the value not display it.
My solution would be to add a line of code above your include there to get the category you're looking for along the lines of:
$current_category = single_cat_title("", false);
The "false" tells the function to return it as a value instead of displaying it by default, the first parameter is the prefix or the text to display before the category title.
Then concatenate the current_category variable into your include statement
You can check out that function on the Template Tags page in the Wordpress Codex.

Resources