(This post has been submitted on the Yootheme forums but I don't have as much confidence in a solution so I thought I'd post it here too.)
I'm using the Nano theme from Yoothemes and its working great for 90% of my site. http://dofekit.org However I've just installed the bbPress forum plugin (not on the live site, but a local version) and I have created 2 'forums'. The forum index page and all sub-pages seem to be inserted into a standard Nano page template. This is not suitable for the forum as it includes the page meta information and also I see no way of turning off 'sidebar-a' for the forums as my screenshot demonstrates.
http://dl.dropbox.com/u/240752/forums.jpg
Is there a way of creating a separate template for the forum post type within the yoothemes framework? ( I know its kind of proprietary but I can but ask)
Thanks.
UPDATE:
I'm part of the way there. I've manged to make separate templates for my forum post types like so, but I still need to get the custom post types to be acknowledged in the widget settings.
I've added the custom post types in warp/systems/wordpress3.0/layouts/content.php
if (is_home()) {
$content = 'index';
} elseif (is_page()) {
$content = 'page';
} elseif (is_attachment()) {
$content = 'attachment';
} elseif ((is_single()) && (get_post_type() == 'forum')) {
$content = 'forum-single';
}elseif ((is_single()) && (get_post_type() == 'topic')) {
$content = 'topic-single';
} elseif (is_single()) {
$content = 'single';
} elseif (is_search()) {
$content = 'search';
}elseif ((is_archive()) && (get_post_type() == 'forum')) {
$content = 'forum-archive';
} elseif (is_archive() && is_author()) {
$content = 'author';
} elseif (is_archive()) {
$content = 'archive';
} elseif (is_404()) {
$content = '404';
}
I've also added these custom post types into
warp/systems/wordpress3.0/config/layouts/fields/profile.php
in an effort to get them to appear in the dropdown lists on each widget. (I want to be able to toggle widgets on these new custom templates.)
$defaults = array(
'home' => 'Home',
'archive' => 'Archive',
'search' => 'Search',
'single' => 'Single',
'page' => 'Pages',
'forum-archive' => 'Forum List',
'forum-single' => 'Forum Single',
'topic-single' => 'Topic Single'
);
Can anyone please help? I think I'm almost there with this.
You should be able to handle this using a WordPress Template for your custom post type for single post display.
For example if your custom post type is called "product" create a template called single-product.php e.g. single-{post_type}.php
This solution should work irrespective of Yoothemes framework, Let me know if that works!
i'm not shure if my answer can help you but...
My code add the Custom Taxonomy categories to the widget position...
I edit the file warp/systems/wordpress/config/layouts/fields/style.php
and I add this lines for each custom taxonomy =)
// set Eventos cate
if ($categories = get_categories(array('hide_empty' => 0, 'name' => 'select_name', 'post_type' => 'event', 'taxonomy' => 'event-category'))) {
$options[] = '<optgroup label="Eventos | Categorias">';
foreach ($categories as $category) {
$val = 'cat-'.$category->cat_ID;
$attributes = in_array($val, $selected) ? array('value' => $val, 'selected' => 'selected') : array('value' => $val);
$options[] = sprintf('<option %s />%s</option>', $control->attributes($attributes), $category->cat_name);
}
$options[] = '</optgroup>';
}
Here... my postype is "event" and my taxonomy is "event-category" in the list of the widget position now you can see all the Categories or Terms of the Taxonomy and y label it with "Eventos | Categorias" for a better identification.
Ok this is only one part of the code and maybe you can take this like a point to start. Now i just can display and list this terms but still nok working :(
so... tnks for the comments and sorry for my english :P
Related
I have a custom post type setup and in the sidebar of every page on the site it is set to display a random post from that custom post type (named "reviews").
This works great everywhere except for category pages for the normal / standard / default post type of "post" where even though the query is setup to only use the custom post type "reviews" it only pulls from the default blog posts.
Is there something I am leaving out to make sure this works even on category pages?
Here is the code I am using that works fine on non category pages, you can see it is restricted to just the "reviews" post type:
// the query
$review_query = new WP_Query( array (
'post_type' => 'reviews', // Display just this post type
'orderby' => 'rand',
'posts_per_page' => 1,
)
);
You can create shortcode that you can put in any widget area you want.
Something like:
function wpb_rand_posts() {
if ( $the_query->have_posts() ) {
$string .= '<ul>';
while ( $the_query->have_posts() ) {
//do stuff
}
$string .= '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
$string .= 'no posts found';
}
return $string;
}
add_shortcode('wpb-random-posts','wpb_rand_posts');
add_filter('widget_text', 'do_shortcode');
Ok so it turns out the code I had added to functions.php to make sure a different custom post type was displaying in the category feed was interfering.
So this was the original code snip I used to do that:
// Show notable cases in tag archives
function themeprefix_show_cpt_archives( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'nav_menu_item', 'post', 'cases'
));
return $query;
}
}
And I changed that to this:
// Show notable cases in tag archives
function themeprefix_show_cpt_archives( $query ) {
if( empty( $query->query_vars['suppress_filters'] ) && ( is_category() || is_tag() ) ) {
$query->set( 'post_type', array(
'nav_menu_item', 'post', 'cases'
));
return $query;
}
}
And added suppress_filters' => true to my query, and this resolved my issue. If anyone else runs into this see what else in your theme may be modifying the query at a higher level through a function like this or plugin as this is a solution specific to the code in my theme.
I've a custom post type named "references" and I added a function so I can use the category as part of the permalink. I'm declaring the custom slug like so:
'slug' => '/references/%category%',
and then use a filter to manipulate it:
function change_post_link($post_link, $id = 0) {
$post = get_post($id);
if ($post->post_type == 'references') {
$terms = wp_get_object_terms($post->ID, 'category');
if ($terms) {
return str_replace('%category%', $terms[0]->slug, $post_link);
}
}
return $post_link;
}
That part works fine, I'm getting URLs like "/references/cars/the-red-one".
But now I can't have a page (the default type) at "/references/cars", it only works if I'm not using a placeholder for the custom post type.
Do you have any ideas how this could be solved? 'has_archive' is false btw.
Thanks!
You can use this way
Find Category Slug:
$categories = get_categories();
foreach ($categories as $cat)
{
$cat_slug = $cat->slug;
}
Create New URL:
$new_url = esc_url(add_query_arg(array( 'category' => $cat_slug,), $old_url));
It might not be the best solution but at least it works now. Here you go:
I've added a hidden dummy post type with the slug "references/dummy". This seems to force Wordpress to recognize the correct (debateable...) permalink structure.
Well, I have a WordPress site with WPML. Not all of my pages are translated to EN version. And I know to realize following. When somebody tries to go to URL which doesn't exist I want to show him/her 'Not translated page' (with a recommendation to observe this content in another language).
How can I realize it? Thanks!
add_action('wp_head', 'wpml_custom');
function wpml_custom() {
global $wp_query;
$postId = $wp_query->post->ID;
$postType = $wp_query->post->post_type;
$args = [
'element_id' => $postId, 'element_type' => $postType
];
$translation = apply_filters( 'wpml_element_language_details', null, $args );
$currentLang = apply_filters( 'wpml_current_language', null );
if (preg_match('/^\/$/', $_SERVER['REQUEST_URI'])) {
return;
} elseif ($translation->language_code !== $currentLang) {
require get_template_directory() . '/no-translation.php';
exit();
}
}
I have a directory site, so I created a post type name "ads" and their post title are phone numbers, but I want the permalinks instead of mysite.com/ads/post_title I want it mysite.com/post_meta_city/post_title and here's my code:
function ads_add_rewrite_rules(){
global $wp_rewrite;
$wp_rewrite->add_rewrite_tag('%post_ads_city%', '([^/]+)', 'post_ads_city=');
$wp_rewrite->add_rewrite_tag('%ads%', '([^/]+)', 'ads=');
$wp_rewrite->add_permastruct('ads', '%post_ads_city%/%ads%', false);
}add_action('init', 'ads_add_rewrite_rules');
function ads_permalink($permalink, $post, $leavename)
{
if ($post->post_type != 'ads' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft'))){
return $permalink;
}else{
$no_data = 'no-city';
$post_id = $post->ID;
$var1 = get_post_meta($post_id, 'post_ads_city', true);
$var1 = sanitize_title($var1);
if(!$var1) {
$var1 = $no_data;
}
//$permalink = str_replace('?ads=', $var1."/", $permalink);
$permalink = str_replace('%post_ads_city%', $var1, $permalink);
return $permalink;
}
}add_filter('post_type_link', 'ads_permalink', 10, 3);
Yes i achieve the url that I want, but the problem is when i visit the other pages on my site, it returns only the homepage, is there away to fix this? without adding a something hard coded on the add permastruct? please help.
By the way the site i am doing has an existing site so its important for me to keep the urls.
This can be set when you register your post type. You can add this to your arguments:
'rewrite' => array( 'slug' => 'announcement' ),
See register_post_type(): https://codex.wordpress.org/Function_Reference/register_post_type
I am using Taxonomy_Manager and Menu_breadcrumb modules
my categories looks like:
+BUSINESS
++Agriculture
++Banking & Finance
++Construction & Real Estate
+News
++ Behind the news
++ Peace and War
now the question is: if i browse any sub-category, it will not appear in the breadcrumb
(the breadcrumb will be "Home>>") while if i browse one of the main categories, it will appear normally in the breadcrumb ("Home>>News")
i have tried taxonomy_breadcrumb but this didnt fix the issue :(
how can i set the subcategories to appear in the breadcrumb??
Thanks for your help
Use any of these modules:
http://drupal.org/project/hansel
http://drupal.org/project/custom_breadcrumbs
I solved all my breadcrumb-taxonomy related problems overriding the druapal breadcrumb function. You have to go to your theme folder and add the follow function in your template.php file.
function YOUR_THEME_NAME_breadcrumb( $variables )
{
// init
$breadcrumb = $variables['breadcrumb'];
// taxonomy hierarchy
$hierarchy = array();
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)))
{
$tid = (int)arg(2);
$parents = array_reverse(taxonomy_get_parents_all($tid));
foreach( $parents as $k=>$v)
{
if( $v->tid==$tid ) continue;
$breadcrumb[] = l($v->name, 'taxonomy/term/'. $v->tid);;
}
}
// rendering
if (!empty($breadcrumb))
{
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$output .= '<div class="breadcrumb">' . implode("<span class='separator'>ยป</span>", $breadcrumb) . '</div>';
return $output;
}
}