wordpress-theming

How do I get the name of the file that is being used to render the current page?

此生再无相见时 提交于 2019-11-28 07:46:44
问题 Let's say I have a WordPress installation, with a page named "About". If I go to http://example.com/about , I know from WordPress' template hierarchy page that I'm looking at the theme file page.php . I'm wondering if there's a way to display that fact (for theme debugging) on the page somewhere? Like what function (or code) would I call to display the current PHP page that is being used to render the page I'm looking at. I could do something with $_SERVER['PHP_SELF'] , but I'm looking for a

jquery and wordpress

╄→尐↘猪︶ㄣ 提交于 2019-11-28 06:14:30
问题 i am having difficulty making my jquery functions operate within wordpress. can anyone help out with why these should work normally but not in wordpress??? 回答1: It seems like you have to load the script using wp_enque_script . You can find the documentation for this function and for loading scripts in WordPress in general at the codex page for wp_enque_script. Furthermore, I found an article on Using jQuery with WordPress that provides sample code for the loading of the script and then the

How do I generate a custom menu/sub-menu system using wp_get_nav_menu_items in WordPress?

寵の児 提交于 2019-11-28 03:55:40
I have an html structure that requires customization of the wp_nav_menu code. This is the html I need to generate: <ul class="main-nav"> <li class="item"> <a href="http://example.com/?p=123" class="title">Title</a> <a href="http://example.com/?p=123" class="desc">Description</a> <ul class="sub-menu"> <li class="item"> <a href="http://example.com/?p=123" class="title">Title</a> <a href="http://example.com/?p=123" class="desc">Description</a> </li> </ul> </li> <li class="item"> <a href="http://example.com/?p=123" class="title">Title</a> <a href="http://example.com/?p=123" class="desc"

Get current category ID of the active page

╄→尐↘猪︶ㄣ 提交于 2019-11-28 03:14:39
Looking to pull the category ID of a specific page in WordPress that is listing all posts using that specific category. Tried the below but not working. I am able to get the category name using single_term_title . $category = single_term_title("", false); $catid = get_cat_ID( $category ); $category is displaying "Entertainment" for example. But I also need the ID of "Entertainment". How would I go about this? You can try using get_the_category() : $categories = get_the_category(); $category_id = $categories[0]->cat_ID; Ram Mehar Deswal If it is a category page,you can get id of current

Trim headline to nearest word

流过昼夜 提交于 2019-11-28 01:16:48
Say for example I have the following code: <h3>My very long title</h3> <h3>Another long title</h3> If I wanted to shorten these titles using PHP or jQuery, how can I trim them to the nearest word and append an ellipsis? Is it possible to specify a character count? <h3>My very long...</h3> <h3>Another long...</h3> Edit - How can I do this for each one of the headlines? I don't really have an idea as to how to pass each headline into a string... Thanks Creating an ellipsis in PHP <?php function ellipsis($text, $max=100, $append='…') { if (strlen($text) <= $max) return $text; $out = substr($text

Redirect after Login on WordPress

落爺英雄遲暮 提交于 2019-11-27 17:30:29
I'm creating a customized WordPress theme based on an existing site. I want to use an alternate dashboard which I have created. How can I have the user directed to ' news.php ' after login instead of ' /wp-admin/ ' ? -- EDIT: Have a working Plug-in for this but the bounty is still availible for anyone who can find a manual way to do this through functions.php, as it would be more secure then using a 3rd party plug-in. Travis This should solve your problem. Adapted from an answer found here. function admin_default_page() { return '/new-dashboard-url'; } add_filter('login_redirect', 'admin

pagination on custom post wp_query

﹥>﹥吖頭↗ 提交于 2019-11-27 14:29:59
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $loop = new WP_Query( array( 'post_type' => 'html5-blank', 'posts_per_page' => 5, 'paged'=>$paged ) ); ?> <?php if ($loop->have_posts()): while ($loop->have_posts()) : $loop->the_post(); ?> //Loop Code Here.. <?php wp_reset_query(); ?> <nav> <?php previous_posts_link( 'Newer posts »' ); ?> <?php next_posts_link('Older »') ?> </nav> <?php endwhile; ?> <?php else: ?> Url on next page as I input result is: www.mywebsite.com/blog/page/2 is WORKING. But I can't show the pagination links. Where did it go wrong? EDIT: Pagination

Using Sass compressed output while leaving theme comment header for Wordpress

亡梦爱人 提交于 2019-11-27 12:57:16
问题 How do other Wordpress theme developers incorporate Sass into their theme development while taking advantage of its compressed output style? Sass compressed removes ALL comments, so I currently have an empty style.css with my theme declaration and an @import calling the minified css from compass, but this hardly seems like the best solution. Has anybody found a way around this? What would be the best solution if not? http://codex.wordpress.org/Theme_Development#Theme_Stylesheet http://sass

How to add automatic class in image for wordpress post

耗尽温柔 提交于 2019-11-27 11:43:42
I want to make a responsive theme with Bootstrap 3. However, I need to automatically add the CSS class .img-responsive to every post image because I need the images to be responsive. Please suggest me what I need to add in WordPress's functions.php file or any other file that will allow me to add the CSS class automatically. AhmadAssaf since you need to have it for all of your post images, then you need to add a hook for the content and add function add_responsive_class($content){ $content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"); $document = new DOMDocument(); libxml_use

Adding custom image fields and other fields at the same time

断了今生、忘了曾经 提交于 2019-11-27 08:59:35
I basically want to have a custom CMS page that has pairs of images and labels for those images defined within it. I intend to use these pairs of items for populating content on a custom page of my new WordPress theme. I have managed to make a new settings page within the CMS and populate any number of text boxes within it all thanks to Handling Plugins Options in WordPress 2.8 with register_setting() . I just now need to add fields for each text box that let a user open up the media browser and then select an existing image uploaded to WordPress or upload a new one for selection. I haven't