![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
simple way to count number of photos in wordpress?
i've spend 3 hours looking for smth, plugin or other crap, ended with some hard to understand script which i cannot utilize.
all i want is to have this same feature as TGPX had: "xxx number of photos on our site" is there any simple to use plugin that would count all photos from all posts excluding featured image and allow me to paste code so i could display it somehere close to header or anywhere i want?
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Nov 2001
Posts: 1,662
|
Now sure how TGPX works with images, but if they're attached to the posts you can use this function in your theme:
Code:
function total_images() { global $wpdb; $images= $wpdb->get_var(" SELECT COUNT(ID) FROM $wpdb->posts WHERE (post_mime_type LIKE 'image/%') AND post_type = 'attachment' AND (post_status = 'inherit') AND post_parent > 0 "); echo 'total attached images= '. $images; } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
so i'm copying this code and paste into functions.php in wordpress, now how can i display it on the site?
and thanks ;)
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
SSH/terminal
Code:
[CD to the $PWD(working directory to start recursion)] $ find . -name "*.jpg" -or -name "*.gif" -or -name "*.png" | wc -l >ct $ cat ct 110 ^image count |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
guys, ffs thank you very much but i'm familiar with html only, fraction of knowledge of php that's all i know, some css.
in other words i need more guidance how to use it and where.
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
Sorry - You said simple. Mine is one short [long :0D] line but I see what you mean.
You either need to install a script (PHP or ?) and execute the script to get the count or do it at the command line. Maybe, someone could make a plug in ... but it would be a very limited market. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
i understand a bit Howlingwulfs script a bit but need to know how to call it, how to display it?
your Barry i have no idea what to do with. but thanks a lot for trying anyway.
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
It would just give you the count (printed to a file) when you run it and would not output 'print or echo' the count on your site.
PHP could open the counter file and echo that count. What I wrote is the basis of a .sh (bash script) that could be set into a cron job -- the server would do it every 4 hours or something. This is the fast way to do things with the least server resources used. If you were to add a PHP script to do this each time the wordpress page loads it is a waste of resources ... polling the same count over and over each page load slows the page load time ... The count should be cached every so often 1 sec - 1 day this is done in a user crontab. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
so i should make a .sh file with this content:
[CD to the $PWD(working directory to start recursion)] $ find . -name "*.jpg" -or -name "*.gif" -or -name "*.png" | wc -l >ct $ cat ct 110 ^image count and setup cron to run it one or more times daily and it will count all images? but how to show this file where are those images located (normally it's wp-content/uploads and there are subfolders) ? also how would look command to echo of results? thanks a lot for helping, your way is indeed much better than any plugin or php which is running all the time.
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
cuck
Industry Role:
Join Date: Mar 2003
Posts: 11,571
|
I just use my fingers. For more complex counting I use an abacus like this:
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
Code:
#!/bin/bash #imgct.sh #FTP and CHMOD 755 find . -name "*.jpg" -or -name "*.gif" -or -name "*.png" | wc -l >ct.txt exit You may have to path the PHP script to the ct.txt file. crontab there shold be access in the admin interface (cPanel?) Quote:
PHP Code:
Freeware: MIT license as-is without warranty or guarantee. ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
thanks a lot, just woke up, i'll play with this and let you know results
![]()
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
here's what i did:
i've made imgct.sh file with this content: #!/bin/bash #imgct.sh #FTP and CHMOD 755 find . -name "*.jpg" -or -name "*.gif" -or -name "*.png" | wc -l >ct.txt exit this file is in my /uploads/ folder inside wp-content now in same folder i've made blank ct.txt file with 755 permissions and as 3rd i've made displayct.php file with content: <?php //display count //displayct.php $imgct = fopen("ct.txt", "r") or die("Unable to open file!"); echo fread($imgct, filesize("ct.txt")); fclose($imgct); ?> where is fopen("ct.txt","r") i've put full path to /wp-content/uploads/ and as 4th step i've setup cron. when i've opened displayct.php in my browser it remains blank, cron is working every 2minutes (testing) and cron sends me an emails with this content: #imgct.sh #FTP and CHMOD 755 find . -name "*.jpg" -or -name "*.gif" -or -name "*.png" | wc -l >ct.txt exit now what i did wrong?
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 | |
Confirmed User
Join Date: Oct 2002
Location: Holland
Posts: 466
|
Quote:
copy the function into the page where to display. then "total_images();" this will invoke the function and echo the total images, if the query is correct ofcourse. Dont use bash scripts for this. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
1. Download the ct.txt and see if it has a number.
If it does, then the .sh and its cron is working Check the ownership of the file it should be username:group (root?) I tested it here on a site directory at the command line, the .sh(bash) command and the php <file> they worked. $cat ct =>110 cat is open and read out a file in LINUX terminal. $tac is reverse the file read from the end Trivia ![]() If there are contents in the file then it is a PHP issue. PHP may need the full path ? Or, there is a fopen, or fread issue -- maybe the chown (ownership of the file -- the PHP user www-data usually needs to be the file's group, i.e.; $chown username:www-data but PHP shouldn't need that permission to read just to write to a file. Full path looks sort of like this: /home/username/docroot/ ..../.../wp-content/uploads/ *** I just tried it in a browser and it worked =>712 That was the count from that directory but the path was relative all in the same directory. Put the image count readout *displayct.php* in the same directory as the ct.txt if that file has contents to read. Wordpess file location problem? I sort of like the idea because it could wc -l (count lines in a file or a find (like shown | (pipe the output))) of a link file or a videos found count. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
thank Kafka but i would love to make Barry's scripts to work, looks like low server resource and should do the job.
can't make it. i think i've fucked up smth at the start since there is no numbers generated in ct.txt so maybe chmods are setup badly or smth in .sh file gonna work on it more, rly like this idea.
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
Did you make the bash .sh script in a widows editor? In Windows it need to be done in notepad and saved as 'all files' .sh -- DOS and UNIX line endings?
If you could SSH to the directory and run the command manually you could test for output ... $ cd ./path/to/file $ find . -name "*.jpg" -or -name "*.gif" -or -name "*.png" | wc -l >ct.txt also $ stat imgct.sh make sure the permissions are 755 if the command works manually. ct.txt and display.php should stat with 644 permissions. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 |
Confirmed User
Join Date: Feb 2006
Posts: 994
|
made it in notepad with .sh tylde
already wrote a ticket to my admins asking what could be wrong, will post here once we will figure out.
__________________
Pure Japan japanese babes blog |
![]() |
![]() ![]() ![]() ![]() ![]() |