INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Is there a way of posting or inserting content directly to the database (without entering the wp-admin)?
Is there a way of for instance, insert a post and assign a category to it, without accessing Wordpress' back-end?
|
Yes @janoChen, you can use wp_insert_post,
take a look at this answers:
WP insert post PHP function and Custom Fields
Front-End Post Submission
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "posts"
}
|
I have a desktop and a laptop: What's the best way to move between local installations?
I'm running several Wordpress installs on my desktop machine using XAMPP. I would like to move them to my laptop as well. Can I simply copy the htdocs, mysql and phpMyAdmin directories to the laptop, replacing the ones from the new install? What if I copied everything in the directory structure under XAMPP?
Will this work, or will everything go gruesomely wrong? If so, what is the right way?
**UPDATE** \- Tried copying the desktop files to the laptop. A combination of lack of sleep, XP to Windows 7 and bad juju made this a case of epic fail. To get things done quickly, I resorted to doing an XML export and reinstalling my theme on the laptop in order to do the demo.
|
From personal experience sync between two different computers work best in one direction. For example your desktop is primary and notebook is precise mirror (yep, of whole directory tree preferably with tool that doesn't touch unchanged files). Two way sync gets messy very fast for web stack.
If you need to actively work with same stack on different computers it is easier to keep portable stack on external media (like external hard drive or flash drive) and just plug it. Don't forget solid backup routine (which you should have in any case) or if external thingie dies - you lose whole stack.
PS another idea is to use something like Dropbox, but I hadn't tried that in practice yet.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "xampp, local installation, localhost, sandbox"
}
|
'x' Converted to html code in example: 5x10
I've created a page that includes a size such as 5x10 since the given term is something people often Google for, together with some other words.
Wordpress is converting 5x10 to: **_& # 2 1 5 ;_**
(without the spaces)
Is there any way to prevent this?
I suppose that there are places where this feature would be useful but in my case it's hindering my SEO efforts.
|
This is performed by `wptexturize()`. Unfortunately it saves replacement lists as static variables which you can't modify.
So your options are:
1. Remove `wptexturize` filter from related hook (depends on where you have that replacement done).
2. Write and add your own filter that will replace converted symbol back.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "pages"
}
|
Is it possible to rename a post format?
Since WP 3.1, it's been possible to use Tumblr-style post formats. I want to use the 'aside' option in a theme, but I want it to have a different title in the WP admin area.
So, for example, when a user is writing a post, they have the option for the post to be, say, either 'Standard' or 'Quick' -- rather than 'Standard' or 'Aside'.
Is it possible to do this without modifying the core? It'd be great if it's something that could be pretty easily done via functions.php or the like. I live in hope...
Thanks!
|
I think this is the only way for now. Put this in your _functions.php_ in your theme folder or create a simple plugin:
function rename_post_formats( $safe_text ) {
if ( $safe_text == 'Aside' )
return 'Quick';
return $safe_text;
}
add_filter( 'esc_html', 'rename_post_formats' );
//rename Aside in posts list table
function live_rename_formats() {
global $current_screen;
if ( $current_screen->id == 'edit-post' ) { ?>
<script type="text/javascript">
jQuery('document').ready(function() {
jQuery("span.post-state-format").each(function() {
if ( jQuery(this).text() == "Aside" )
jQuery(this).text("Quick");
});
});
</script>
<?php }
}
add_action('admin_head', 'live_rename_formats');
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 7,
"tags": "functions, post formats"
}
|
How to test wp_cron?
This is kind of a stupid question...
I scheduled a action to run every hour:
if(!wp_next_scheduled('my_hourly_events'))
wp_schedule_event(time(), 'hourly', 'my_hourly_events');
add_action('my_hourly_events', 'the_function_to_run');
function the_function_to_run(){
echo 'it works!';
}
How can I test if this works without waiting an hour? :)
I tried adding `wp_clear_scheduled_hook('my_hourly_events');` before this code and adding `wp_cron()` after, but I don't see my function running...
**edit:**
ok, I added a `trigger_error()` inside my function, checked out the apache error log, and it's there :)
So now I'm even more confused:
* How can the wp-cron run in the background? because apparently that's what happens if I see no output...
* this doesn't seem to work in a object context; why?
|
My favorite plugin for that is Core Control which has very nice module for display of what is going in the cron - which events are set up, when are they next firing, etc.
On getting your hands dirty level see `_get_cron_array()`, which returns internal stored data for cron events (top level of keys are timestamps).
|
stackexchange-wordpress
|
{
"answer_score": 22,
"question_score": 29,
"tags": "events, actions, cron, wp cron"
}
|
Remove tabs from buddypress groups and members pages
Basically if you see the picture below there are 5 tab items in my groups page:
!Screenshot
Now, I want to be able to remove some of them. I want to be able to remove "Members" and "Send Invites" (for instance).
This is on the frontend groups page. When you select a group and go to view it.
I don't want to edit core files really, is there any other way to do this? Maybe a remove_action?
Thank you.
|
Managed to crawl through the core code and find this function:
`bp_core_remove_subnav_item`
So you can do something like this:
function remove_group_options() {
global $bp;
bp_core_remove_subnav_item($bp->groups->slug, 'members');
bp_core_remove_subnav_item($bp->groups->slug, 'send-invites');
}
add_action( 'bp_setup_nav', 'remove_group_options' );
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "buddypress"
}
|
Clone plugins (and settings) to new installation?
Is it possible to clone the plugins and settings from a WordPress site to a new fresh install?
I don't want any of the content from the original site I just want all the plugins used and their settings.
Just ftp'ing the plugins into the new install doesn't work.
It's really important that all the settings are saved from the one site to the other as this will save a huge amount of time.
|
Usually blog settings, sidebars and plugins option are located in wp_options table. If you copy whole table except option_name IN ( 'siteurl', 'home' ), You get whole "old" configuration.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 2,
"tags": "options, staging, deployment"
}
|
WordPress.com podcast feed missing iTunes tags?
I recently published a podcast hosted on WordPress.com on iTunes and it says "Podcasts by Unknown". It seems like it is missing the author tag. My question is that how can I add the author tag to the RSS since I used the RSS widget to expose my RSS?
|
iTunes uses extra tags for author information, category classification, ... I believe you can't add these using WordPress.com. What you can do is pick up your feed using FeedBurner and submit that URL to iTunes instead. FeedBurner has support for podcasts and allows you to fill in the extra iTunes tags.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "wordpress.com hosting, podcasting"
}
|
How to determine when my theme is deactivated?
I'm using the following code branch to execute some theme setup options...
$myTheme_initialized = get_option('myTheme_initialized');
if (is_admin() && !$myTheme_initialized && isset($_GET['activated'] ) ) {
//do setup stuff
}
What hook can I tap into when the theme is deactivated?
|
<
Pretty good writeup for activation and deactivation
Same thing is here on SE Theme Activate Hook
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "theme development"
}
|
How can I let my audience tag my posts?
I have over 400 interviews on my site and my audience keeps asking me for a way to sort through them.
I don't have time to tag all 400 interviews. Do you think there's a way for my audience to tag interviews themselves?
|
### Andrew,
Matt Mullenweg uses a similar feature on on his blog, Ma.tt, that lets users tag photos.
!enter image description here
He released the code as a plugin, Matts Community Tags. You will have to create a custom taxonomy for the tags and add some additional code to your templates to make it work. See the discussion on the WordPress.org forums for more information.
|
stackexchange-wordpress
|
{
"answer_score": 9,
"question_score": 4,
"tags": "tags"
}
|
What's the correct way to include files in Wordpress TwentyTen theme with it's own jquery scripts and css?
I want to include a slider in the default Wordpress theme on the home page. I did manage to get the page to show using `<?php if ( is_home() ) { include ('slider.php'); } ?>` but it doesn't look like it's loading the jquery script it needs or the style sheet. I know there's a conflict with scripts and Wordpress, I just don't know how to get it to work.
Sample page is at <
How do you feed in a page with it's own style sheet and scripts?
|
**UPDATE!** What I did was just include the slider I was trying to use. I linked the jquery scripts that page needs via the `<?php bloginfo('template_directory'); ?>` method. I did notice that it takes a couple of seconds to load that portion of the page, but it works. I still think this can be improved, but with time constraints it will have to do. Thanks all for your comments and eagerness to help!
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "include, theme twenty ten"
}
|
I'm trying to add an image in my CSS
I'm trying to add an image in my CSS with the theme folder code, `<?php bloginfo('template_directory'); ?>`, which works in HTML but for some reason it's not working in the CSS. Does anyone know why or a solution?
Here's my code:
background: url("<?php bloginfo('template_directory'); ?>/images/bg.jpg");
|
That's because php code inside a CSS file is not parsed unless you configure your server to. Just use it as a relative path to the image (as per the CSS file).
`background: url("images/bg.jpg");`
|
stackexchange-wordpress
|
{
"answer_score": 7,
"question_score": 3,
"tags": "themes, images, css"
}
|
Wordpress | Sub-domain switching
I'm finding a way to redirect to a sub-domain. Sub-domains contain instances of multiple languages, say for an example -:
`
This is the English site and I want it to redirect to (when user selects particular language)
Is there a simple way of doing this want to know if there are any plugins to do so. This the requirement of my client, and they wont to do it in that way.
Thanks.
|
You can Use qTranslate, this WordPress plugin let you have an easy to use interface for managing a fully multilingual web site.
> One-Click-Switching between the languages - Change the language as easy as switching Choose one of 3 Modes to make your URLs pretty and SEO-friendly. - The everywhere compatible ?lang=en, simple and beautiful /en/foo/ or nice and neat en.yoursite.com One language for each URL - Users and SEO will thank you for not mixing multilingual content
For reference: <
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 4,
"tags": "multi language, subdomains"
}
|
How to keep track of new plugins published on wordpress.org?
Is there any RSS feed to keep track of the Newest Plugins published on wordpress.org?
|
**Update:** Found it from the dashboard widget code, its <
As a workaround, you can use Page2rss.com to create a feed for that page - <
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "plugins"
}
|
disk was full but wordpress still having issues
When trying to update wordpress from 3.1 to 3.1.1 I am getting the error
Incompatible Archive.: PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature
Some searching shows a cause of this can be that the servers disk is full. My disk is not full but it was about a week ago. I believe Wordpress has the disk still flagged as full and not writeable. Does that sound plausible or does any one have any other suggestions?
I have three Wordpress blogs on the server and this is only affecting one of them.
|
Sounds like the upgrade download corrupted (probably because of disk space) - just do the upgrade manually.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "updates"
}
|
How to make condition, based on custom fields value?
So what i would like to do is order in some CSS depending on the value of a custom field.
The code below just says that if there is ANY value, do X, else do nothing...
<?php $pageNumbered=get_post_meta($post->ID, 'page-number', true); ?>
<?php if ( $pageNumbered ) : ?>
<div class="page-number left">
<?php echo get_post_meta($post->ID, "page-number", true); ?>
</div>
<?php else : ?>
<?php endif; ?>
...what i want to do is say if the value is X do Y, if it is Z do XY etc etc...
Thanks guys!
|
Sorry but it's not clear what you want to do. From what I understand is you simply want to use an elseif statement:
<?php $pageNumbered=get_post_meta($post->ID, 'page-number', true); ?>
<?php if ( $pageNumbered ) : ?>
<div class="page-number left">
<?php echo get_post_meta($post->ID, "page-number", true); ?>
</div>
<?php elseif($pageNumbered == "Z") : ?>
<div class="page-number left">
<?php echo get_post_meta($post->ID, "page-number", true); ?>
</div>
<?php endif; ?>
If you can edit you question to be clearer then I might be able to help more.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "custom field, customization"
}
|
Clear cache when a post is submitted
I have a question.
How can I clear the cache when a post is submitted ? Actually, I need to clear two speficied pages which display these articles ? By default, I have noticed the `index.php` is cleared automatically when a post is submitted. But not `Archive page` or `Category page`...
Thanks in advance.
EDIT : By the way, how to clear only a specific page with W3 Total Cache ?
Example : Clear `/blog.php`
|
Hm, I am not sure but I think that whole cache should be invalidated on publishing of new post... Had you tried to enable debug info in W3TC and check why are those pages aren't refreshed?
As for manual cache clear, from plugin's FAQ:
> **How can I flush the cache without using the WP Admin interface?**
>
> It's possible to empty the entire cache or simply purge the cache of a single post / page:
>
> Purge the entire page cache: `if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); }`
>
> Purge a single post / page by passing it's ID:
>
> `if (function_exists('w3tc_pgcache_flush_post')) { w3tc_pgcache_flush_post($post_id); }`
|
stackexchange-wordpress
|
{
"answer_score": 12,
"question_score": 5,
"tags": "posts, archives, cache, plugin w3 total cache"
}
|
Adding An Image To A Custom Taxonomy Term
I would like to be able to associate an image with a custom taxonomy term. Ideally, I'd like to provide the end-user with an interface for managing the image directly on the term itself.
I have worked with a plugin that provides this functionality (Ultimate Taxonomy Manager) - it may be what I stick with. I'm after the best practice, though, and would like to know if any of you have worked through this before and what solutions you recommend.
|
Maybe `How TO custom taxonomies extra fields` is whats you are looking for?
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 5,
"tags": "custom taxonomy"
}
|
Plugin - Make sure jquery is loaded in my settings page plus my JS file
I'm creating my first wordpress plugin and I'm struggling to find the correct and best way to make sure jquery and my own JS file is included on my settings page of my plugin.
I do not need them to load anywhere else unless on my settings page.
What code and where do I put it in my plugin?
This is what I have so far as for creating the settings page:
add_action("admin_menu", "create_admin_pages");
function create_admin_pages() {
add_submenu_page('options-general.php', "MYPLUGIN", "MYPLUGIN", 10, "my-plugin", 'settings_page');
}
functions settings_page() {
// Settings form is here and I need Jquery and my script loaded for this
}
EDIT: The code above is somewhat been dumbed down so not to reveal the plugins function until its ready to be released. The Plugin I'm coding is wrapped in a class so its ok that the function names are generic.
|
First use `add_options_page()` \- shorter wrapper, better practice.
Second you need to save its return in some (global or static) variable. That is often used thingie and confusingly referenced by different names in documentation. Global `$hook_suffix` holds such value for current page.
function create_admin_pages() {
global $my_page;
$my_page = add_options_page(...
From there it is something like this:
add_action('admin_enqueue_scripts', 'enqueue_script');
function enqueue_script($hook_suffix) {
global $my_page;
if ($my_page == $hook_suffix)
wp_enqueue_script('my_script', plugins_url('my_script.js', __FILE__), array('jquery'));
}
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "plugin development, jquery, javascript"
}
|
What is the best practice to localize content? (Geographic not langauge)
I have a website that needs to display state-specific versions, for a few states. Obviously, I will need to parse the IP address to gain geographic information. Before I start making that plug-in, I figured I'd shoot a question out to the collective.
To further explain my situation, the website has a different "version", depending on if customers are coming to it from Texas, California, New York and Canada. The language will be English throughout, but the content for Texas is different (think: compliance) from California.
I was thinking of using a splash page (cringe) with a drop-down, should all else fail.
|
I guess this thread will steal you more than a day. After reading through it and all the code it contains, you'll be more than happy... or maybe just confused ;)
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "content, customization"
}
|
post formats - how to get the relevant content part?
The following post formats got a specific type of content part that should get displayed:
* Audio
* Video
* Link
## Questions:
**A)** What is the exact content (element) that is meant to get displayed for video & audio?
**B)** How would you get the relevant part of the post content that represents the post format?
**C)** What would you do with the rest of the content?
**D)** How would you know which format a audio/video player needs as there's nothin built in?
* * *
_Note (ad C): How would a user know that she/he should only post eg. a "link" (post format) and not a link inside a text?_
_Note (ad D):As already asked by @bueltge there's no player._
|
There is no convention or consensus on any of these questions.
In my own Theme, Oenology, I use the standard template tag `the_content()` to get the content for almost every Post Format type. The exception is Images and Galleries, where I pull the image out separately, and use `the_excerpt()` as the image caption/gallery description.
A) They are intended to display whatever content is added to the Post.
B) Use `the_content()`, just as you would with a "standard" Post
C) Display it, either as per normal, or using some creativity for certain post format types. If you develop a Theme that makes certain assumptions about what content applies to specific Post Format types, then provide documentation within the Theme to explain those assumptions.
D) You can't know. I just leave the raw link to the audio, and leave it up to the end user to choose an Audio Player Plugin.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "post formats"
}
|
custom post type or taxonomy
I'm working on a real-estate site where I need to create a profile for each **agent** , the initial view when you click on **view agents** would be to list them alphabetically, ideally from a dropdown you could select a **region** to view all the **agents** from that **region** , or chose a **language** to view all the **agents** who speak a given **language**.
My thinking is **Agent** would be a custom post type, **region** and **language** would be a taxonomy.
The listing of **agents** would then be created by showing many posts, just only showing limited details, then when clicked act as a single post, with more details shown?
Does this seem like the best way to go about this?
Thanks
|
That Sounds about right, I'm just about to finish similar project with the same base (post type, taxonomies) structure, so here are a few notes to get you going:
* To enable your "view agents" make sure when you register agents post type that you set has_archive to true or use string as archive slug which will make your life much easier.
* When registering custom taxonomies make sure to set `rewrite` to `true`.
* Create a custom template taxonomy-{taxonomy}.php for each of your custom taxonomies (even if they both show the same thing, trust me on this one) this will save you a lot of time.
* On your "view agents" template file (`archive-agents.php`) Use wp_dropdown_categories function to generate your region and language dropdowns.
* And last create your single-agents.php template file to display the full information of the agent.
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 5,
"tags": "custom post types, custom taxonomy"
}
|
display list of posts/pages in admin edit post/page
Basically, I thinking how i could get a mini wp-admin/edit.php view inside the wp-admin/post.php page. does this even make sense to anyone?
|
Try the CMS Tree Page View plugin (my favorite) or the Easily navigate pages on dashboard plugin. Both allow you to have a list of your pages on the Dashboard.
!Easily navigate pages screenshot
Then you should be able to add that panel using this reference: add_meta_box to integrate the box that appears on the Dashboard (see wp_add_dashboard_widget in functions.php of CMS Tree Page View)
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "posts, wp admin"
}
|
Minimum Widget Width for Plugin Development
I was considering a plugin that inserts itself as a widget in one's sidebar. Trouble is, I don't know what to expect for the minimum width in one's sidebar. Is there a standard?
|
As far as i am aware there is "no" standard each sidebar is defined by the theme itself i would create the elements so that they stretch and wrap in your div and use %'s in your css for associated sizes.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "plugin development, widgets, sidebar"
}
|
Widgets in PHP files?
IS it possible to make every Widget on Wordpress in a different .php file?
I have one page that contains 12 elements, I want to make each of them
a Widget so it would be easier to manage/edit them later on, but it would be better
if it's from a php page rather then from a code block on the Admin panel.
|
If the 12 elements are static HTML, you can just create 12 text widgets.
If they're not, it depends on what you mean by "easy to manage". I, for one, prefer to be able to easily manage my code via SVN. Using widgets obscures that.
If you just want them to be in separate files, just make separate files, put them in their own folder and include them:
include './sidebar/part-1.php';
include './sidebar/part-2.php';
If you're sure you really want widgets, wrap the code in the files mentioned previously in classes, as described here:
<
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": -1,
"tags": "widgets"
}
|
VideoJS in a Widget?
I'm trying to get VideoJS plugin to work in a Widget.
I tried to add a PHP widget and write, as it said in the manual:
[video mp4="
But it just shows the code as is, any ideas?
|
To display shortcodes in widgets , use a regular text widget, and add this line to your theme's functions.php file:
// Use shortcodes in text widgets.
add_filter('widget_text', 'do_shortcode');
This tells WordPress to render the shortcodes in widgets.
and if you want to call your shortcode by php you can use do_shortcode() function
// Use shortcode in a PHP file (outside the post editor).
do_shortcode('[video mp4="
To get a better understanding of shortcodes check out **this tutorial** which covers: What shortcodes are, How to use shortcodes, ,How to define your own. and How to use them in widgets.
Hope this helps
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "videos"
}
|
User capability of create page/new page
I am working with the Role and Capabilities API for the first time today and making use of the the excellent Members plugin. Having tinkered around for some time I notice that the "edit pages" capability does two things:
1. Allow the user to create a new page
2. Allow the user to edit existing pages
I am trying to split this capability into two. I want my user to:
1. Not be able to create any new pages
2. Allow the user to edit existing pages
I am looking to write some code for my theme that allows this to happen. I can create a new capability very easily. The challenge is then getting WordPress to respond accordingly to it.
Any thoughts would be appreciated.
|
Yes, this is indeed a problem. A dedicated 'create_posts' capability is planed:
<
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "pages, user roles, capabilities"
}
|
How to show a hierarchical terms list?
I have a hierarchical taxonomy called 'geographical locations'. It contains continents on a first level, and then the countries for each one. Example :
Europe
- Ireland
- Spain
- Sweden
Asia
- Laos
- Thailand
- Vietnam
etc.
Using get_terms() I managed to output the full list of terms, but the continents get mixed up with the countries, in one big flat list.
How can I output a hierarchical list like above?
|
Use `wp_list_categories` with the `'taxonomy' => 'taxonomy'` argument, it's built for creating hierarchical category lists but will also support using a custom taxonomy..
**Codex Example:**
Display terms in a custom taxonomy
If the list comes back looking flat, it's possible you just need a little CSS to add padding to the lists, so you can see their hierarchical structure.
|
stackexchange-wordpress
|
{
"answer_score": 23,
"question_score": 47,
"tags": "taxonomy, list, terms, hierarchical"
}
|
Why is style.css not being enqueued?
I got a pretty basic theme and just found out my **style.css** file doesn't get loaded into the `<head>`. I already searched around but can't find out, why it's not loading.
I inspected the `global $wp_styles` object already but couldn't find anything:
function style_test()
{
$wp_styles = new WP_Styles();
echo '<pre>';
// $wp_styles->enqueue == completely empty
print_r( $wp_styles->registered );
echo '</pre>';
}
add_action( 'wp_print_scripts', 'style_test', 0 );
Inside the object i also can't find my registered/enqueued stylesheets (they get loaded), so i guess i'm doing something wrong on inspecting this too. Any ideas?
**Note:**
If i enqueue it manually, my **style.css** file get's loaded. Just the automatic loading doesn't work. Further more i can access the file with `get_theme_data( TEMPLATEPATH.'/style.css' );` without a problem.
|
The _recommended_ way to do it is by enqueue-ing style.css in the functions.php of the theme.
Add this to functions.php
/**
* Load CSS and JS the right way
*/
function myprefix_load_css_and_js() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'myprefix_load_css_and_js' );
You can refer this in the WordPress theme handbook here and see examples here.
|
stackexchange-wordpress
|
{
"answer_score": 8,
"question_score": 11,
"tags": "css, wp enqueue style, wp register style"
}
|
Themes—Child Themes
I apologize if this is a very basic question, but I am very new to working with Wordpress.
I'm looking into using Wordpress as a CMS for a new site I'm building but I'm not sure I understand some of the best practices for themes. I've heard that a good approach is to use pre-existing themes and modify them to your own purposes using a child theme.
Is this the direction in which I should look? Is there another approach that I should look in to?
Thanks for your help!
|
If you don't want to develop/maintain your own Theme, then yes: choose an existing Theme, and make modifications to it via Child Theme.
If, on the other hand, you are comfortable with developing/maintaining your own Theme, then either create a new Theme, or make a derivative of an existing Theme.
Since, as you state, you are very new to WordPress, I would highly recommend using the Child-Theme approach.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "themes, child theme"
}
|
How do I find non-SSL problems on my SSL page?
I have a couple of pages on my WordPress site that need to run over SSL. I've installed the WordPress HTTPS plugin and configured the pages to use SSL.
However, I'm still getting the error message that some of the items are coming over unsecured and that is a concern for some users. I've looked into the generated source code and I can see some items that are still going over non SSL channels, such as the following tags at the top of the page when I view source:
<html xmlns=" dir="ltr" lang="en-US">
<head profile="
The browser only gives me the generic error message about mixed content. How do I determine which resources are causing the error?
|
Do exactly what you're doing: view the source of the offending page, and do a text search for " Anything with this protocol is "insecure", and needs to be swapped to https. Common offenders are stylesheets, javascript, and 3rd-party widgets.
If you can't find any problems in the source, try using firebug's "net panel". It lists all the requests a page makes, and you can scan through them to look for anything that starts with " (even asynchronous requests).
If you're still stuck, post the URL of your problem page and I'll take a look.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "ssl"
}
|
After server migration only the homepage works
I have recently changed hosting of my WordPress site to VPS.net. I have moved all of my files and imported the database. Everything appeared to be fine until I clicked a link and noticed that all of my pages are bringing back a 404 except the homepage.
Site URL is <
|
I guess you get but not
I had a similar problem and it worked when I changed
the `httpd.conf` from
AllowOverride None
to
AllowOverride All
It makes the `.htaccess` take effect.
|
stackexchange-wordpress
|
{
"answer_score": 52,
"question_score": 41,
"tags": "permalinks, database, 404 error, migration"
}
|
Displaying Custom Taxonomy Children in Dropdown
I have a question I hope you can help me with. I have a custom taxonomy called locations and on the first level I have the areas (Asia, Europe, etc) and under each area I have countries (England, South Africa). What I would like to do it display a dropdown menu of all the children of that particular parent similar to what was done here, < . However, I want the dropdown to only display the children of the parent page I am currently on, not all the terms. So if I am on North America I want it to show the United States and Mexico and if I am on the Europe parent page I want it to show England.
Does that make sense?
Nick
|
You can use `get_query_var( 'term' )` to get the current term and `get_query_var( 'taxonomy' ) to get the current taxonomy, then all that is left is to use [wp_dropdown_categories()][1] function with`child_of`parameter and`taxonomy` parameter, so something like this:
//first get the current term
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
//then set the args for wp_dropdown_categories
$args = array(
'child_of' => $current_term->term_id,
'taxonomy' => $current_term->taxonomy,
);
wp_dropdown_categories( $args );
Done!
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "taxonomy, children"
}
|
Custom post type and body_class: Remove "blog" class
I am using `body_class();` to style different sections of a wordpress site by their body class. Page styles descend from `.page-template`, blog styles descend from `.single-post` and/or `.blog` etc.
I have created a custom post type "Products" for the products section of the site and want to style this section specifically using it's body class, but unfortunately `body_class();` is also giving the custom post type single pages the class `.blog` which is making many of the blog styles override the product styles- very frustrating.
Is there a way to take the "blog" class away for my custom post type single pages?
Thanks!
|
You can use `body_class` filter to check if you are on your custom post type, and if so then just remove the `blog` class like this:
function remove_blog_from_cpt_classes($classes, $class){
global $post;
if ($post->post_type != "products"){
return $classes;
}else{
foreach($classes as &$str){
if(strpos($str, "blog") > -1){
$str = "";
}
}
}
return $classes;
}
add_filter("body_class", "remove_blog_from_cpt_classes", 10, 2);
Hope this helps
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "custom post types, posts, css, customization"
}
|
Moved WP into new folder. How to fix image links in posts?
I moved from Wordpress.com to my own Wordpress.org hosting. I had no problems importing all my posts over, and the images were all linked up fine.
Since the import, I decided to move my WP install from the root of HTML_public, to a new folder called Wordpress.
The posts are all still fine, but the picture links are still pointing to:
<
When they should be pointing to:
<
I am assuming I must have missed out a step and should have not been so hasty in moving things around.
Is there an easy way to automatically update all pics in all posts to point to the new URLs? i.e. Add the new wordpress folder into each of the link URLs
dekho.com.au/blog/
|
Search RegEx is a good plugin to be able to search and replace with Grep through all posts and pages to fix things like broken URLs.
And no need to export the DB and use a text editor; that's overkill for simply adding the /wordpress.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "urls"
}
|
wordpress multisite... collect all posts on main blog - exclude category?
hey guys, I'm using the sitewide tags Multisite plugin on my wordpress setup. I'm collecting all blogposts of multiple subblogs on my mainblog.
Any idea how I could manage to exclude a certain category from this collection? e.g. If a user is writing a blogpost on a subblog and is adding it to the category "private" the mainblog should not show this post!
thank you for your help.
|
You may want to encourage users to instead use the 'Post Visibility' option in the main publishing actions box on the post edit screen. Rather than filing private posts in a category, the user can simply set a post to private. Unless by 'private' you mean private to their individual blog but still public...
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "categories, multisite"
}
|
Selling WordPress sites?
What are the laws concerning developing WordPress sites using other developers' plugins and then selling the sites?
|
Please read through the following:
* <
* <
* <
* <
You ~~can't~~ can sell it as software or development, ~~although~~ and/or you can also charge for maintanance and install.
Anyway, you should at least donate to the plugin developers, if you make money with their work somehow.
**EDIT** I'm am sorry for my previous lines: I have to admit that GPL code can be sold, even if it's not your code, althought I still recommend donating.
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 4,
"tags": "plugins, hosting"
}
|
How does one reduce the number of stored revisions?
How does one reduce the number of stored revision (e.g. 5 max) for post types that support revisions?
|
add to your wp-config.php file the following line:
// set max post revisions
define('WP_POST_REVISIONS', 5);
source: <
|
stackexchange-wordpress
|
{
"answer_score": 8,
"question_score": 5,
"tags": "posts"
}
|
WordPress Cron how to find out my event recurrence?
In my plugin I'm able to set a cron event like so:
wp_schedule_event(time(), 'daily', 'myhookname');
But want I want to do is be able to find out what recurrence I have set for `myhookname`.
The reason why is that I'm offering a setting to allow the recurrence to be changed. What I need to do is check if the recurrence setting has changed from what its currently set as and if so remove the event and reschedule the event with the new recurrence.
So if there a function like this:
$recurrence = wp_current_event_recurrence('myhookname'); // returns hourly/daily/etc
|
I think I've found it: `wp_get_schedule('myhookname')`
Edit: yes this works as I want it.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "cron"
}
|
Redirecting all old links from previous EE site to new WP site in one go?
I'm about to migrate from an old Expression Engine website to a new WordPress site on the same domain. Is there anything I should be aware of with respects to redirecting old links?
The old site is quite well indexed in Search engines and linked to from other sites, but because the domain name is the same, I'm unsure of how to redirect all those old links in EE to the homepage of my new WP site without having to copy-paste all the existing individual URLs in .htaccess 301 redirects.
Any ideas?
Thanks,
osu
|
Good plugin: <
You can import CSV files of URLs to redirect, so use the string site:mydomain.com in Google to grab all your indexed URLs, get them into a file and when the WP site is live, import the file and then select the new target WP pages. The plugin has good 404 logging, too.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "url rewriting, redirect, htaccess"
}
|
Determine if page is the Posts Page
On the **Reading Settings** page you can set a "Front Page" and a "Posts Page". You can check whether the current page `is_front_page();`
Is there a similar function for the "Posts Page". I have noticed that `is_page();` does not work for this special page.
Thanks
|
`is_home()` checks for the "Posts Page", despite the somewhat confusing function name.
|
stackexchange-wordpress
|
{
"answer_score": 47,
"question_score": 28,
"tags": "posts, pages"
}
|
Import and replace existing page/post content
Is there any way to import a basic, exported Wordpress content XML file and have it replace the existing content? What I'm trying to do is synch up two instances of a site (development and staging servers) and all I want to replace is the Page content. When I try to import the XML document it simply states that all the pages already exist and nothing is done. Is it possible to override that warning and replace the content of the pages with the content of the XML?
|
One option might be to export both XML files, merge them using a file merging tool like < delete all posts and replace with the merged version.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 5,
"tags": "import, content, export"
}
|
Action hook on Edit custom post type?
Is there an explicit action hook that will fire when (or just before) the admin Edit page renders for a custom post type? Something similar to {$new_status}_{$post->post_type}?
I'm trying to find the least obtrusive place to insert my add_meta_box() registration so that it's not calling that function on every page refresh, but only when it's needed (ie: the user wants to create a new custom post or edit an existing custom post).
Thanks for your thoughts / code snippets!
|
`register_post_type()` has a registration option called `'register_meta_box_cb'`. Set that to a valid callback and it will call that function only when it is compiling the meta boxes for that post type's edit screen. Something like this:
register_post_type( 'foo', array(
'public' => true,
'label' => 'foo',
'register_meta_box_cb' => 'bar',
));
function bar(){
add_meta_box('blah', 'blah', /* etc */ );
}
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 5,
"tags": "custom post types, actions, metabox"
}
|
Why images are disappearing on WordPress web site?
I had this problem on 2 web sites (different versions of WP, different web hosts, different plugins), once in a while some images are disappearing from media library. Is it plugin-related issue, database, web host?
|
"Disappearing" means very little unless you can say the image file really disappeared from the server or if it's just a broken link you're seeing in page source or a bad link in the DB.
Little help can be offered unless you look in logs and see errors, ask your host about problems and nail down the similarities and differences between the two instances of missing images, versions of WP and plugins.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "images, database, customization"
}
|
WP-nivo-slider Producing Error "Cannot modify header information - headers already sent by ..."
I have installed the wp-nivo-slider and am now getting a list of these errors on my /wp-admin/ page.
The error is:
Warning: Cannot modify header information - headers already sent by (output started at /html/wp-content/plugins/wp-nivo-slider/wp-nivo-slider.php:633) in /html/wp-login.php on line 354
Any ideas?
|
This error is typically from there being extra spaces after the final closing ?> tag in a plugin file, or possibly even your wp-config.php file.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "plugins, errors"
}
|
How Do I Allow Comment Moderation for Other User's Posts?
I want to setup a user account that only has access to moderate comments - for all posts - but doesn't have access to edit any posts.
When I give the user the moderate comments privilege (using an old role manager plugin), it doesn't let them moderate comments on other articles.
Is there a plugin that does this, or something I'm doing wrong?
|
Probably not the answer you want to hear, but I'm afraid that is not possible as a user needs the edit_posts Capability in order to access the moderate_comments capability.
(source: <
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "comments, moderation, privileges"
}
|
Custom Post Type Template Based on Page Slug?
I have a hierarchical custom post type (missions) setup. I want to create a few child pages for it (discuss, petition, educate), but I want each of those child pages to display a different template.
There does not appear to be a way to use a selected template, like on a normal page, so I thought maybe I could just have the child custom post type pages display content based on their slug.
So the permalinks would appear as:
/mission/mission-01/
- /mission/mission-01/discuss/
- /mission/mission-01/petition/
- /mission/mission-01/educate/
/mission/mission-02/
- /mission/mission-02/discuss/
- /mission/mission-02/petition/
- /mission/mission-02/educate/
Since they are children, and the Discuss pages could all use the same slug, maybe a function that gives all pages with slug /discuss/ the page-discuss-template.php from my theme directory.
Thanks for any help!
|
There are two approaches to my question, that are both useful. They were provided by @goldenapples and @Bainternet.
Custom Post Type Data in Sidebar widgets?
How to quickly switch custom post type singular template?
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, page template, templates"
}
|
Apply a tag to every images 'Link Rel'
Building my first site. Running v3.1.1 with the Boldy theme from Site5.
Boldy makes use of prettyPhoto Lightbox. If you refer to the instructions for setting up Boldy (bottom of page)
> For adding Lightbox behaviour to a link just add rel="prettyPhoto" to the image Link Rel !enter image description here
I have just imported about 100 blog posts from Wordpress.com.
2 questions (although very related:
1. How do I batch update all previous pictures to load by default with the prettyPhoto i.e. Apply a 'prettyphoto' tag to each pictures rel.
2. I have about 15 authors for the blog. I know they will forget to manually set this prettyPhoto tag = Is there a way to make it default to this?
|
You can create a `content_filter` that will update on the fly meaning that you don't have to update all previous pictures and it will be the default so you don't have to worry about your authors. something like this:
function autoadd_rel_prettyPhoto($content) {
global $post;
$pattern = "/(<a(?![^>]*?rel=['\"]prettyPhoto.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png)['\"][^\>]*)>/i";
$replacement = '$1 rel="prettyPhoto['.$post->ID.']">';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter("the_content","autoadd_rel_prettyPhoto");
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "updates"
}
|
Using the Importer on an IIS Server
I'm running into an issue for a client whereby I keep getting the same error over and over again whilst trying to import an exported file (into an IIS environment):
Sorry, there has been an error. The uploaded file could not be moved to D:\www\www514\obtecfoundcom/wp-content/uploads/2011/04.
Anybody know what might be going on here (besides the weird slashes)? Thank you! Noel
**Technical Info**
<
**Attempts so far**
Googled the hell out of the error, nothing with a real solution.
Permissions changed to 777 all the way up to /wp-content/ (recursive)
Manually adding the file to ../2011/04
|
Have you verified permissions on the upload_tmp_dir (C:\Temp)? It's possible that the upload is actually failing there rather than in the destination directory.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "import, iis"
}
|
How to query children by post name/slug
It appears that I can only use an ID for the param `post_parent` whether in `WP_Query` or `get_children`
Is there a way to query for children via postnames which are more readable.
|
Try using the `get_page_by_path()` function (Codex ref).
So, something like:
$mypage = get_page_by_path( 'page-slug' );
$mypageid = ( $mypage ? $mypage->ID : '0' );
Then, the `post_parent` argument becomes:
`'post_parent' => $mypageid`
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "plugin development, wp query"
}
|
Efficient Tag Management?
I am the admin for a blog with around 20 authors contributing articles. Have just migrated from Wordpress.com.
The problem that started to happen at WP.com, was different authors would use tags differently. i.e Some would pick just basic tags, others would list out every key word possible.
It would appear that for WP roles, all the ones that allow people to submit posts, they can also tag their posts with as many tags as they want.
So, my question is - **What is best practice for Tag Management for a blog that has multiple authors?**
\- I guess the answer to this could be subjective. But I really need experienced advice on this, and Wordpress-Answers is where I am going to find this.
\- Happy to convert to Community Wiki?
|
I manage a blog with 3 editors and 8-10 contributors.
In my experience, the best way to manage tags is to simply instruct contributors not to add tags to their own articles, and instead have the editors be responsible for tagging articles. You can then work with editors to agree on what the purpose of tags are on for your site and make sure they enforce those policies.
I use the Simple Tags plugin for adding tags to articles which replaces the default tag entry system. When you type in a tag, it automatically searches existing tags and displays them in an AJAX-y dropdown display, which is very helpful to avoid dupes and to see what similar tags exist.
I hadn't always managed tags so diligently, so I used the Terms Management Tool plugin to merge similar/duplicate tags together. We had a lot of things like "Firefox" and "Mozilla Firefox", so I combined those into a single tag, and Simple Tags helps avoid problems like that in the future.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "tags, workflow"
}
|
How can I remove fields in the attachment editor?
Is it possible to remove a default attachment field from the attachment editor, for example the "Caption" field ?
To give you some context, I'm trying to build a custom attachment editor page. I found how to add custom fields, now I'd like to remove some of the default ones I don't need.
|
Use the attachment_fields_to_edit filter to remove the fields you don't want displaying from the array.
function remove_caption($fields) {
unset($fields['post_excerpt']); // See wp-admin\includes\media.php line 1071
return $fields;
}
add_filter('attachment_fields_to_edit','remove_caption');
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 4,
"tags": "custom field, attachments, editor"
}
|
How to create a page template that retrieves content from db?
I have to create a hundred of content pages that share the same structure.
For example:
[Title] - [Subtitle]
[Description]
[Specs]
- [Spec-A]
- [Spec-B]
- [Spec-C]
[Features]
- [Image-A][Feature-A]
- [Image-A][Feature-B]
- [Image-A][Feature-C]
I would like to store this information in some DB tables so that if I need to change the template content positions or style, I can do it once for all pages.
But unfortunately I am not very good at PHP, so I don't know where to start. Which features of Wordpress or plugins can I use to reach the result?
Thank you in advance
|
You might want to consider creating a **Custom Post Type** for this product (I assume it's some sort of product), and then adding custom metaboxes, that will store the custom data (specs, features, etc.) as metadata for each Post.
Then, your custom template file becomes "single-.php" (e.g. "single-product.php"), and you can structure the markup however you need.
Storing the custom data (specs, features, etc.) as post metadata allows you to retrieve these data using `get_post_meta()` (Codex ref) or `get_post_custom()` (Codex ref).
|
stackexchange-wordpress
|
{
"answer_score": 7,
"question_score": 1,
"tags": "page template, content"
}
|
determining if the user is logged in
I am new to wordpress, and trying to get my head around the idea of sessions and all. I read in a lot of places that session concept is not used in wordpress. Anyway, I downloaded the my-login-theme plugin. My question is, when a user navigates to some secured area, I want to check if that user is logged in or not. Once I check that, I want to get user details like email, and full name. Is this possible in wordpress?
Thanks
|
Use the `is_user_logged_in()` conditional tag (Codex ref) to determine if the current user is logged in.
Use the `get_userdata()` function (Codex ref) to return user data.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "users"
}
|
Permalinks set to /%postname%/ but still have links being indexed in the form ?p=x
I have a site that has pages being indexed in Google in the form...
site.com/?p=1
site.com/?category_name=uncategorized
site.com/?author=1
site.com/?m=201103
And since the permalinks of the site have been set to postname since the site was created, I'm trying to determine how these links are being created and where I might be able to find the source file that created the link index.
I realize its possible that the site was indexed prior to the permalink update, but just trying to determine if there is a script I'm not aware of that might be accessible to a search engine spider.
Any insights?
|
There are two places bots would look: your sitemap (if you submitted one to google), and your robots.txt. WordPress itself doesn't put anything in robots.txt (unless you set your site to private, then it tells the bots not to index anything), nor does it create xml sitemaps that google would use.
There are a few plugins that will do this for you, though. I know Google XML Sitemaps is popular, and works for me. Yoast's SEO plugin also creates sitemaps for you.
I think the easiest way to get Google to start indexing correctly is to create a sitemap with one of those two plugins and then submit it to google using google webmaster tools.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "permalinks, search engines"
}
|
Questions about Robots.txt
I need some help with robots.txt.
Under Privacy Settings, I selected "I would like my blog to be visible to everyone, including search engines..."
As I understand it, WordPress automatically creates a robots.txt file. But, I need to exclude one page from the automatically generated robots.txt file. Let's say the page is called, "myPage". How do I keep myPage from being indexed?
If I make my own static robots.txt will it be overwritten by WordPress' dynamic one?
Also, does WordPress' auto-generated robots.txt exclude files like wp-admin, that shouldn't be indexed?
Thank you!
-Laxmidi
|
you can just make a file in your root named robots.txt if you don't already have one
User-agent: *
Disallow: /myPage
is the format for that one page there is no allow, only disallow. disllowing pages you follow the above format
WP may not have generated a robots.txt, I believe it only would have if you wanted your site not indexed
I'm not sure if WP has inbuilt mechanism for not indexing your admin stuff....but mine's never been indexed. If you are worried, to block entire directories you add
Disallow: /wp-admin/
it's one entry per line/disallow
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "robots.txt"
}
|
What is better for wordpress performace?
I'm developing a website using the WPML plugin. And I would like to know which is the better option, or even the correct way to change _classes_ or _IDs_ between the languages.
**Sample code:**
<ul id="<?php _e('menu-topo'); ?>">
<ul id="<?php if ($lang = 'en') { echo "menu-topo-en"; } else { echo "menu-topo"; } ?>
I'm not sure that the `_e` function is supposed to be used this way so if someone could clarify this for me it would help me a lot, thanks.
|
_e() will translate the text passed as a argument to the language your site is currently set up to use (if the translation exists).
Anyway, don't do that. Use it for text visible on the website, not for IDs/classes etc. To create context based css rules, simply add the WPML language ID as a body class:
add_filter('body_class', 'wpml_body_class');
function wpml_body_class($classes){
return array_push($classes, ICL_LANGUAGE_CODE);
}
then style the elements you need to using something like:
.en .menu-top{
...
}
It's faster, and you keep your code easy to maintain.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 4,
"tags": "multi language, plugin wpml"
}
|
Retrieve posts by author
I am trying to retrieve all custom post types created by the current user.
I have this piece of code:
wp_get_current_user();
$args_my_items = array(
'posts_per_page' => 10,
'post_type' => 'mycustomposttype',
'post_author' => $current_user->ID);
query_posts($args_my_items);
What ends up being returned are all posts of type "mycustomposttype". It does not filter by post_author.
Am I using the wrong query parameters? How can I filter by the current user?
Thanks.
|
You must specify the `author` parameter as described here. Try to use:
$args_my_items = array(
'posts_per_page' => 10,
'post_type' => 'mycustomposttype',
'author' => $current_user->ID
);
query_posts($args_my_items);
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom post types"
}
|
something like is_childtheme()
in the functions.php of a parent theme, I would like to check for wheter the theme is being run directly, or it is run via a child theme.
Is there a conventional way of doing this? I cant find the is_childtheme() function I would have liked to have found.. so whats the best way? Check for theme name and compare it to parent theme's maybe? how can this be done?
|
As One Trick Pony said, there's a dedicated function (since WP 3.0):
is_child_theme()
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "child theme"
}
|
Counting post fields
Is there a way to count the amount of empty fields of a post (or the fields of a plugin as they relate to the different)?
For example, I have 1,500 posts on my site. Each post has important fields (information) needed for the proper functionality and user accessibility (i.e. city, state, zip code, address, etc), but not every post has all of these fields filled out.
So what I want to do is know how many posts are missing certain fields. For example, how many posts are missing the city field and so forth. Is there a plugin or a function that can count the amount of fields are missing?
I would really appreciate any help or advice with this. This would be very helpful for multiple reasons.
Thanks in advance,
Gary
|
You can do custom query loop for that particular meta box for an empty value. Something along the lines of
$check_city_value = get_post_meta($post->ID, 'city_box'); ?>
if (empty($check_city_value)) {
echo '$check_city_value is either 0, empty, or not set';
}
You would have to loop through all the posts to do this and for multiple meta box checking it might just be better to use a more direct database query using `$wpdb` , <
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom field, customization, plugin simple fields"
}
|
Is fopen() forbidden in WP?
I badly need to create an .XML file inside my theme every time user comes to my site.
But I can't.
This code in header:
<?php $ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle); ?>
Just does nothing. It doesn't display "can't open file", but it doesn't create the file as well.
I'm testing it at my /localhost machine and this code works perfectly everywhere there (so file permissions are alright), but not in Wordpress.
Why is it happening? :(
|
File system access is tricky thing between different possible server configurations. If you need to implement it reliably in WP you should look into its API for such.
See Using the WP_Filesystem.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "filesystem"
}
|
Stable tag of plugin in the readme file
If I am pushing a new version (v0.2) of my plugin (v0.1) on the repo, what does I do with the stable tag in readme file? Change it to v0.2?
What should come here? Clarifications please :)
|
Yes. You need to:
* Change stable tag to 0.2
* Commit (or copy/branch) new version to `/tags/0.2`
* Don't forget to update version to 0.2 in plugin's header
|
stackexchange-wordpress
|
{
"answer_score": 13,
"question_score": 10,
"tags": "svn, plugin repository, readme"
}
|
Export blog posts with MathJax to LaTeX document?
I use MathJax to blog my mathematical thoughts. Is it possible to convert my WordPress posts (with plenty of math) into a LaTeX document? The plugin should prompt me to select posts for the paper, and should do the rest automatically.
|
WPTeX allows you to convert your WordPress blog to a LaTeX document. If it does not already contain support for inline LaTeX, it should be really easy to add it.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "plugin recommendation, export, latex, plugin mathjax"
}
|
Pretty URLs or permalinks for attachments
Theres a way to convert links like:
<
into:
<
or:
<
|
here a simple WordPress rewrite rule to get the job done:
add_action('generate_rewrite_rules', 'attachment_rewrite_rule_14924');
function attachment_rewrite_rule_14924($wp_rewrite){
$new_rules = array();
$new_rules['attachment/(\d*)$'] = 'index.php?attachment_id=$matches[1]';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
just add this code to your theme's functions.php file and save.
*note: the index.php is regardless of your existing URL structure.
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 1,
"tags": "url rewriting"
}
|
Plugin to list active plugins across networked sites
I guess the title of this question is not clear. I'm asking for a plugin, which only superadmins can use, that shows which (or, at least, how many) blogs use each plugin installed on the network.
I've searched a lot for this, but found nothing. Is anybody who knows any such plugin?
|
You mean something like: **Active Plugins** which is a plugin that Generates a list of plugins that are currently in use and Does not include primary blog, network activated plugins, or plugins with 0 users.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 1,
"tags": "plugins, multisite, network admin"
}
|
How do I show a different homepage to logged in and non-logged in users?
Basically, I want to show non-logged in users a page that says 'register or log in.' But I want to show logged in users a standard homepage will all my posts.
|
Rarst's solution is indeed the simplest way to do it and the Members plugin also has heaps of other advantages.
You can also do it without a plugin, by using the is_user_logged_in() function
More info on < and <
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "plugins, registered, logging"
}
|
BuddyPress - How to add logout in nav menu
How to add a logout option to the main nav menu (not to the top bar) in BuddyPress?
|
Google is your friend. Here is a snippit I found I didn't test it but seems logical.
// functions.php
function add_login_logout_link($items, $args)
{
if(is_user_logged_in())
{
$newitems = '<li><a title="Logout" href="'. wp_logout_url('index.php') .'">Logout</a></li>';
$newitems .= $items;
}
else
{
$newitems = '<li><a title="Login" href="'. wp_login_url('index.php') .'">Login</a></li>';
$newitems .= $items;
}
return $newitems;
}
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
Source
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "menus, buddypress, navigation"
}
|
Retreive post thumbnail and display it as tooltip on hover?
I used a plug in to retrieve all the post from a category. The post is displayed in an unordered list `<ul><li>` and everything if fine, even the `<a>` tags to the post.
Now, for more usefulness (it's a word?), I would like, on hover of the link, to display the first image of the nextgen gallery found in this post. I do not have enough know-how to retro engineer the ngg plugin, but there should be a way to get, let's say the thumbnail of a post and set it as a tooltip.
|
I just forget the idea. Doing it with NGG is way too complicated. I am looking for a different solution. Magic gallery (PRO) look good to me
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "post thumbnails, plugin nextgen gallery, tooltip"
}
|
Why will using __construct instead of widget_class_name when creating widget trigger out of memory error
I find that if I use
class widget_name extends WP_Widget {
function __construct() { ... }
}
instead of
class widget_name extends WP_Widget {
function widget_name() { ... }
}
I get an error like
> `Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /var/www/vhosts/klifmedia.net/httpdocs/jm/km/wp-content/themes/km/functions.php on line 77`
|
Because `widget_name::__construct()` calls `WP_Widget::WP_Widget()`, which in turn calls `widget_name::__construct()` etc.
A simple solution would be to make `widget_name::__construct()` call `WP_Widget::__construct()` directly.
Also see <
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "widgets, errors"
}
|
Row actions for custom post types?
I'm working on a plugin, which converts a site into a feedback sort of portal. I made a new object page, 'Feedbacks', which displays all the feedbacks is a tabular format, and I'm using `register_column_headers($array_of_column_headers)` to make my table. I wanted to know if it is possible to add my own page row actions to this table, i mean under every feedback in the list, actions like 'approve', 'delete', 'blacklist' etc.
I read the code and a couple of tickets, and found out its done this way: for posts, its `post_row_actions`, for comments its `comment_row_actions`, for media its `media_row_actions` and so on. Is there a filter that allows me to do, `my-page-slug_row_actions`?
|
When using custom post type you use the `post_row_actions` filter hook and check the post type to modify it only:
add_filter('post_row_actions','my_action_row', 10, 2);
function my_action_row($actions, $post){
//check for your post type
if ($post->post_type =="feedbacks"){
/*do you stuff here
you can unset to remove actions
and to add actions ex:
$actions['in_google'] = '<a href=" if indexed</a>';
*/
}
return $actions;
}
**Quick update:**
thanks to somatic if you custom post type is "hierarchical" then you action hook is: `page_row_actions`.
|
stackexchange-wordpress
|
{
"answer_score": 24,
"question_score": 20,
"tags": "custom post types, wp admin, filters"
}
|
Determining the "current_page" in WordPress Custom Menus
I am using WordPress Custom Menus. I have links like
* **Home** \- Rendered using `home.php`
* **Blog** \- Rendered using `page-blog.php` with `WP_Query` to get blog posts
* **Services** \- Page
* **Portfolio** \- Rendered using `page-portfolio.php` to get all posts of the Custom Post Type "Portfolio"
* **Contact** \- Page
I will like to determine which link is current and style them. How will I do that? WordPress wont know which is selected when I am in a simple blog post for example `single.php`
|
for category:
* li.current-category-ancestor
* li.current-cat
for menu:
* li.current-menu-item
for page:
* li.current_page_item
* li.current-page-ancestor
for post:
* li.current-post-ancestor
For more details: <
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "menus, css"
}
|
Whats the difference between current_page_item and current-menu-item
Whats the difference between `current_page_item` and `current-menu-item` when using Custom Menus
.current_page_item{} // Class for Current Page
.current-cat{} // Class for Current Category
.current-menu-item{} // Class for any other current Menu Item
.menu-item-type-taxonomy{} // Class for a Category
.menu-item-type-post_type{} // Class for Pages
.menu-item-type-custom{} // Class for any custom item that you added
.menu-item-home{} // Class for the Home Link
|
current_menu_item is the active element in the menu, independent from the type (page, archives, post, etc.) of the current menu element, while current_page_item only available, if the current item is a page and is current.
For more details: <
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 5,
"tags": "menus"
}
|
add_image_size creating lots of images (of various sizes)
I wonder if its a good idea to use `add_image_size` or is it just a convinence feature. I say this as I think `add_image_size` creates images of various sizes regardless of what the usage if the image maybe
eg. I may want a thumbnail of 500x200 in my portfolio pages only. but WordPress will create images of 500x200 for all images I upload right? If I have a bunch of `add_image_size`, it will clutter up my uploads with useless images I will never use? Is there a better solution? Resize before upload, maybe alittle troublesome?
|
For image formats that are only used for a small fraction of the images, I suggest using an on-the-fly image resizer. Preferrably one that caches the images so that you only have to resize them once. I use TimThumb for a number of projects, and it's been good enough for me.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 3,
"tags": "uploads, media library, images"
}
|
WordPress adds br in between my shortcode
I am having a problem where my markup is rendered incorrectly (more space because of `<br />`) as WordPress adds `<br />` everywhere theres a line break
eg.
[x]
[y]Hello world[/y]
[y]A test[/y]
[/x]
In the handler for `x` the `$content` looks like
<br />
[y]Hello world[/y]
<br />
[y]A test[/y]
<br />
Am I suppose to strip out all the line breaks?
**UPDATE**
I notice that no line breaks
[x][y]Photoshop[/y][y]Notepad++[/y][/x]
`[y]Notepad++[/y]` will not be rendered as a shortcode. I must have a space like
[x][y]Photoshop[/y] [y]Notepad++[/y][/x]
^
Isit?
|
before you register your shortcode, add the filter to the content for unautop:
add_filter( 'the_content', 'shortcode_unautop' );
Do this also for the areas, maybe excerpt or widget, when your shortcode add to this areas.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 4,
"tags": "shortcode, editor"
}
|
Why is archive.php used for my page
I have a page "Portfolio", it contains a loop that outputs the list of portfolio (Custom Post Type, _is this the problem?_ ) items using `page-portfolio.php`. Problem is somehow WordPress used the `archive.php` to render my portfolio page, why is that?
|
An archive of a custom post type is displayed using `archive-[posttype].php` or `archive.php` if the first does not exist (see the Template Hierarchy for the full details). `page-[posttype].php` is only used if you create a "dummy" page to show a custom post type archive (before WordPress 3.1).
So in your case you should rename `page-portfolio.php` to `archive-portfolio.php`, and don't include a header to indicate a page template name.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "custom post types, theme development"
}
|
Loop from another WP site onto mine
What i'm trying to achieve is bringing a loop from one WP site into another WP Site.
I used this method to get the loop into an external php file (which all works fine, the results show)
<?php
define('WP_USE_THEMES', false);
require('path_on_server/wp-blog-header.php');
query_posts('showposts=5');
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>"><?php the_title(); ?>" /></a>
</li>
<?php endwhile; endif; ?>
I then try and include the file in my sidebar using a simple php include call but the results don't show.... I imagine this is because of some sort of confliction between my WP & the other sites WP.
Any help on achieving this?
Thanks
|
If you want to grab info right off the page you should use one of these options if you don't want a plugin, the content can be returned and parsed as xml, rss, json or just html/text. This is the proper way to do this.
WordPress HTTP API: < or
`fetch_feed()` ( for rss only).
ps. On side note I usually use simplexml instead of the built in rss wp stuff as it has way more functionality along with the HTTP API.
Also an alternative, though more troublesome way is to connect to the other database.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "loop"
}
|
Can't access WordPress functions in file called via Ajax?
I am trying to reload the fresh posts using jQuery. As far as I know, I can't reload the contents of a div inside the page so I reload a file into that div.
The problem is that my loaded file gives me a **Fatal error: Call to undefined function wp_query()**
How can I implement functions to a newly created file inside the theme directory to work properly?
_**This is my jQuery_**
<script language="JavaScript">
$(function() {
var SANAjax = function(){
}
setInterval(SANAjax, 15000 );
});
</script>
_**And this is what i have in`reloadhomeposts.php` (I have deleted the content though)_**
<?php $recent = new WP_Query("cat=3,4,5&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
.
.
.
<?php endwhile; ?>
|
The reason for this error is that your loading the file without loading in the WordPress system and so wp_query() doesnt exist.
Quick fix is to:
`include("../../../wp-load.php");` <\-- guessing at the location of the wordpress file.
at the top of the php file.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "theme development, functions, ajax"
}
|
RSS feed for deleted posts and comments
I need to create a feed (RSS or Atom) of posts and comments that have been deleted (ie moved to Trash).
What's the best way of doing this? Right now I'm thinking about creating 2 pages templates containing a SQL / $wpdb query that returns posts and comments with trashed status (and then creating new pages eg deletedposts / deletedcomments)
Any better ways? Main reason for doing it this way is easy routing - ie the URLs are created for me. How would I handle the routing if I put this in a plugin and don't create pages?
|
Well if you want a feed it would be logical to create a feed, rather than emulate it with page.
`add_feed()` ( source ) and your queries+output in callback.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "feed, customization, routing"
}
|
Custom CSS class or ID on menu items that have a Submenu
If I want to apply a style to only an item in a menu that has a submenu, how can I select that with CSS?
|
You could use jQuery, if you're open to a jQuery solution?
<script type="text/javascript">
jQuery(document).ready( function($) {
$('#your_menu_id li').has('ul').addClass('has_children');
});
</script>
Slight modification of what i posted here basically.
Any menu item with a submenu will then have a `has_children` class you can target in the stylesheet..
#your_menu_id li.has_children { /* your styling */ }
#your_menu_id li.has_children ul { /* your styling */ }
#your_menu_id li.has_children ul li { /* your styling */ }
Hope that helps..
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "css, menus"
}
|
Get Posts shortcode plugin and meta_query?
I'm using Get Posts plugin to list posts with post type "project". I want to filter the list by two custom fields: year (ex. 2006) and state (ex. Completed). I added `meta_query` to the plugin's `get_post` args and tried the shortcode:
[get_posts post_type="project" meta_query="array(array('key' => 'state', 'value' =>
'Completed'),array('key' => 'year','value' => '2006'))" suppress_filters="false"]
This is not working, though I can get both "state" and "year" to work by their own using `meta_key` and `meta_value`.
Can someone put me in the right direction?
|
Besides the plugin not being updated, this will not work because the meta_query arg is evaluated as a string:
array(3) {
["post_type"] => string(7) "project"
["meta_query"] => string(96) "array(array('key' => 'state', 'value' =>
'Completed'),array('key' => 'year','value' => '2006'))"
["suppress_filters"] => string(5) "false"
}
I suggest you make a custom page template, where you would directly call get_posts() with the meta_query you want.
You will have to copy the code that handles the actual listing of the posts.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "shortcode, meta query"
}
|
muliple wordpress multisite installs on the same sever
I want a separate production and test/dev instance. Is it possible to have two installs of wordpress multi on the same server, using different databases or do I need 2 servers, one for test and one for production?
I want to have a test instance where I can try out plugins, setting changes etc, without affecting my production instance
|
Yes, it's possible to have 2 WP MultiSite installs on the same server - just treat them as 2 separate virtual hosts, put the WP files in separate folders and use separate databases (although you can use the same database server)
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "multisite, customization, installation"
}
|
What's the best way to echo out a filter variable?
I have a plugin filter that isn't working for me:
add_filter( 'gform_notification_email_3', 'route_notification', 10, 2 );
function route_notification($email_to, $entry) {
global $post;
$email_to = get_the_author_email();
return $email_to;
}
I think the $email_to variable isn't being set properly, but how do I echo this variable out to check it?
|
Like usual. :) Works most of the time unless it ends up in some place that is not echoed to the screen by browser.
echo $email_to;
And for debug it is more informational to use `var_dump()`. Personally I usually use this to quickly add/remove dump to filter:
add_filter('filter','dump_filter',10, 1); // 1, or how many arguments the filter passes.
function dump_filter($input) {
var_dump(func_get_args());
return $input;
}
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugins, filters, variables, plugin gravity forms"
}
|
google conversion code
What is the best practice for adding google conversion tracking code to a specific page?
|
User needs it in his footer so I think you should use conditional page logic. Something like:
If ( is_single(postID)) { //insert tracking code }
You can also use the post title or post slug, but id is the most reliable.
_Old Answer_
I would consider writing a shortcode. Add the following to your functions.php file. You can specify input parameters. In this case I specify id and target.
add_shortcode( 'signup', 'signup_shortcode' );
function signup_shortcode( $atts ) {
extract( shortcode_atts( array(
'id' => '',
'target' => '',
), $atts ) );
$HTML = 'hello world'.$id;
return $HTML;
}
Then call it in your post like so:
[signup id="1234" target="goog"]
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "plugins, seo, google analytics"
}
|
wp_nav_menu sort order?
Hey Guys, I'm trying to build a right aligned, wrapping capable wp_nav_menu powered menu.
Is there a way to have it rendered backwards, so that float: right; would work and not mess up the order?
I was hoping for something like this:
<?php wp_nav_menu( array('sort_order' => 'DESC' )); ?>
Thanks!
|
I just found this handy little function that ads the ability to reverse the menu output order. it might come in handy:
/**
* Enables a 'reverse' option for wp_nav_menu to reverse the order of menu
* items. Usage:
*
* wp_nav_menu(array('reverse' => TRUE, ...));
*/
function my_reverse_nav_menu($menu, $args) {
if (isset($args->reverse) && $args->reverse) {
return array_reverse($menu);
}
return $menu;
}
add_filter('wp_nav_menu_objects', 'my_reverse_nav_menu', 10, 2);
All you need to do is ad `'reverse' => true` as one of the wp_nav_menu parameters. :)
this is the source: <
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 5,
"tags": "theme development, menus"
}
|
Utilize TinyMCE hyperlink chooser outside of TinyMCE
Is it possible to use the "Insert/edit link" dialog box outside of TinyMCE? For example, if I wanted to add that dialog box to a generic button within a plugin settings form, is it possible to include just the portion of the TinyMCE that is required to make it work?
|
this was asked before, but sadly the "Insert/edit link" (with interlinking) was developed as a tinymce plugin so using it outside of tinymce is not really possible unless your write the whole thing from scratch.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 3,
"tags": "plugin development, custom field, tinymce"
}
|
404 error after publishing a post
My issue is prety much what the title indicates. Whenever I publish a new post, everything works fine - the post is listed in my WP dashboard and all looks good. However, if I try to 'view post' to view it live on my website,
I've searched for this issue throughout the net, and all point into editing the .htaccess file. However, this issue is more likely related to a theme I've developed (why? because several buyers have reported this issue, so I need to find a fix for the theme itself).
That said, editing or manipulating the root .htaccess file is not really an option as the issue is originated in my theme.
Best,
Chris
|
I just ran into something similar to this. It had to do with refreshing permalinks. If you go to Settings -> Permalink and just click save see if it fixes your problem. It did for me. In the end I added the following to my functions.php file which updated the permalinks for me. I was using custom post types. Maybe you have a plugin that is doing the same.
add_action('admin_init', 'flush_rewrite_rules');
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "posts, 404 error"
}
|
How do I create a multi site network?
I'm wondering how to do make a multi-site network with wordpress. The best example I have is the cheezburger network.
|
<
Have you looked through the basics?
You can set up subdomains, site.domain.com or subdirectories domain.com/site
Or you can even route domains to the sub sites. Check out that stuff first, as multisite is built in to WP since 3.0
If you had more specific questions you maybe rephrase your question?
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "multisite"
}
|
Can you keep session data for visitors?
I read that you can use session_start() in config.php, but that it is not recommended.
I have a form where a user fills out their name and submits. On confirmation of the submission they land on a new page that says 'Thank-you First Last.' What is the preferred way of passing this information from page1 on to page2?
|
I would recommend using `$_GET` or `$_POST` variables ... the same way you submit the form. This has nothing to do with session.
Basically, when the user fills out the form, you're populating `$_POST` with information. When the user submits the form, you process the information in `$_POST` and display a thank you page ... you'll have access to the first and last name at this time.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "variables"
}
|
Wordpress global variables?
I've got page with metabox called "something". It can have two values "value" and "value2".
I'm using a shortcode at this page and want it to display something's value. The problem is I don't know how to access global variable in a shortcode?
Example, I have this in page.php:
if($something == "value") {
global $one, $two;
$one = 120;
$two = 240;
}
Now I want to access these variables in my shortocde (functions.php file), but
echo $one; echo $two;
Gives no output.
Any ideas?
|
Meta data is save in postmeta table and to get them you can use `get_post_meta($post_id,'meta_key_name',true);`
so in your shortcode function globilaize $post object and get you value like that
if($something == "value") {
global $post;
$one = get_post_meta($post->ID,'value_name'true);
$two = get_post_meta($post->ID,'value2_name'true);
}
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "metabox, shortcode"
}
|
Number of posts in the archive
How do I show 10 posts on the first page of the archive, and 20 on others (>1)?
My custom post type name is "apartments".
Cheers!
|
You can change the `posts_per_page` variable depending on the page you are on, so make it 10 on the first page and 20 on the other pages. However, you will have to modify the `offset` query variable too, otherwise you will skip posts 11-20 on the second page, because this page thinks they are already displayed on the first page.
add_action( 'pre_get_posts', 'wpse15087_pre_get_posts' );
function wpse15087_pre_get_posts( &$wp_query )
{
if ( $wp_query->is_post_type_archive( 'apartments' ) ) {
if ( ! $wp_query->is_paged() ) {
$wp_query->set( 'posts_per_page', 10 );
} else {
$wp_query->set( 'posts_per_page', 20 );
$wp_query->set( 'offset', ( ( $wp_query->get( 'paged' ) - 2 ) * 20 ) + 10 );
}
}
}
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "custom post types, customization, pagination, query, get posts"
}
|
Vanilla Forums as a replacement for WordPress comments?
I really like the way Vanilla Forums is integrating with WordPress however I am wondering if it is possible to take it one step further?
What i'd like to be able to do is to replace WordPress comments with a Vanilla Forum thread. That way, the conversation can continue and work more in the fashion of a forum thread, as opposed to a point in time comment.
Can this be done?
|
Vanilla recently released an update to their WordPress plugin that enables the comments to be replaced with a Vanilla thread discussion. See here:
<
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 3,
"tags": "comments"
}
|
Buddypress - New user type with no profile and can't interact but can be admin of a group
I need an easy way to create a set of users who cannot interact with the other users, all they can do is administrate a group (they can upload documents to the group-documents plugin and maybe change the name and description and avatar).
Apart from that they're not allowed to have a profile, they're not allowed to interact with other users, post to groups or anything. All they can do is log in and administrate their group.
Any ideas? I'd greatly prefer to create this in plugin format, and don't really want to edit any core files.
Thanks for any help.
Tom
|
If you want them to be able to choose the type You'll need to write your own registration logic
After that check via get_user_meta() to see if they have a certain permission
if they can do xyz and allow accordingly. I've done custom user types before for a plugin i wrote.
There's no build in roles in BP AFAIK but a lot can be done via actions and filters, does require some coding skills though.
Let me know if you need more help
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "users, buddypress"
}
|
How does one delete orphan custom post type?
I created some posts using a custom post type, then I decided to delete this custom post type but of course the old posts remained orphan inside the database.
How can I remove these orphan posts and all related attachment (post meta, etc.) safely from DB?
|
DELETE a,b,c FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID=b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID=c.post_id)
WHERE a.post_type='customposttype'
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 4,
"tags": "custom post types, customization"
}
|
Garbage in uploads folder
I have massive number of files in my uploads folder. Is there a way of identifying those which are not linked to any post?
Note: some of those files are manually copied to uploads folder not via "media library"
|
The easiest way would probably be:
1) perform a WordPress XML export ( Dashboard -> Tools -> Export )
2) import into a clean WordPress install ( Dashboard -> Tools -> Import )
At this point, everything in the `/uploads` directory of the clean install is attached. You can now:
3) backup/delete your original `/uploads` directory
4) copy over the `/uploads` directory from the clean install
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "customization"
}
|
List WordPress Custom Menu's active parent level's children as separate menu
I have a structured Custom Menu:
* parent 1
* children1_1
* children1_2
* parent 2
* children2_1
* children2_2
* parent 3
* parent 4
* children4_1
etc.
I want the following: on every page, the parent level items will be shown as main menu.
If a parent level item is active, I want to show the child menu items as a separate list somewhere else in the page.
Is there an "easy" way to achieve this, or do I have to list the menu every time and select the current one with PHP and have headache for this for days? :)
Thanks, cadeyrn
|
This plugin do exactly what you want!
|
stackexchange-wordpress
|
{
"answer_score": -2,
"question_score": 0,
"tags": "menus"
}
|
Can one plugin activate another plugin via script?
Can one plugin activate another plugin via script?
I know its possible to deactivate known plugins via script, but can't find any examples of how to activate them.
|
Take a look at
function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false );
in wp-admin/includes/plugin.php
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugin development"
}
|
Additional page and post status types
I have a site where pages will often move from draft to published and then to legacy. I would like to create another status type similar to draft or published titled "legacy". Wherein the page exists but is indicated as no longer active on the site.
Is anyone aware of a Plugin or way to hack this feature?
|
take a look at **Edit Flow plugin** which offers a suite of functionality to redefine your editorial workflow within WordPress. Features include **Custom Statuses**
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "post status"
}
|
BuddyPress - User Login instead of Full Name
Im trying to display user login instead of user full name below each post avatar. Im using the following hook:
function my_member_username_link() {
global $post;
if (isset($post->post_author)) {
$user_info = get_userdata($post->post_author);
return '<a href="/' . $user_info->user_login . '/" title="' . $user_info->user_login . '">' . $user_info->user_login . '</a>';
}
}
add_filter('bp_core_get_userlink','my_member_username_link');
This works on each avatar close to each post, but acts weird in the right sidebar where my session is displayed.
Any help is welcome.
Thanks in advance.
|
The reason it's not working in the sidebar is likely because the sidebar content is _outside_ the Loop, and `$post` data, and thus, `$post->post_author`, are only available _inside_ the Loop.
You could try setting a variable equal to `$post->post_author` while still inside the Loop, and then passing that variable to `get_userdata()` in your function call outside the Loop.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "buddypress"
}
|
Upload gravatar in WP profile?
I'm interested in the theory of a user being able to register/upload a gravatar directly in their user account within a hosted WP system.
Is this feasible?
|
If you are looking to connect your sites sign-up with Gravatar then you simply can't, since Gravatar don't have a sing-up api you can use.
But if you are just looking to let your users upload there own photos the either Simple Local Avatars Plugin that Chip suggested or one I've used a lot before is **User Photo** will do the job just fine.
But the better part of User Photo plugin is that it has an overwrite function `get_avatar` which will get the user photo if exists or the gravatar if not.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 3,
"tags": "users, avatar, profiles, gravatar"
}
|
function to remove 'comments and trackbacks are closed'
Does anyone have a function I can place in my `functions.php` that will remove this? I want to avoid altering the core files. It currently says "Both comments and trackbacks are currently closed."
|
for thematic, it's inside the 'content-extensions.php' just do a search with ctrl-f and just leave the field empty
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 3,
"tags": "comments"
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.