Load Wordpress widget in a fixed div - wordpress

I'm working on a site that sells various products. Currently we're presenting those products as fixed width (no sidebar) pages within Wordpress. I'm using "Simple WP Shopping Cart" to drive the transactions (because all of the other solutions are bloated and break stuff). With this plugin you get a widget that contains the cart...
What I want to do is load that cart to a fixed div that sits on the side of the page, rather like all those "feedback" and "socialise" bars you see on a variety of sites these days. I've done the div, so that's not a problem, but I can't seem to get the widget to load.
So basically: how would one go about loading widgets, or a widget, in a div that isn't the "designated" sidebar in Wordpress?

you need to "designate" it as a sidebar... :-)
A "sidebar" is actually a placeholder for widgets .
<div id="mysidebar">
<?php dynamic_sidebar( 'Right Sidebar' ); ?>
</div>
from the codex :
You can load a specific sidebar by either their name (if given a string) or ID (if given an integer). For example,
dynamic_sidebar('my_name')
will make a sidebar (widget placeholder) for a registered sidebar with :
register_sidebar(array('name'=>'my_name',)).
read here for more : http://codex.wordpress.org/Function_Reference/dynamic_sidebar

Related

Relative linking in Wordpress

I'm creating a website in WordPress that has child pages for multiple locations.
For example, the main page has a Home, About, and Contact pages + 15 service pages.
And the location pages have the About, Contact, and the 15 service pages duplicated.
I have links in the about page linking to the 15 services. Now If I could have a relative link it would be as easy as duplicating this section.
What I want the link to do is that if you are on
https://example.com/about/ and you click a service
it takes you to https://example.com/service1/
but if you are on https://example.com/location/
the same link structure takes you to https://example.com/location/service1
I don't want to have to create 15 different links + different menu links for every single location when all you need to do is add service1/ to the end of the slug you are on.
In Wordpress you should always use the built-in "menu" functionality: You create a menu once (in the WP backend, on the "Design > Menues" page), give it a name, define a position in your PHP template (for example the header.php file) and assign that position to that menu (in the WP backend again). WP will take care of the correct filepaths, regardless on which page you are, by dynamically creating absolute links when parsing the pages. And you can create as many menues as you want, for example the main navigation, footer nav, sidebar menu or whatever.
Here's a simple example for the code in a php template:
<nav id="main_nav">
<?php
$arguments = array(
'theme-location' => 'main_menu_1',
'container' => 'ul'
);
wp_nav_menu($arguments);
?>
</nav>

Archive displayed on a custom page to be used in menu structure

I would like to direct users to appropriate archive pages from within the menu. If I want this I need a page that I can attach to the menu.
How would I display the exact same stuff as on the archive page (archive.php) on another page so that pagination and functionalities remain the same, but some stuff will be taken from the actual page ? (can create custom page template of course)
I'll still have to show a sidebar for the page that you visited and not archive's sidebar
Breadcrumbs path will still have to show current menu item position and not archive page path
To show sidebar from the actual page is of most importance here.
EDIT
What I want to achieve is this actually:
Lets say I have a page
http://my.page/subpage/something/notifications/
I want that on this page, I can display exactly the same stuff as on the certain archive page which is here:
http://my.page/subpage/notification/
('notification' is a custom post type here)
I already have a solution that displays all archive stuff on another page (created a page template for that), but its a bit complicated to display title, breadcrumbs and sidebar properly for each page, since some of these should stay the same as they would be, but some should take the value of another site.
You can create a custom page template and assign it to a page. On that page you can use get_posts() to query the posts you want, like this:
global $post;
$posts = query_posts( /* Your args here*/ );
foreach($posts as $post) {
setup_postdata($post);
// Do your stuff as in archive.php
}
wp_reset_postdata();

Change side of sidebar (left/right) when custom post type is being used

On my Wordpress website, my archive.php has a sidebar on the right side.
I'm using WP Download Manager plugin and the categories from this plugin also use the archive.php template file from my theme. But on these category pages, I want to show the sidebar on the left side (default side is left).
Right now, in my archive.php I have a custom code to call custom made sidebar in the sidebar area when WP Download Manager is being used:
//get the sidebar for support
if ( 'wpdmpro' == get_post_type() ) {
echo '<aside class="sidebar sidebar_right smartphones_sidebar_active three alpha units" role="complementary" itemscope="itemscope" itemtype="http://schema.org/WPSideBar"><div class="inner_sidebar extralight-border">';
dynamic_sidebar( 'Support' );
echo '</div></aside>';
}
Check http://wptest.alcadis.nl/downloads/was-105r/.
This is an example page with the sidebar on the right. I want it on the left side for this custom post type.
I'd suggest adding a new template called archive-wpdmpro.php.
Copy the contents of archive.php inside here and place the sidebar where you'd like it.
This will make it easier for any post type specific changes you intend to make in the future.
Then add a single-wpdmpro.php to change the sidebar on individual pages.

how do i add different custom right sidebars with different widths and content on different pages in wordpress?

i everyone i have afew pages in wordpress that i need different custom right sidebars on with different css styles. for example i would like my homepage right sidebar to be a set width say 100px and displaying specific content and id like to have my special offers page with a right sidebar thats a different width say 230px displaying different content like widgets etc...
to my understanding this should be able to be achieved by creating custom sidebars by registering them with a wordpress function and then creating a custom sidebar template php file with a different css class for the sidebar. and then calling the new custom sidebar template file inside of a custom page template file being applied to a target page in wordpress so that the page loads the custom sidebar template instead of the normal sidebar template with a new css class that can be modified to achieve different sidebar styles for different pages. so i created the following custom sidebar template and called it customrightsidebar.php
<div id="sidebar3"><div class="sidebar3"><?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('customright-sidebar') ) : ?><div class="customright-sidebar"><h4>Recent Posts</h4><ul><?php wp_get_archives('type=postbypost&limit=5'); ?> </ul></div><?php endif; ?></div> <br style="clear:both"></div>
i then registered a new custom sidebar using this function
register_sidebar(array('name'=>'customright-sidebar','before_widget' => '<div class="customright-sidebar">','after_widget' => '</div>','before_title' => '<h4>','after_title' => '</h4>',));
and here is the custom page template that is calling the custom sidebar template
<?php get_header(); ?><div id="breadcrumb"><?php breadcrumbs(); ?></div>
<?php include(TEMPLATEPATH."/customrightsidebar.php");?>
<div id="kontenutama"> <div class="postingan2"><?php if (have_posts()) : while (have_posts()) : the_post(); ?><h2><?php the_title(); ?></h2><?php the_content(); ?><?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?><br style="clear:both;"></div></div>
<br style="clear:both"><div style="clear:both"></div><?php get_footer()?>
i successfully have a custom right sidebar that appears in my wordpress admin panel and i can apply widgets to it in the widgets section of my admin panel i can also see it appear in the custom sidebar dropdown selection menu in my wordpress pages where you would specify your new custom sidebars to overwrite the old ones. you can see a screenshot of the sidebar selection boxes in my theme by visiting this url
http://test.smartphonesource.org/sidebars.png
and normally by selecting it it would overwrite the default sidebars on the page
i have been able to get the custom sidebar template to load with the custom class on the page and ive been able to edit the css but the actual custom sidebar itself with its widgets isnt appearing or overwriting anything even though ive selected it to overwrite the right sidebar of the current page in the custom sidebars selection box
im not sure where to go from here or if there is a different way to do this i think somewhere the customsidebar isnt overwriting the default right sidebar when its been selected in the custom sidebar selection box on my pages im new to wordpress and php. ive been able to use the customright-sidebar on my videos page for testing and it successfully overwrote the right sidebar and worked but it was running this default right sidebar template
<div id="sidebar2"><div class="sidebar2"><?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar Right') ) : ?><div class="left-sidebar"><h4>Recent Posts</h4><ul><?php wp_get_archives('type=postbypost&limit=5'); ?> </ul></div><?php endif; ?></div> <br style="clear:both"></div>
anyhelp would be greatly appreciated figuring this out =) you can see the homepage of the site here that im using to learn wordpress and from there you can navigate to the videos and special offers page that im tearing apart to get a better idea of what im trying to do with the sidebars
http://test.smartphonesource.org
First of all, your website looks really awesome:) And to fix this did you make sure that your page is only grabbing the new sidebar code only?
i managed to fix the page issue im not sure what was wrong but it suddenly started working with the same code i know i cleared my cache so maybe that was affecting it or preventing the new changes from appearing sometimes if i dont clear the cache after i upload new images they wont display for me

Drupal 7 - Wanting content (of certain content-type) to appear in block

I have recently started on Drupal (v 7) to create a small company website.
After much reading and watching tutorials, I have started to create my new theme from scratch. I have defined regions and customised the page.tpl.php file to place them into the template (and node.tpl.php etc). All these changes are working and the layout is looking good, and any item I add appears in the main content output.
In my footer region, I have created a block in which I would like links to appear. I have also created a content-type called footer links (with relevant fields) and I have created a couple items of content for it.
The block is showing fine (the title and block body appear). However, despite scouring the documentation, I am not sure what needs to be done to make the items of content (footer links) appear in this block.
Any help appreciated, thanks!
info file snippet for a region
regions[footer_one] = Footer Column One
... and code in page.tpl.php
<div class="one">
<?php if ($page['footer_one']): ?>
<?php print render($page['footer_one']); ?>
<?php endif; ?>
</div>
If you just need simple footer links, no need to create a content type for this, you can simple create a menu and add a menu block in footer.
If you really want to use your own content type for these links, you can create a view (with views module) to display what you want in a block.
About creating a theme from scratch, did you try before to create a sub theme ?
PS: I don't think drupal is a good cms for "small company website".
Views is really powerful and sounds like it will do exactly what you need. Otherwise, you can create a menu for your items and place that menu in your region as well.
Regarding your original code, you'd probably need to grab the information about the nodes from the database in order to construct a list on your own, but views basically does that for you :)

Resources