Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

mmdwc on "display children category by ID on page"

$
0
0

Hello,

I'm trying to display on an archive page all the children category from a parent category bu ID.

My category ID is 4.

Here what I've used so far.

<?php $args = array(
'child_of' => 4,
'style' => 'none'	);
wp_list_categories($args); ?>

Using this code I get all my children categories list with permalink.

What I'm trying to do is to get the category slug and name separatly.

here is my example :

Parent Category name is Color, Id is 4.
my Child categories are :

name : Blue, Slug : blue
name : Red And Yellow, Slug : red_and_yellow
name : Green And Brown, Slug : green_and_brown

I need to output my category list like this :

<li class="filter" data-filter=".blue"><a href="#blue">Blue</a></li>
<li class="filter" data-filter=".red_and_yellow"><a href="#blue">Red And Yellow</a></li>
<li class="filter" data-filter=".green_and_brown"><a href="#blue">Green And Brown</a></li>

In fact I need to have separate slug & name to echo in my custom li list.

Is there a way of doing it ?

thanks a lot for your help


knudoboy on "How to run a script from a post"

$
0
0

Hi.
I am trying to run s cript from a post, when user has clicked the <--more--> tag and is sent to the single post view. The script should not execute when the home page is loaded and 10 or more posts are listed. Only if user clicks <---more---> tag
Can you make an If(....) {} thing?
Thnak you for all tips.

Knud

peterorpete on "Rewriting a custom-post-type permalink with taxonomy term before post-type?"

$
0
0

Hi hope anyone can help me. Apologies if this is simple stuff, new to it all.

Ok heres my aim: Got a website that has two top level pages called commercial and domestic and in these pages there is other content that shares similar format. So for example i want case studies in both of commercial and domestic pages.

I thought it would be best to have case studies as a custom post-type (case_studies) and have have a taxonomy (work_type) that has the two terms: commercial and domestic to help distinguish what type of case study it is.

I thought to achieve this i would rewrite the cases-studies post types url to show the term first followed by the word case_studies. so commercial/Case_studies/single

I actually got the above to work, well almost! Got the rewritten page slug to function but when it did it broke all the top level pages and turned the commercial and domestic pages to categories. I think the reason those pages used categories pages was because the originals cant be found.

Did some research and i think everyone was saying that a custom field has to be prefixed by static text. Is there anyway of making it so i don't need that text prefixed.

So current issue is this makes the case_study post type work %work_type%/case_studies but breaks top level pages. case_studies/%work_type% will work for everything, but it is not what i really want.

I have included the code below:

add_action( 'init', 'cptui_register_my_cpts' );
function cptui_register_my_cpts() {
    $labels = array(
        "name" => "Case Studies",
        "singular_name" => "Case Study",
        );

    $args = array(
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "show_ui" => true,
        "has_archive" => false,
        "show_in_menu" => true,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => true,
        "rewrite" => array( "slug" => "%work_type%/case_studies", "with_front" => false ),
        "query_var" => true,
        "supports" => array( "title", "thumbnail", "page-attributes" ),
        "taxonomies" => array( "work_type" )
    );
    register_post_type( "case_studies", $args );

// End of cptui_register_my_cpts()
}
add_action( 'init', 'cptui_register_my_taxes' );
function cptui_register_my_taxes() {

    $labels = array(
        "name" => "Work Type",
        "label" => "Work Type",
        );

    $args = array(
        "labels" => $labels,
        "hierarchical" => true,
        "label" => "Work Type",
        "show_ui" => true,
        "query_var" => true,
        "rewrite" => array( 'slug' => '%work_type%', 'with_front' => false ),
        "show_admin_column" => true,
    );
    register_taxonomy( "work_type", array( "testimonial", "case_studies" ), $args );
}

add_filter('post_type_link', 'work_types_permalink_structure', 10, 4);
function work_types_permalink_structure($post_link, $post, $leavename, $sample) {
    if (false !== strpos($post_link, '%work_type%')) {
        $work_types_type_term = get_the_terms($post->ID, 'work_type');
        if (!empty($work_types_type_term))
            $post_link = str_replace('%work_type%', array_pop($work_types_type_term)->
            slug, $post_link);
        else
            $post_link = str_replace('%work_type%', 'uncategorized', $post_link);
    }
    return $post_link;
}

mrbombastic84 on "Remove rss link - I will PAY anyone that gives the solution"

$
0
0

Hi to all,

I've got to sort this out fellas.... any help will be appreciated. I will PAY the first person that gives the solution.

I've got an external RSS feed on my website but it's feeding some irrelevant links.

Is there a way to stop the irrelevant links from showing up on my website either with a piece of code, plugin or whatever?

Best regards

cbrtom on "Error Adding Link to Sidebar"

$
0
0

I am trying to add an if statement inside of a variable. Upon doing it how I thought it should go, the page goes blank. So I'm obviously not doing it right.

Here is what I have.

$logout = apply_filters( 'wpmem_logout_link', $url . '/?a=logout' );

$str = '<p>' . sprintf( __( 'Welcome to CEnet, %s', 'wp-members' ), $user_login ) . '<br />
<li><a href="/customer-profile">Your Profile</a></li>
<li><a href="#">Support</a></li>
'
	if (current_user_can('activate_plugins')) { echo"
<li><a>admin panel</a></li>
"; }

'<li><a href="' . $logout . '">' . __( 'Logout', 'wp-members' ) .'</a></li></p>';
?>

What I'm trying to accomplish, is add a link only seen by admins. Where I happen to need it, is inside of a variable. I've never done that before.

Does anyone notice off hand, what I've done wrong?

Odido on "Manipulate comments before storing them in db"

$
0
0

Hello,

I have to replace pseudo-tags into real html-tags. These pseudo-tags are included in new comments and need to be replaced before the new comment is stored into the database. Up to now I did not find out how to use my existing function to do this.

Any help appreciated

Thx
Oliver

johnywhy on "Is `prepare` Required with `get_var`?"

$
0
0

Hi

This article says

"if you use any of the helper functions, then you don’t need to do anything: the query is escaped for you.”
https://diigo.com/08f43m

They say get_var is one of the helper functions, which, they say, is already escaped without prepare.

Is that correct?

A moderator over on buddypress.org says "no, prepare is still required for get_var". They referenced this page.

Who's right?

thx

johnywhy on "Is `get_var` Automatically Cached?"

$
0
0

Hi

According to this article, get_var is automatically cached. Does that mean i do not need to explicitly cache it in my own php call?

A moderator over on buddypress.org says, "no, you have to explicity cache it, otherwise the results will not be cached."

What's the correct answer?

thx!


alexejp on "Cannot get Post ID"

$
0
0

hey there!

i code a plugin.
in this little piece of code i want to create an array which contains the title of each post as Key, this actually works great.
but the post id is just not added as value to each key. Dont get the point in it, been looking for mistakes for ages, or at least felt like that.

$heldengeschichtenDropdown = array( 'Platzhalter' => 0 );
$args = array( 'category' => 5 );
$heldengeschichten = get_posts( $args );
foreach ( $heldengeschichten as $post ) : setup_postdata( $post );
$arraykey = get_the_title($post);
$value = $id;
$heldengeschichtenDropdown[$arraykey] = $value;
endforeach;
wp_reset_postdata();

johnywhy on "Is WP_Query() Automatically Escaped?"

$
0
0

the title says it all :)

a corollary question is, is wp_query recommended over $wpdb?

thx

andrewf12 on "Recent Comments Widget"

$
0
0

Hi,

I'm using the Recent Comments widget in the footer area and I noticed that it shows the latest comments just fine, but when I click on any of the comments in this section and the page loads, all the usernames in this section change to become that one username. Does anyone know why this might be happening?

Here's a link to the site: http://goo.gl/49Mbeo

Thanks!

Mariah_A_C on "Javascript not working in wordpress"

$
0
0

Forgive my stupidity on this I have never worked with Javascript before and I am struggling with it. I have a very basic understanding of php, mysql, html, and css.

I am trying to create a very basic image gallery where someone can select an image and I can insert the product_id associated with that image into a ?add-to-cart url.

So far I have written the code to get the products, their images, everything I need. I then foreach and create a simple photo gallery with the product_id stored in the alt= of the img.

Now the hard part how to allow someone to select the img (without having to reload the page). I went to W3schools found a javascript photo gallery and using their "try it editor" I paired it down a lot and made some small changes. The code works in thier editor, but when I put it in wordpress the gallery shows up, but it wont let me select the images.

here is the code:

<div class="colorway" style="float:left; padding:5px;">
  <div class="img">
      <img src="color_1.jpg" alt="product_id" width="100">
    <div class="desc">Color 1 </div>
  </div>
</div>

<div class="colorway" style="float:left;padding:5px;">
  <div class="img">
    <img src="color_2.jpg" alt="product_id" width="100" >
    <div class="desc">Color 2</div>
  </div>
</div>

<div class="colorway" style="float:left;padding:5px;">
  <div class="img">
    <img src="color_3.jpg" alt="product_id" width="100">
    <div class="desc">Color 3</div>
  </div>
</div>

<div class="colorway" style="float:left;padding:5px;">
  <div class="img">
    <img src="color_4.jpg" alt="product_id" width="100">
    <div class="desc">Color 4</div>
  </div>
</div>

<div style="clear:both;"></div>

<!-- The Modal -->
<div id="myModal" class="modal">
  <span class="close"></span>
  <img class="modal-content" id="img01">
  <div id="caption"></div>
</div>

<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// Get all images and insert the clicked image inside the modal
// Get the content of the image description and insert it inside the modal image caption
var images = document.getElementsByTagName('img');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
var i;
for (i = 0; i < images.length; i++) {
   images[i].onclick = function(){
       modal.style.display = "block";
       modalImg.src = this.src;
       modalImg.alt = this.alt;
       modalImg.width = 300;
       captionText.innerHTML = '<a href ="http://www.mydomain.com/cart/?add-to-cart=' + modalImg.alt +'">ADD TO CART</a>';
   }
}
</script>

I would really appreciate any suggestions. Thank you! I am also open to other ways of making this work.

enriquerene on "Losing constants and variables wordpress core"

$
0
0

Hello,

I'm developing my first plugin. It creates directories and save the path, level (if it is a subdirectory of other created directory) and name in a custom table, created at the activation.

The plugin has an option page where users can manager the files in each directory or create more directories and upload more files. In this option page I had to create a form with action atribute as "<?php echo EASYDM_PLUGIN_URL; ?>generate-dir.php".

The problem is when I try to use the constants like WP_CONTENT_URL, ABSPATH wordpress tells me they are undefined constants... just in this page of action atribute. Why?

I tried //add_action( 'admin_init', 'easydm_register_settings' ); with register_setting( 'pluginPage', 'easydm_settings' ); and so on, but when I click in submit button the page redirects me to the 'file.php' in action but as wp-admin/file.php. So, neither the first nor the second way are working for me. How can I do that?

linuxjackie on "How to fully disable 'Edit Image' function ?"

$
0
0

How to fully disable 'Edit Image' function ?
or only available for admin .

Thank You
Jackie

theitguy on "Block customers from making orders in the weekend."

$
0
0

Dear fellow Wordpress Users,

The case is:
My customer(Bakery) uses woocommerce to sell pie's and other sweet delacacies. The case is he wants the weekend off (He is working on other things in the weekend like buffets).

So my question is: Is there anyway I can prevent people from ordering something from friday to sunday?

Greetings,

The IT Guy


NachoMan42 on "fatal error when creating user and blog programmatically"

$
0
0

I have written a plugin for a multisite installation that bypasses the normal login and automatically logs a user in based on a set cookie or creates a user and blog if the user doesn't already exist. I based the user/blog creation on site-new.php. When I run the wpmu_create_blog function I get the following error:

Notice: Use of undefined constant WP_DEFAULT_THEME - assumed 'WP_DEFAULT_THEME' in /usr/local/share/wordpress/wp-admin/includes/schema.php on line 356

Notice: Use of undefined constant WP_DEFAULT_THEME - assumed 'WP_DEFAULT_THEME' in /usr/local/share/wordpress/wp-admin/includes/schema.php on line 423

Fatal error: Call to a member function init() on null in /usr/local/share/wordpress/wp-admin/includes/upgrade.php on line 250

Below is the relevant plugin code:

add_action ('set_current_user', 'sc_authenticate');

function sc_authenticate () {
// Check if already logged in
$user = wp_get_current_user();
if ( ! $user->exists() ) {
// Check if cookie set
if ( isset($_COOKIE['user'])) {
$username = $_COOKIE['user'];
$email = $_COOKIE['email'];

// Automatic login
$user = get_user_by('login', $username );

// Check if user already created in wordpress
if ($user == false) { // user doesn't exist
// create new site and user
$password = wp_generate_password( 12, false );
$user_id = wpmu_create_user( $username, $password, $email )
or die('Unable to create new wordpress user.');
$current_site = get_current_site();
$id = wpmu_create_blog( $current_site->domain, "/$username/", $username . '\'s Musings', $user_id , array( 'public' => 1 ), $current_site->id )
or die('Unable to create new wordpress blog.');
update_user_option( $user_id, 'primary_blog', $id, true );
// set auth cookie and login
wp_clear_auth_cookie();
wp_set_current_user ( $userid );
wp_set_auth_cookie ( $userid );
} else { // user already exists
// set auth cookie and login
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID );
wp_set_auth_cookie ( $user->ID );
}
}
}
}

Dieter_Z on "add_cap for author role in a Plugin – is this correct code?"

$
0
0

Hello

I wrote a little "plugin" for enhancing the user role "author". He should be able to

- see pages in admin area
- edit pages which are published by himself
- publish pages (authors normally are only allowed to publish posts)

With these short lines of codes I got success and it works, but I'm not a developer and I'm not sure, if this is a real good solution. May please somebody tell me, if the following code ist correct for putting it into a plugin? Thanks a lot in advance.

<?php
$role_object = get_role( 'author' );
$role_object->add_cap( 'edit_pages' );
$role_object->add_cap( 'publish_pages' );
$role_object->add_cap( 'edit_published_pages' );
?>

Steelclover on "Order by date - where to put in"

$
0
0

I modified this function for showing events on a page but i dont know how to sort it by date or title?

Can someone help me?

<?php // TICKERA ALL EVENTS
add_shortcode( 'tc_all_events', 'tc_all_events' );
function tc_all_events() {
$wp_events_search = new TC_Events_Search( '', '', '', 'publish' );
foreach ( $wp_events_search->get_results() as $event ) {
// echo '<div class="smticketcalendar"><h3>' . $event->post_title . '</h3>';
echo '<div class="smtickets"><div class="smticketstitle"><a id="SM-'.$event->ID.'"  href="'.$event->guid.'">'.$event->post_title.'</div></a>';
echo '<div class="smticketsdate">' . mysql2date('l, \d\e\r d. F Y \u\m H:i \U\h\r', $event->event_date_time ). '</div>';
echo '<div class="smticketslocation">' . $event->event_location . '</div>';
echo '<div class="smticketshide" tabindex="0"><div class="smticketstickets">TICKETS</div>' . do_shortcode( '[tc_event id="' . $event->ID . '"]' ).'</div></div>';
} }
?>

ccarlow on "How to make a 2 column div in a WP post that is alphabetized"

$
0
0

I have a referral list (name and address info) that I want to display in 2 columns in a wordpress post and I also need it to be alphabetized like below
A B
C D
E F
G H
and so on

Anyone have some coding suggestion? I'm a tweaker and not good with code.

Thanks!

chrstna on "PHP shortcode of custom plugin returning white screen"

$
0
0

Hi,

So there is a custom plugin that was being used on http://www.brownlowtracker.com.au that displays a horizontal scroll of AFL scores above the header.

I changed the theme it was using, and now the plugin doesn't work.

I am using code <?php do_shortcode('[matchesscore]'); ?> (this was in the original theme file of header.php that worked) in the new theme's header.php file, but it just returns a white screen.

I'm not sure where the issue is. Is it is the new theme's header?

Let me know what code/files you need to see.

Thanks for your help.

Regards,

Christina

Viewing all 8245 articles
Browse latest View live




Latest Images